-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(nuxt): payload rendering support #6455
Conversation
β Deploy Preview for nuxt3-docs canceled.
|
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! Would be nice to see some tests as well.
Mind if I push a test suite later this evening before merging? |
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.
Looks good to me!
Some suggestions for follow-up PRs:
- enabling static in dev mode without the method I used in tests - user may have an API that can't be called from browser or relies on server-only api keys
- hybrid mode (as you mention)
process.env.prerender
- presumably we'll set this somehow in nitropack whilst prerendering?- would be nice to deduplicate payloads - e.g. if you hard load
/random/a
then it should 'fill' the payload and not redownload it when navigating from a -> b -> a. - [another note: would be nice to have support for testing generated or hybrid sites in test-utils - cc: @antfu]
Thanks for helping to add tests @danielroe β€οΈ Regarding your notes:
Later, with route rules, we could predict which routes are prerendered/static to adjust behavior. But note that payload rendering is not only for static mode (ie: server API keys available during prerendering phase. that should work in production too and with API fallback)
It is already added and released from nitropack which I've used. If it doesn't work, not only is a performance issue but a security issue because an attacker could fill the memory of server by abusing payload cache. I plan to improve it later with a shared LRU.
Not quite sure to understand this. Payload state is fresh per page and payload URL is unique. We don't download by with but use dynamic import. Browsers have caching mechanism for esm imports and don't redownload. (unless using new hash to force download a new payload). Also note that we are splitting data/state from initial payload (runtime config and other top level keys)
Do you mind to open an issue to elaborate more about your idea about possible utils? |
6745fc1
to
374429a
Compare
π Linked issue
nuxt/nuxt#14507
β Type of change
π Description
This PR:
/_payload.js
to the end of the URL, returning only payload chunkloadPayload(url, force?)
composableprefetchPayload(url)
composablemodulepreload
relcallsSame as server addsusePayload(url)
to fill in the cachemodulepreload
to trigger browser prefetching in backgroundnuxt generate
orprefetchPayload(url)
, it detect rendering mode based on headers and sets thex-nitro-prerender
hint to prerender/[route]/_payload.js
fileprerenderedAt
to the payload when using prerendering or nuxt generateisPrerendered
composable (check active payload)Testing:
yarn nuxt build test/fixtures/basic
node test/fixtures/basic/.output/server/index.mjs
Todo:
π Checklist