Skip to content

Fix barrel self-import when a route name is both a leaf and a prefix … - #317

Merged
joetannenbaum merged 3 commits into
laravel:mainfrom
imanimen:fix/index-leaf-and-prefix-collision
Sep 8, 2026
Merged

Fix barrel self-import when a route name is both a leaf and a prefix …#317
joetannenbaum merged 3 commits into
laravel:mainfrom
imanimen:fix/index-leaf-and-prefix-collision

Conversation

@imanimen

@imanimen imanimen commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

…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.

…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.
@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you!

@joetannenbaum
joetannenbaum merged commit 043c4af into laravel:main Sep 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants