-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: statically analyse universal pages and layouts v3 #13684
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 48210cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
It looks like |
We have to import the module on the server to access
The alternative was #13669 where we're importing modules on demand. This has its own pros and cons such as being more generous before we fallback, logging which export caused the module import on error, but at the same time it introduces more complexities (proxies, requires finding all exports, etc.). |
What's an example combination of settings that would pass there and not here?
I think as long as we can indicate which file it is that should probably be sufficient. Logging which export it is seems like a nicety, but not necessary to me |
You're right. I checked and there are no combinations that would pass differently. Essentially all page options are being checked by SvelteKit whether or not Therefore, the only difference between that PR and this one is that PR will error later (analysis during build) rather than earlier (rendering the route). In which case, I think I'd prefer it to error earlier (this PR).
Good idea. I think I can add that. EDIT: this already happens as part of the current behaviour. |
Assessing all the page options on dev startup makes the basic app test suite take 3-4 seconds instead of 1.5s. Going to try and make it perform the static analysis lazily similar to when the Vite resolves modules. However, build times will definitely get a couple of seconds longer regardless. |
This is looking promising! Wondering if we should append all errors thrown during loading a universal file with "...if you didn't expect this file to be executed, it was executed because of X. If you don't want it to exexute on the server then make sure that Y" (where X is somehow trying to tell you why it got loaded) |
…into static-analysis-v3
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 looks great — if we delete the failing tests (since we probably don't need to worry about those cases) then I think we can merge this
Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
Perhaps we could land #11637 at the same time. I think it's been softened up a bit since the original and improving SPA support at the same time we land it may help soften the blow. I think https://x.com/BenjaminMcCann/status/1844744358429688145 really demonstrates how important it is |
…into static-analysis-v3
closes #12580
Similar to #13669, we use acorn and acorn-ts to analyse the nodes. However, we follow the approach of #13673 where all exports (except
load
and exports prefixed with_
) must have literal values or we fallback to importing the module. Then, we identify which nodes are never used for SSR by computing their page options and any inherited values from their parents. If a node is never used for SSR, that means the server will never access its universalload
function (if any) and we can just provide the page option values we retrieved from static analysis. This allows us to avoid importing the module in Nodeand also avoid importing the component in the build output so that serverless function bundles don't include component code they will never use.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits