Skip to content

Remove extra call coming from duplicate layout scheduling in src/useC…#234

Open
hbmartin wants to merge 1 commit intomasterfrom
fix-dupe-layout-scheduling
Open

Remove extra call coming from duplicate layout scheduling in src/useC…#234
hbmartin wants to merge 1 commit intomasterfrom
fix-dupe-layout-scheduling

Conversation

@hbmartin
Copy link
Copy Markdown
Owner

@hbmartin hbmartin commented May 2, 2026

…aretLayout.ts

handleCaretPositionChange updated caretPosition and also requested inline/suggestions measurement, while the commit-time layout effect already requests the same measurement when caretPosition changes. Depending on rAF ordering, those could coalesce to 1 call or split into 2

Summary by CodeRabbit

  • Performance
    • Caret position updates now generate fewer layout measurement requests
    • Inline autocomplete rendering performance improved

Note

Remove duplicate requestViewSync call from handleCaretPositionChange in useCaretLayout

  • handleCaretPositionChange in useCaretLayout.ts previously called requestViewSync (with measureSuggestions and measureInline set to true) after updating caret position state, duplicating a sync that was already scheduled elsewhere.
  • The call is removed so only state is updated, eliminating the redundant layout measurement.
  • The performance test in MentionsInput.performance.spec.tsx tightens the inline layout assertion from <= 3 to === 1 to reflect the corrected call count.

Macroscope summarized b823e2e.

…aretLayout.ts

handleCaretPositionChange updated caretPosition and also requested inline/suggestions measurement, while the commit-time layout effect already requests the same measurement when caretPosition changes.
Depending on rAF ordering, those could coalesce to 1 call or split into 2
Copilot AI review requested due to automatic review settings May 2, 2026 19:00
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

📝 Walkthrough

Walkthrough

The handleCaretPositionChange function has been optimized to remove a view synchronization request. The performance test assertion for calculateInlineSuggestionPositionCalls was correspondingly tightened from allowing up to 3 calls to requiring exactly 1.

Changes

Caret Handler Optimization

Layer / File(s) Summary
Handler Logic
src/useCaretLayout.ts
handleCaretPositionChange removes the requestViewSync call that previously queued measureSuggestions and measureInline measurements, replacing it with new code to reduce redundant view synchronization.
Performance Test
tests/MentionsInput.performance.spec.tsx
Assertion for inline suggestion position calculation call count is tightened from toBeLessThanOrEqual(3) to toBe(1) to verify the optimization reduces layout recalculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing a duplicate layout measurement call caused by redundant scheduling in useCaretLayout.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-dupe-layout-scheduling

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes performance by removing a redundant call to requestViewSync within the handleCaretPositionChange callback in useCaretLayout.ts. This change reduces unnecessary layout measurements, which is verified by the updated performance test expectation in MentionsInput.performance.spec.tsx. I have no feedback to provide.

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/MentionsInput.performance.spec.tsx`:
- Line 168: Replace the strict equality assertion on
metrics.calculateInlineSuggestionPositionCalls with a bounded assertion to
tolerate legitimate second calls; locate the
expect(metrics.calculateInlineSuggestionPositionCalls).toBe(1) assertion in the
test and change it to a range check such as
expect(metrics.calculateInlineSuggestionPositionCalls).toBeLessThanOrEqual(2)
(or a similar <= bound) so the test still enforces reduced work but allows 2
calls.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7d2f0864-ab4e-4730-b117-5fafcaaa6e7a

📥 Commits

Reviewing files that changed from the base of the PR and between b7064cd and b823e2e.

📒 Files selected for processing (2)
  • src/useCaretLayout.ts
  • tests/MentionsInput.performance.spec.tsx
💤 Files with no reviewable changes (1)
  • src/useCaretLayout.ts


expect(metrics.calculateSuggestionsPositionCalls).toBe(0)
expect(metrics.calculateInlineSuggestionPositionCalls).toBeLessThanOrEqual(3)
expect(metrics.calculateInlineSuggestionPositionCalls).toBe(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Assertion at Line 168 is too strict and is breaking CI

This expectation is currently failing (received 2). Given src/useCaretLayout.ts still computes inline position per eligible flush cycle, this interaction can legitimately produce 2 calls. Use a bounded assertion instead of exact 1 to keep the test stable while still enforcing reduced work.

Suggested patch
-    expect(metrics.calculateInlineSuggestionPositionCalls).toBe(1)
+    expect(metrics.calculateInlineSuggestionPositionCalls).toBeGreaterThan(0)
+    expect(metrics.calculateInlineSuggestionPositionCalls).toBeLessThanOrEqual(2)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(metrics.calculateInlineSuggestionPositionCalls).toBe(1)
expect(metrics.calculateInlineSuggestionPositionCalls).toBeGreaterThan(0)
expect(metrics.calculateInlineSuggestionPositionCalls).toBeLessThanOrEqual(2)
🧰 Tools
🪛 GitHub Actions: Performance Notes

[error] 168-168: Vitest perf test failed: AssertionError at tests/MentionsInput.performance.spec.tsx:168:60 (expected 1, received 2; Object.is equality).

🪛 GitHub Check: perf-check

[failure] 168-168: tests/MentionsInput.performance.spec.tsx > MentionsInput performance > reports layout measurement counts for inline autocomplete interactions
AssertionError: expected 2 to be 1 // Object.is equality

  • Expected
  • Received
  • 1
  • 2

❯ tests/MentionsInput.performance.spec.tsx:168:60


[failure] 168-168: tests/MentionsInput.performance.spec.tsx > MentionsInput performance > reports layout measurement counts for inline autocomplete interactions
AssertionError: expected 2 to be 1 // Object.is equality

  • Expected
  • Received
  • 1
  • 2

❯ tests/MentionsInput.performance.spec.tsx:168:60

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/MentionsInput.performance.spec.tsx` at line 168, Replace the strict
equality assertion on metrics.calculateInlineSuggestionPositionCalls with a
bounded assertion to tolerate legitimate second calls; locate the
expect(metrics.calculateInlineSuggestionPositionCalls).toBe(1) assertion in the
test and change it to a range check such as
expect(metrics.calculateInlineSuggestionPositionCalls).toBeLessThanOrEqual(2)
(or a similar <= bound) so the test still enforces reduced work but allows 2
calls.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes redundant layout measurement scheduling in the caret layout hook to prevent duplicate inline/suggestions positioning work triggered by the same caretPosition update.

Changes:

  • Remove requestViewSync({ measureSuggestions: true, measureInline: true }) from handleCaretPositionChange, relying on the commit-time layout decision to schedule measurement when caretPosition changes.
  • Tighten the inline-autocomplete performance test to assert a single inline position measurement call.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/useCaretLayout.ts Eliminates a redundant view-sync request on caret position updates to avoid duplicate measurement work.
tests/MentionsInput.performance.spec.tsx Updates the inline layout performance assertion to expect exactly one inline measurement call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants