Fix barrel self-import when a route name is both a leaf and a prefix … - #317
Merged
joetannenbaum merged 3 commits intoSep 8, 2026
Merged
Conversation
…of "index" A barrel child named "index" is written to "index/index.ts", but the generated import referenced "./index". Every resolver prefers the sibling "index.ts", so the barrel imported itself. With `photos.index` and `photos.index.window`, `photos/index.ts` emitted `import index<hash> from './index'`, producing TS7022 and TS2303 under tsc. Bundlers accepted it silently because `Object.assign(index, undefined)` is a no-op, so `photos.index.window` was dropped with no warning. When the "index" prefix has no leaf route of its own, such as `albums.index.recent`, the previous `$key !== 'index'` filter removed the import altogether while still emitting `Object.assign(index, index)`, leaving `index` undeclared: TS2304, and a ReferenceError at runtime. Import such a child by its full path instead, and narrow the filter so it only drops an "index" child that has no grandchildren, keeping the actions path unchanged.
Collaborator
|
Thank you! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…of "index"
A barrel child named "index" is written to "index/index.ts", but the generated import referenced "./index". Every resolver prefers the sibling "index.ts", so the barrel imported itself.
With
photos.indexandphotos.index.window,photos/index.tsemittedimport index<hash> from './index', producing TS7022 and TS2303 under tsc. Bundlers accepted it silently becauseObject.assign(index, undefined)is a no-op, sophotos.index.windowwas dropped with no warning.When the "index" prefix has no leaf route of its own, such as
albums.index.recent, the previous$key !== 'index'filter removed the import altogether while still emittingObject.assign(index, index), leavingindexundeclared: TS2304, and a ReferenceError at runtime.Import such a child by its full path instead, and narrow the filter so it only drops an "index" child that has no grandchildren, keeping the actions path unchanged.