Conversation
✅ Deploy Preview for nuxt3-docs canceled.
|
danielroe
left a comment
There was a problem hiding this comment.
❤️ This looks great! Would be nice to see some tests as well.
|
Mind if I push a test suite later this evening before merging? |
danielroe
left a comment
There was a problem hiding this comment.
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/athen 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.jsto the end of the URL, returning only payload chunkloadPayload(url, force?)composableprefetchPayload(url)composablemodulepreloadrelcallsSame as server addsusePayload(url)to fill in the cachemodulepreloadto trigger browser prefetching in backgroundnuxt generateorprefetchPayload(url), it detect rendering mode based on headers and sets thex-nitro-prerenderhint to prerender/[route]/_payload.jsfileprerenderedAtto the payload when using prerendering or nuxt generateisPrerenderedcomposable (check active payload)Testing:
yarn nuxt build test/fixtures/basicnode test/fixtures/basic/.output/server/index.mjsTodo:
📝 Checklist