-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Support re-exporting astro components containing client components #3625
Conversation
🦋 Changeset detectedLatest commit: 1476acc The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
@@ -71,30 +71,18 @@ export async function collectPagesData( | |||
css: new Set(), | |||
hoistedScript: undefined, | |||
scripts: new Set(), | |||
preload: await ssrPreload({ |
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 removes the "preload" step which was the expensive part of the build that we no longer need to do. Metadata is extracted via the compiler instead.
...internals.discoveredClientOnlyComponents, | ||
...astroConfig._ctx.renderers.map(r => r.clientEntrypoint).filter(a => a) as string[], | ||
...internals.discoveredScripts, | ||
]); |
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.
These are all of the client pieces to build; hydrated and client:only components, renderers, and hoisted scripts.
@@ -138,6 +89,9 @@ export async function staticBuild(opts: StaticBuildOptions) { | |||
await cleanSsrOutput(opts); | |||
} | |||
} else { | |||
// Inject the manifest | |||
await injectManifest(opts, internals) |
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.
The SSR manifest is injected after both builds, so that we can build a full manifest containing all of the asset information.
return JSON.stringify(manifest); | ||
}); | ||
internals.ssrEntryChunk = chunk; | ||
delete bundle[chunkName]; |
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.
The SSR entry is removed from the bundle so that we can inject the manifest post client build.
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.
Very happy to see this! Do you have any benchmarks to measure the perf impact?
Non-blocking, but a bit worried about the custom elements change... Might have some ideas that mostly avoid a breaking change, happy to discuss.
const injectPlugin: VitePlugin = { | ||
name: '@astrojs/netlify/plugin-inject', | ||
generateBundle(_options, bundle) { | ||
if(_buildConfig.serverEntry in bundle) { | ||
const chunk = bundle[_buildConfig.serverEntry]; | ||
if(chunk && chunk.type === 'chunk') { | ||
chunk.code = `globalThis.process = { argv: [], env: {}, };${chunk.code}`; | ||
} | ||
} | ||
} | ||
}; |
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.
Is this related?
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.
No, the Netlify Edge functions were failing in CI, but I think this was broken at the time I created this branch. Looks like the tests were disabled here: #3631
Re: benchmarks -- definitely run this on https://github.com/rebelchris/ddt-v2 and share the stats/results (if they're on a recent enough beta). |
Before
After
32% faster. Note that this PR does not prevent |
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.
Just noticed the drafts
change, are we still handling that somewhere?
// Filter pages by using conditions based on their frontmatter. | ||
Object.entries(allPages).forEach(([page, data]) => { | ||
if ('frontmatter' in data.preload[1]) { | ||
// TODO: add better type inference to data.preload[1] | ||
const frontmatter = (data.preload[1] as any).frontmatter; | ||
if (Boolean(frontmatter.draft) && !this.config.markdown.drafts) { | ||
debug('build', timerMessage(`Skipping draft page ${page}`, this.timer.loadStart)); | ||
delete allPages[page]; | ||
} | ||
} | ||
}); |
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 break drafts
support? Didn't see where this was handled elsewhere.
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.
Hm, I was thinking this was handled in the markdown plugin but I don't see the code for it. There are tests which are passing though. Will investigate more.
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.
The test was just wrong, so this is broken in this branch. Will fix.
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.
Fixed in 2dc17d0
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.
Approved! Nice work.
Feel like this perf boost deserves a callout with an astro
changeset!
…ithastro#3625) * Support re-exporting astro components containing client components * Include metadata for markdown too * Fix ssr, probably * Inject post-build * Remove tagName custom element test * Allows using the constructor for lit elements * Fix hoisted script scanning * Pass through plugin context * Get edge functions working in the edge tests * Fix types for the edge function integration * Upgrade the compiler * Upgrade compiler version * Better release notes for lit * Update .changeset/unlucky-hairs-camp.md Co-authored-by: Nate Moore <[email protected]> * Properly test that the draft was not rendered * Prevent from rendering draft posts * Add a changeset about the build perf improvement. Co-authored-by: Nate Moore <[email protected]>
Changes
Testing
Docs
N/A, perf improvement