Fixed sidebar flicker during navigation preference updates#26924
Conversation
WalkthroughThe pull request adds a test case for the 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2d97b3a to
ebfb201
Compare
ref https://linear.app/ghost/issue/BER-3464/prevent-sidebar-flicker-during-navigation-preference-updates Keep previous user preference data during accessibility-backed query key changes and cover the regression at the useUserPreferences hook boundary so sidebar consumers no longer flicker during unrelated navigation preference updates.
ebfb201 to
3f246fb
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/admin/src/hooks/user-preferences.test.tsx (1)
358-358: Make the snapshot check non-vacuous.Line 358 can pass even when no post-mutation snapshots were recorded. Add a length assertion first so this regression test fails if no render states were observed.
Suggested tightening
- expect(snapshots).not.toContain(undefined); + expect(snapshots.length).toBeGreaterThan(0); + expect(snapshots).not.toContain(undefined);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/admin/src/hooks/user-preferences.test.tsx` at line 358, The test's final assertion only checks that the snapshots array does not contain undefined, which is vacuous if no snapshots were recorded; update the test in user-preferences.test.tsx by asserting that the snapshots array has at least one entry (e.g., expect(snapshots.length).toBeGreaterThan(0)) before the existing expect(snapshots).not.toContain(undefined) so the regression fails when no post-mutation render states were observed; target the test's snapshots variable and the failing assertion that currently reads expect(snapshots).not.toContain(undefined).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/admin/src/hooks/user-preferences.test.tsx`:
- Line 358: The test's final assertion only checks that the snapshots array does
not contain undefined, which is vacuous if no snapshots were recorded; update
the test in user-preferences.test.tsx by asserting that the snapshots array has
at least one entry (e.g., expect(snapshots.length).toBeGreaterThan(0)) before
the existing expect(snapshots).not.toContain(undefined) so the regression fails
when no post-mutation render states were observed; target the test's snapshots
variable and the failing assertion that currently reads
expect(snapshots).not.toContain(undefined).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6a9cacb1-f4fc-4a2e-bd88-9e3b6b3d2019
📒 Files selected for processing (2)
apps/admin/src/hooks/user-preferences.test.tsxapps/admin/src/hooks/user-preferences.ts
fixes https://linear.app/ghost/issue/BER-3464/prevent-sidebar-flicker-during-navigation-preference-updates Enabling the `keepPreviousData` flag ensures that query data won't cycle through `undefined` when the derived query re-evaluates.
This fixes a sidebar flicker that happens when expanding or collapsing sidebar sections updates the current user's
accessibilitypreferences.useUserPreferences()would briefly drop its data during unrelated preference updates, which in turn made dependent sidebar UI such as the What's New banner and user-menu indicators disappear and reappear.The fix keeps the previous user preference data while the accessibility-backed query key changes. I also added one focused regression test at the
useUserPreferences()boundary to lock that behavior in place.Verification:
../../node_modules/.bin/vitest run src/hooks/user-preferences.accessibility-updates.test.tsxfromapps/admin../../node_modules/.bin/eslint src/hooks/user-preferences.ts src/hooks/user-preferences.accessibility-updates.test.tsxfromapps/adminFixes https://linear.app/ghost/issue/BER-3464/prevent-sidebar-flicker-during-navigation-preference-updates