-
Notifications
You must be signed in to change notification settings - Fork 0
fix(packages/core): emit sidebar keys for orphaned workspace children #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
899e1f6
fix(packages/core): emit sidebar keys for orphaned workspace children
zrosenbauer f077024
fix(packages/core): address PR lint feedback in multi-sidebar tests
zrosenbauer b49d425
Update packages/core/src/sync/sidebar/multi.test.ts
zrosenbauer 512e141
Merge branch 'main' into fix/workspaces
zrosenbauer 1dc727d
fix(packages/core): strengthen multi-sidebar test assertions
zrosenbauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@zpress/core': patch | ||
| --- | ||
|
|
||
| Fix multi-sidebar routing for workspace children whose paths live outside the parent prefix. When `packages` items use paths like `/libs/ai` instead of `/packages/ai`, Rspress prefix matching could not find a sidebar key — the sidebar silently disappeared. Extra sidebar keys are now emitted for orphaned child paths so they resolve correctly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
|
|
||
| import type { ResolvedEntry } from '../types' | ||
| import { buildMultiSidebar } from './multi' | ||
|
|
||
| describe('buildMultiSidebar()', () => { | ||
| it('should place non-standalone entries under the root "/" key', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Guides', | ||
| link: '/guides', | ||
| items: [ | ||
| { title: 'Setup', link: '/guides/setup', page: { outputPath: 'guides/setup.md', frontmatter: {} } }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| expect(result['/']).toBeDefined() | ||
| expect(result['/'].length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it('should create sidebar keys for standalone entries', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Apps', | ||
| link: '/apps', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'API', link: '/apps/api' }, | ||
| { title: 'Web', link: '/apps/web' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| expect(result['/apps']).toBeDefined() | ||
| expect(result['/apps/']).toBeDefined() | ||
| }) | ||
|
|
||
| it('should create orphaned child keys when children live outside parent prefix', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'AI', link: '/libs/ai' }, | ||
| { title: 'Database', link: '/libs/database' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| // Parent keys still exist | ||
| expect(result['/packages']).toBeDefined() | ||
| expect(result['/packages/']).toBeDefined() | ||
|
|
||
| // Orphaned child keys are created | ||
| expect(result['/libs/ai']).toBeDefined() | ||
| expect(result['/libs/ai/']).toBeDefined() | ||
| expect(result['/libs/database']).toBeDefined() | ||
| expect(result['/libs/database/']).toBeDefined() | ||
| }) | ||
|
|
||
| it('should use the same sidebar content for orphaned keys as the parent', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'AI', link: '/libs/ai' }, | ||
| { title: 'DB', link: '/libs/db' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| expect(result['/libs/ai/']).toEqual(result['/packages/']) | ||
| expect(result['/libs/db/']).toEqual(result['/packages/']) | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('should not create orphaned keys for children that match the parent prefix', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Apps', | ||
| link: '/apps', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'API', link: '/apps/api' }, | ||
| { title: 'Web', link: '/apps/web' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| const keys = Object.keys(result) | ||
| // Only root, /apps, and /apps/ — no extra orphaned keys | ||
| expect(keys).not.toContain('/apps/api') | ||
| expect(keys).not.toContain('/apps/api/') | ||
| expect(keys).not.toContain('/apps/web') | ||
| expect(keys).not.toContain('/apps/web/') | ||
| }) | ||
|
|
||
| it('should handle mixed children where some match and some are orphaned', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'Utils', link: '/packages/utils' }, | ||
| { title: 'AI', link: '/libs/ai' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| // Parent keys exist | ||
| expect(result['/packages']).toBeDefined() | ||
| expect(result['/packages/']).toBeDefined() | ||
|
|
||
| // Only orphaned child gets extra keys | ||
| expect(result['/libs/ai']).toBeDefined() | ||
| expect(result['/libs/ai/']).toBeDefined() | ||
|
|
||
| // Matched child does NOT get extra keys | ||
| expect(Object.keys(result)).not.toContain('/packages/utils') | ||
| expect(Object.keys(result)).not.toContain('/packages/utils/') | ||
| }) | ||
|
|
||
| it('should handle standalone entry with no children', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
|
|
||
| expect(result['/packages']).toBeDefined() | ||
| expect(result['/packages/']).toBeDefined() | ||
| }) | ||
|
|
||
| it('should sort sidebar keys by length descending', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { title: 'Guides', link: '/guides', items: [{ title: 'Setup', link: '/guides/setup' }] }, | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| items: [{ title: 'AI', link: '/libs/ai' }], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
| const keys = Object.keys(result) | ||
|
|
||
| // Keys should be sorted by length descending | ||
| const lengths = keys.map((k) => k.length) | ||
| const sorted = lengths.toSorted((a, b) => b - a) | ||
| expect(lengths).toEqual(sorted) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| it('should include the parent landing link in orphaned sidebar content', () => { | ||
| const entries: ResolvedEntry[] = [ | ||
| { | ||
| title: 'Packages', | ||
| link: '/packages', | ||
| standalone: true, | ||
| items: [ | ||
| { title: 'AI', link: '/libs/ai' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const result = buildMultiSidebar(entries, []) | ||
| const sidebar = result['/libs/ai/'] as { text: string; link: string }[] | ||
|
|
||
| // First item should be the parent landing link | ||
| expect(sidebar[0]).toMatchObject({ text: 'Packages', link: '/packages' }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.