-
Notifications
You must be signed in to change notification settings - Fork 6
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
HTTP Header directive not used for RSC requests #100
Comments
The issue is that the default {
"cache-control": "must-revalidate",
"Cache-Control": "s-maxage=1"
} I was not able to reproduce any issues with the headers regarding the response type being HTML or RSC. In both cases, the headers were applied properly. But when the page or RSC is static exported, these headers will not be applied. This could be an enhancement in the SSG feature set: store the response headers besides the HTML or RSC payload and use that information when serving the static files. If this is the requested feature, then I would suggest to move the feature request into a separate issue. |
there is no need to set header for static rendered pages RSC Cache-Control But because the header in the RSC response is missing the additonal entry |
Can you reproduce this issue when running the app locally using Node.js? I'm testing this with a minimal component: import { headers } from "@lazarv/react-server";
export default function App() {
headers({
"cache-control": "s-maxage=1",
});
return <div>Hello World</div>;
} Just running: Response headers are:
Works both in dev and a production build. |
I changed my code to use the lowercase version of But your own react-server header docu and the official moz docs use the Pascal-Case names. It should be handled by Based on the same specs multiple headers with the same name - e.g.:
are merged when the header supports multiple entries which is correct for Why not use the office Javascript Header Object which handles this with |
Handling cookies is a very specific use case, there's an API for it just exposing the HatTip cookie store. https://react-server.dev/framework/http#cookies In the linked PR, there's a minimal resolution to the case-sensitivity issue, which only affects headers that are also handled by the framework and not just the developer using it, in cases like But you're right regarding the store for the headers as the case-sensitivity issue could be an error in the app using the framework, not just inside the framework and the framework should prevent this issue. So I'm thinking about a new API similar to the cookie handling functions, |
I found the problem, I build my apps with defining root in the {
"root": "src"
} you find my example here: react-server build
react-server start get the RSC response with wrong curl 'http://localhost:3000/s/page/hello/rsc.x-component' \
-H 'Accept: text/x-component,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' -vv
* Host localhost:3000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:3000...
* Connected to localhost (::1) port 3000
> GET /s/page/hello/rsc.x-component HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/8.7.1
> Accept: text/x-component,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
>
* Request completely sent off
< HTTP/1.1 200 OK
< cache-control: must-revalidate
< content-type: text/x-component; charset=utf-8
< last-modified: Thu, 19 Dec 2024 17:49:42 GMT
< Date: Thu, 19 Dec 2024 17:49:42 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
0:[[],"$L1"]
1:[[],["$","div",null,{"children":"Hello"}]]
* Connection #0 to host localhost left intact I can also replicate the problem if I build an app without specifying a root file when calling I can even reproduce the problem without using the
curl 'http://localhost:3000/hello/rsc.x-component' \
-H 'Connection: keep-alive' \
-H 'React-Server-Outlet: PAGE_ROOT' \
-H 'Referer: http://localhost:3000/' \
-H 'accept: text/x-component' \
-vv
* Host localhost:3000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:3000...
* Connected to localhost (::1) port 3000
> GET /hello/rsc.x-component HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/8.7.1
> Connection: keep-alive
> React-Server-Outlet: PAGE_ROOT
> Referer: http://localhost:3000/
> accept: text/x-component
>
* Request completely sent off
< HTTP/1.1 200 OK
< cache-control: must-revalidate
< content-type: text/x-component; charset=utf-8
< last-modified: Thu, 19 Dec 2024 17:59:14 GMT
< Date: Thu, 19 Dec 2024 17:59:14 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
0:[[],"$L1"]
1:[[],"$L2"]
2:["$","div",null,{"children":"Hello World 02"}]
* Connection #0 to host localhost left intact What is very dangerous that any file called |
Moves route matching and route component loading into middleware when using the file-system based router to remove async implementation in the React Server Component entrypoint of the router. Changes RSC payload handling to use the same approach as in the HTML SSR renderer to handle async components better. Introduces a rendering lock mechanism to suspend sending the response to be able to handle response headers in async components until the lock is released. Refactors HTTP response header handling to use `Headers` directly and introduces helper functions to set, append, delete, or clear response headers in the HTTP context. Fixes an issue with accessing the `Response` sent to the client when using `useResponse` in an async React Server Component. Adds test cases for above changes and updates the docs to include the new helpers and to give more details about how to handle response headers. #100
Thanks for all the details @aheissenberger! This was a huge catch and an extremely important fix was needed to address this issue in the file-system based router entrypoint component, which was unnecessarily an async component, forcing the rendering to skip any response header changes in any React components when sending an RSC payload. I also changed how to handle response headers and while it was quick and convenient to use a simple object to store the response headers, it was also an incomplete and poor solution. Some more information is in the PR description at #106 |
Describe the bug
When I add a http header to a page, the header is added to the page request but not to the RSC request.
This is specifically a problem for HTTP Cache headers which define how long a content can be cached on the client side and at the proxy (CDN).
I am not sure if there are other header which need to be set on RSC streams. Maybe a simple optional option
{"rsc":true}
on the existing function could solve this:Or maybe a specific
cacheHeader
function?It looks like you currently merge the new entry to the existing one as the result is:
Cache-Control: must-revalidate, s-maxage=1
Maybe a second option to define this would help to replace the
must-revalidate
:Reproduction
https://d53oahuh7w7td.cloudfront.net/s/page/hello
Steps to reproduce
request the page e.g. https://d53oahuh7w7td.cloudfront.net/s/page/hello - this is OK:
go to an other page and come back - or load this url:
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: