Skip to content

fix: workaround hardcoded dreamshaper changes #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

vcashwin
Copy link
Contributor

@vcashwin vcashwin commented May 20, 2025

PR Type

Bug fix, Enhancement


Description

  • Add useSearchParams in useStreamUpdates hook

  • Only set prompts for Dreamshaper pipelines

  • Remove always-on prompt slot creation

  • Document current workaround via TODO comment


Changes walkthrough 📝

Relevant files
Enhancement
useDreamshaper.tsx
Conditional Dreamshaper prompt injection                                 

apps/app/hooks/useDreamshaper.tsx

  • Imported useSearchParams for query access
  • Added isDreamshaper conditional around prompt injection
  • Removed unconditional prompt slot creation
  • Inserted TODO comment about hack
  • +15/-7   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    vercel bot commented May 20, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    pipelines-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 20, 2025 9:19am

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing Callback Dependency

    The searchParams value is used inside handleStreamUpdate but isn't included in the useCallback dependency array, which may lead to stale references. Add searchParams to the dependencies.

    const searchParams = useSearchParams();
    
    const handleStreamUpdate = useCallback(
    Hardcoded Prompt Slot

    The prompt slot ID "5" is hardcoded in multiple places. Consider extracting it into a named constant or deriving it from the pipeline configuration to improve maintainability.

      if (!updatedInputValues.prompt["5"]) {
        updatedInputValues.prompt["5"] = { inputs: {} };
      }
      if (!updatedInputValues.prompt["5"].inputs) {
        updatedInputValues.prompt["5"].inputs = {};
      }
    
      updatedInputValues.prompt["5"].inputs.text = cleanedPrompt;
    }
    Conditional Logic Clarity

    The condition searchParams.get("isDreamshaper") !== "false" may be confusing and could result in unintended behavior if the parameter is omitted. Consider using an explicit check like === "true" or a clearer boolean flag.

    if (searchParams.get("isDreamshaper") !== "false") {

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Clear stale prompt text

    Add an else branch to clear or delete text on prompt["5"].inputs when isDreamshaper
    is "false", preventing stale prompt data from leaking into non-Dreamshaper
    pipelines.

    apps/app/hooks/useDreamshaper.tsx [470-479]

     if (searchParams.get("isDreamshaper") !== "false") {
       if (!updatedInputValues.prompt["5"]) {
         updatedInputValues.prompt["5"] = { inputs: {} };
       }
       if (!updatedInputValues.prompt["5"].inputs) {
         updatedInputValues.prompt["5"].inputs = {};
       }
     
       updatedInputValues.prompt["5"].inputs.text = cleanedPrompt;
    +} else {
    +  if (updatedInputValues.prompt["5"]?.inputs?.text) {
    +    delete updatedInputValues.prompt["5"].inputs.text;
    +  }
     }
    Suggestion importance[1-10]: 7

    __

    Why: Adding an else branch to remove stale text prevents incorrect prompt data in non-Dreamshaper cases and improves data integrity.

    Medium
    General
    Use nullish coalescing

    Simplify nested existence checks by using nullish coalescing to initialize the
    objects in a more concise and readable way.

    apps/app/hooks/useDreamshaper.tsx [471-476]

    -if (!updatedInputValues.prompt["5"]) {
    -  updatedInputValues.prompt["5"] = { inputs: {} };
    -}
    -if (!updatedInputValues.prompt["5"].inputs) {
    -  updatedInputValues.prompt["5"].inputs = {};
    -}
    +updatedInputValues.prompt["5"] = updatedInputValues.prompt["5"] ?? { inputs: {} };
    +updatedInputValues.prompt["5"].inputs = updatedInputValues.prompt["5"].inputs ?? {};
    Suggestion importance[1-10]: 5

    __

    Why: Replacing multiple existence checks with nullish coalescing makes the code more concise and readable with minimal functional change.

    Low

    @vcashwin vcashwin temporarily deployed to Preview - e2e May 20, 2025 09:16 — with GitHub Actions Inactive
    @vcashwin vcashwin changed the title [wip] workaround dreamshaper hardcode fix: workaround dreamshaper hardcode May 20, 2025
    @vcashwin vcashwin changed the title fix: workaround dreamshaper hardcode fix: workaround hardcoded dreamshaper changes May 20, 2025
    @vcashwin vcashwin closed this May 21, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants