Skip to content

fix: debounce slider to avoid laggy behavior #18980

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

Merged
merged 5 commits into from
Jul 22, 2025
Merged

Conversation

jaaydenh
Copy link
Contributor

@jaaydenh jaaydenh commented Jul 21, 2025

resolves #18856
resolves coder/internal#753

@jaaydenh jaaydenh self-assigned this Jul 21, 2025
@jaaydenh
Copy link
Contributor Author

@CodeRabbit review

Copy link

coderabbitai bot commented Jul 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 21, 2025

📝 Walkthrough

Walkthrough

The changes add support for a new "slider" form type in the DynamicParameter component. The slider UI is implemented in DebouncedParameterField, handling value state, validation, and disabled state. The "slider" case is removed from ParameterField, consolidating its handling. No exported interfaces or APIs are altered.

Changes

File(s) Change Summary
site/src/modules/workspaces/DynamicParameter/...tsx Added "slider" form type support in DynamicParameter and DebouncedParameterField; removed "slider" from ParameterField; managed slider state, validation, and UI.

Estimated code review effort

2 (~15 minutes)

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx (1)

413-433: Refactor slider value conversion & guard validation defaults

To clean up duplication and safely handle missing validations, consider pulling out your computed values and defaults at the top of the render case:

+   // Compute once at render-time
+   const numericValue = Number.isFinite(Number(localValue)) ? Number(localValue) : 0;
+   const {
+     validation_min: min = 0,
+     validation_max: max = 100,
+   } = parameter.validations[0] ?? {};
  
    case "slider":
      return (
        <div className="flex flex-row items-baseline gap-3">
          <Slider
            id={id}
            className="mt-2"
-           value={[numericValue]}
+           value={[numericValue]}
            onValueChange={([value]) => {
              setLocalValue(value.toString());
            }}
-           min={parameter.validations[0]?.validation_min ?? 0}
-           max={parameter.validations[0]?.validation_max ?? 100}
+           min={min}
+           max={max}
            disabled={disabled}
          />
-         <span className="min-w-8 font-medium">
-           {numericValue}
-         </span>
+         <span className="min-w-8 font-medium">
+           {numericValue}
+         </span>
        </div>
      );

• Eliminates repeated Number() checks by centralizing numericValue
• Destructures min/max with clear defaults if validations[0] is absent
• Uses min-w-8 so larger numbers don’t overflow the display span

Please verify that every slider-type parameter always supplies a first validation object with both validation_min and validation_max; if not, adjust the data model or add an explicit guard.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7b1253 and b2f30fc.

📒 Files selected for processing (1)
  • site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx (2)

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : MUI components are deprecated - migrate away from these when encountered

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Use functional updates (setX(prev ⇒ …)) whenever next state depends on previous state.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: chromatic
  • GitHub Check: test-e2e
  • GitHub Check: test-js
  • GitHub Check: lint
  • GitHub Check: fmt
  • GitHub Check: gen
🔇 Additional comments (1)
site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx (1)

80-81: Good consolidation of slider handling into debounced field.

Routing slider parameters to DebouncedParameterField is the correct approach for addressing laggy behavior, as sliders can generate rapid value changes during user interaction.

@jaaydenh jaaydenh requested a review from Emyrk July 21, 2025 21:43
@coder coder deleted a comment from coderabbitai bot Jul 21, 2025
@jaaydenh jaaydenh merged commit dd2fb89 into main Jul 22, 2025
34 checks passed
@jaaydenh jaaydenh deleted the jaaydenh/debounce-slider branch July 22, 2025 15:15
@github-actions github-actions bot locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic parameter slider is laggy and non-functional in Safari Dynamic defaults seem to not update on Multi-select in coder/coder
2 participants