fix(DashboardSidebar): guard against null persisted storage in useResizable#6522
fix(DashboardSidebar): guard against null persisted storage in useResizable#6522benjamincanac wants to merge 2 commits into
useResizable#6522Conversation
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/runtime/composables/useResizable.tsParsing error: Unexpected token { 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/composables/useResizable.ts`:
- Around line 335-337: The sync currently skips persisted false because it
checks truthiness; update the condition that sets collapsed.value so it detects
an explicit stored false (e.g. check for undefined rather than falsiness).
Locate the block using isRef(collapsed) and storageData.value?.collapsed and
change the guard to verify storageData.value exists and
storageData.value.collapsed is not undefined (or use `'collapsed' in
storageData.value`) before assigning collapsed.value =
storageData.value.collapsed.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fa90992c-e0de-46d0-b33d-c7e59b6f80ca
📒 Files selected for processing (1)
src/runtime/composables/useResizable.ts
| if (isRef(collapsed) && storageData.value?.collapsed) { | ||
| collapsed.value = storageData.value.collapsed | ||
| } |
There was a problem hiding this comment.
Initial sync should not ignore persisted false
The condition only syncs when persisted collapsed is truthy, so an explicit persisted false is skipped and can leave the external ref out of sync.
Suggested fix
- if (isRef(collapsed) && storageData.value?.collapsed) {
+ if (isRef(collapsed) && typeof storageData.value?.collapsed === 'boolean') {
collapsed.value = storageData.value.collapsed
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/runtime/composables/useResizable.ts` around lines 335 - 337, The sync
currently skips persisted false because it checks truthiness; update the
condition that sets collapsed.value so it detects an explicit stored false (e.g.
check for undefined rather than falsiness). Locate the block using
isRef(collapsed) and storageData.value?.collapsed and change the guard to verify
storageData.value exists and storageData.value.collapsed is not undefined (or
use `'collapsed' in storageData.value`) before assigning collapsed.value =
storageData.value.collapsed.
commit: |
🔗 Linked issue
Resolves #6517
❓ Type of change
📚 Description
useResizablecrashes withCannot read properties of null (reading 'collapsed')when the persisted cookie or localStorage value parses tonullinstead of the expected{ size, collapsed }object.This happens because
useCookie'sdefaultoption only fires when the cookie is undefined, not whendestrparses it tonull. Any of these puts the ref into anullstate and crashes the sidebar permanently for that user:nulllocalStorageentry containing"null"nullFix:
storageData, if the value isnullor not an object, immediately reset it todefaultStorageValue(self-heals the persisted value).isCollapsedandsizecomputed getters use optional chaining with nullish coalescing so they never throw.collapsedref sync and watcher both handle the nullish case.📝 Checklist