next-runtime
next-runtime copied to clipboard
fix: add text/x-component header to .rsc assets generated at build time, don't use rsc-data edge function when hitting .rsc path directly
Description
When working on something else I noticed quite the weirdness with how rsc-data middleware behaves when it comes to routing:
# hitting /blog/erica/first-post
Aug 31, 06:02:32 PM: 01H9659Z info Is rsc request
Aug 31, 06:02:32 PM: 01H9659Z info Rewriting to /blog/erica/first-post.rsc
# hitting /blog/erica/first-post/
Aug 31, 06:06:23 PM: 01H965H0 info Is rsc request
Aug 31, 06:06:23 PM: 01H965H0 info Rewriting to /blog/erica/first-post.rsc/
# hitting /blog/erica/first-post.rsc
Aug 31, 06:07:18 PM: 01H965JP info Is rsc request
Aug 31, 06:07:18 PM: 01H965JP info Rewriting to /blog/erica/first-post.rsc.rsc
as /blog/erica/first-post.rsc is actually asset produced at build time:
so only the first request from logs above one worked correctly. Second one did seem to work, but instead of using static asset on CDN it wen't to lambda to generate it and third one I don't even remember but it definitely seems wrong.
I'm not exactly sure why we make edge middleware to handle requests for .rsc paths - when trying that path we should just use path as-is - it will either use static asset from CDN or go to lambda to generate it (and possibly cache with with ODB). I did remove that from this PR as it didn't make sense to me, especially as it was redirecting to /blog/erica/first-post.rsc.rsc which seems all kind of wrong thing to do.
The statically produced .rsc files also didn't get expected text/x-component header (we only get this header right now when request is handled by lambda), so I also added header rule to ensure those get expected headers.
And finally I'm not sure why the rsc-data would want to rewrite to paths that end with trailing slash (.rsc/) - the comment say to differentiate those for ODB, but with no clarity why you want to do that? It also meant that if user hit path with trailing slash it would never use static assets on CDN and would always need to go through lambda
Documentation
Tests
You can test this change yourself like so:
- TODO
Relevant links (GitHub issues, etc.) or a picture of cute animal
Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/64f1bf2bc2c07c0008c0f0b6 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for next-plugin-edge-middleware ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/64f1bf2baff88600086fdad8 |
| Deploy Preview | https://deploy-preview-2290--next-plugin-edge-middleware.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/64f1bf2bc00a9800080703c5 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-next-auth-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for netlify-plugin-nextjs-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/64f1bf2bb1b61600086bc598 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for nextjs-plugin-custom-routes-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/64f1bf2b120f180008dc81d4 |
| Deploy Preview | https://deploy-preview-2290--nextjs-plugin-custom-routes-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/64f1bf2be797ce0008fb6e18 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-static-root-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for netlify-plugin-nextjs-demo-all-flags ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-demo-all-flags/deploys/64f1bf2b120f180008dc81d9 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-demo-all-flags.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for next-plugin-canary ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/next-plugin-canary/deploys/64f1bf2b0d1dd500072ba999 |
| Deploy Preview | https://deploy-preview-2290--next-plugin-canary.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for netlify-plugin-nextjs-export-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/64f1bf2be0a2a60008ae05f3 |
| Deploy Preview | https://deploy-preview-2290--netlify-plugin-nextjs-export-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Deploy Preview for next-i18next-demo ready!
| Name | Link |
|---|---|
| Latest commit | 44e7843464e807f35f81652bedac07263a80e756 |
| Latest deploy log | https://app.netlify.com/sites/next-i18next-demo/deploys/64f1bf2bd087980008db10c7 |
| Deploy Preview | https://deploy-preview-2290--next-i18next-demo.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
I think the reason was because at the time at least Next didn't request .rsc files directly. We were adding the .rsc to we could either load the static asset, or get a different asset from the ODB as we couldn't vary on the RSC header. I dunno which of those have now changed
Superseded by v5.