-
-
Notifications
You must be signed in to change notification settings - Fork 575
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
fix(router-plugin): do not split if known ident is exported #2334
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
51b3f3c
fix(router-plugin): do not split component if ident is being exported
SeanCassiere 416ad59
fix(router-plugin): better logic for not splitting the component and …
SeanCassiere 205b060
fix(router-plugin): handle the split file case
SeanCassiere fbf60c6
test(router-plugin): handling the component and loader being exported…
SeanCassiere 1c82c28
fix(router-plugin): handle named exports that are functions
SeanCassiere 919449e
fix(router-plugin): use an else-if
SeanCassiere b59a7b4
test(router-plugin): check that function exports are also being retained
SeanCassiere d890bad
refactor(router-plugin): simplified code-path for handling the proper…
SeanCassiere 7eb0300
refactor(router-plugin): add a more descriptive warning message
SeanCassiere a50bb7a
test(router-plugin): add more test cases
SeanCassiere cf3d8d1
Merge branch 'main' into codesplitting-retain-default-exports
SeanCassiere 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
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
packages/router-plugin/tests/code-splitter/snapshots/retain-export-component.tsx
This file contains 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,27 @@ | ||
const $$splitLoaderImporter = () => import('tsr-split:retain-export-component.tsx?tsr-split'); | ||
import { lazyFn } from '@tanstack/react-router'; | ||
import { createFileRoute, Outlet } from '@tanstack/react-router'; | ||
import { importedComponent as ImportedComponent } from '../shared/imported'; | ||
export function Layout() { | ||
return <main> | ||
<header style={{ | ||
height: HEADER_HEIGHT | ||
}}> | ||
<nav> | ||
<ul> | ||
<li> | ||
<a href="/">Home</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
</header> | ||
<ImportedComponent /> | ||
<Outlet /> | ||
</main>; | ||
} | ||
export const Route = createFileRoute('/_layout')({ | ||
component: Layout, | ||
loader: lazyFn($$splitLoaderImporter, 'loader') | ||
}); | ||
const HEADER_HEIGHT = '63px'; | ||
export const SIDEBAR_WIDTH = '150px'; |
4 changes: 4 additions & 0 deletions
4
packages/router-plugin/tests/code-splitter/snapshots/retain-export-component@split.tsx
This file contains 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,4 @@ | ||
console.warn("These exports from \"retain-export-component.tsx\" are not being code-split and will increase your bundle size: \n- Layout\nThese should either have their export statements removed or be imported from another file that is not a route."); | ||
import { importedLoader } from '../shared/imported'; | ||
const loader = importedLoader; | ||
export { loader }; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this cause a problem with Start?
will Start properly work with some non-code-split routes?
it Start will not work, then we should throw a fatal error in case we are building for Start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only capturing if the
component
orloader
is being exported out of the route file. It'll detect it both for Start and Router since this happens during dev and at build time (not at runtime).This is the example that are checking for:
In this case, we can't code-split the
loadUser
fn, since other external files may be imported from this source file.So it needs to remain as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood, but is skipping a route from code splitting posing any problems in TanStack Start? i.e. could we just disable automatic code splitting for start and it would still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could choose to turn it off automatic code-splitting on our side, but currently, we force it ON in the Start config.
router/packages/start/src/config/index.ts
Lines 290 to 296 in 8fde2ef