fix: improve collapsible section state detection#1381
fix: improve collapsible section state detection#1381danielroe merged 1 commit intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThe Suggested reviewers
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/components/CollapsibleSection.vue (1)
29-35:⚠️ Potential issue | 🟠 MajorFix optional chaining to avoid
undefined.includescrashes.When
document.documentElement.dataset.collapsedis unset,?.split(' ')returnsundefinedand.includes(...)throws. This can break hydration and sidebar behaviour on first load. Use a default empty string and split safely in both locations.Proposed fix
onPrehydrate(() => { const settings = JSON.parse(localStorage.getItem('npmx-settings') || '{}') const collapsed: string[] = settings?.sidebar?.collapsed || [] for (const id of collapsed) { - if (!document.documentElement.dataset.collapsed?.split(' ').includes(id)) { - document.documentElement.dataset.collapsed = ( - document.documentElement.dataset.collapsed + - ' ' + - id - ).trim() - } + const collapsedIds = (document.documentElement.dataset.collapsed ?? '') + .split(' ') + .filter(Boolean) + if (!collapsedIds.includes(id)) { + document.documentElement.dataset.collapsed = [...collapsedIds, id].join(' ') + } } }) onMounted(() => { if (document?.documentElement) { - isOpen.value = !( - document.documentElement.dataset.collapsed?.split(' ').includes(props.id) ?? false - ) + const collapsedIds = (document.documentElement.dataset.collapsed ?? '') + .split(' ') + .filter(Boolean) + isOpen.value = !collapsedIds.includes(props.id) } })Also applies to: 41-43
Coderabbit definitely knows Vue a little better than JS |
Collapsible sections (in the sidebar of package pages) sometimes showed content that weren't clickable.
The problem was that the logic simply checked for the presence of the current section's id in the dataset. For example - if
optional-dependencieswere collapsed, this check also worked fordependenciessection, marking the wrong section as !isOpen.At the same time, the content was visible, since the required style for hiding was not added (it is added by passing through exact ids)