Remove extra call coming from duplicate layout scheduling in src/useC…#234
Remove extra call coming from duplicate layout scheduling in src/useC…#234
Conversation
…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
📝 WalkthroughWalkthroughThe ChangesCaret Handler Optimization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/useCaretLayout.tstests/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) |
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
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 })fromhandleCaretPositionChange, relying on the commit-time layout decision to schedule measurement whencaretPositionchanges. - 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.
…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
Note
Remove duplicate
requestViewSynccall fromhandleCaretPositionChangeinuseCaretLayouthandleCaretPositionChangein useCaretLayout.ts previously calledrequestViewSync(withmeasureSuggestionsandmeasureInlineset totrue) after updating caret position state, duplicating a sync that was already scheduled elsewhere.<= 3to=== 1to reflect the corrected call count.Macroscope summarized b823e2e.