-
-
Notifications
You must be signed in to change notification settings - Fork 637
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
Conversation
…loader based on its exports
☁️ Nx Cloud ReportCI is running/has finished running commands for commit cf3d8d1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
…ties inside the virtual split
return str | ||
}, '') | ||
|
||
const warningMessage = `These exports from "${opts.filename.replace('?' + splitPrefix, '')}" are not being code-split and will increase your bundle size: ${list}\nThese should either have their export statements removed or be imported from another file that is not a route.` |
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
or loader
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:
// this export ident here
export const loadUser = async () => {
return { user: 'john' }
}
export const Route = createFileRoute('/login')({
loader: loadUser
})
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.
could we just disable automatic code splitting for start and it would still work?
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
TanStackRouterVite({ | |
...tsrConfig, | |
autoCodeSplitting: true, | |
experimental: { | |
...tsrConfig.experimental, | |
}, | |
}), |
From https://discord.com/channels/719702312431386674/1283438765817331712
When using
autoCodeSplitting
, we need to take into account the scenario where the user is exporting theircomponent
orloader
from the route file. Consider this route before code-splitting:An assumption can be made here, that if the user is exporting the
component
orloader
from this file, then they expect to import it into another file.As such, the current strategy of nuking the
component
orloader
, once it has been detected for use in thecreateFileRoute
function will not work, as a user wouldn't then be able to make the import from another file since it would no longer exist.Therefore, if the
component
orloader
is being exported, then code removal shouldn't happen and it should retain the item in the same compiled file. As such, since the item remains in the same file, we can skip performing an import.A warning is also going to be added into the
console
, so the user knows that this function is not being code-split.