Skip to content

HTTP Header directive not used for RSC requests #100

@aheissenberger

Description

@aheissenberger

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:

headers(
  { "Cache-Control": "s-maxage=1" } ,
  {"rsc":true}
);

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:

headers({
      "Cache-Control": "s-maxage=1",
    },{"replace":true});

Reproduction

https://d53oahuh7w7td.cloudfront.net/s/page/hello

Steps to reproduce

  1. add a cache header to a non static page:
  import { headers } from "@lazarv/react-server";

  export default async function HelloPage() {
    headers({
      "Cache-Control": "s-maxage=1",
    });
  
    return (
  1. request the page e.g. https://d53oahuh7w7td.cloudfront.net/s/page/hello - this is OK:
    image

  2. go to an other page and come back - or load this url:
    image

System Info

System:
    OS: macOS 15.2
    CPU: (12) arm64 Apple M4 Pro
    Memory: 3.07 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 9.15.0 - /opt/homebrew/bin/pnpm
    bun: 1.1.40 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 131.0.6778.140
    Safari: 18.2
    Safari Technology Preview: 18.2
  npmPackages:
    @lazarv/react-server: workspace:^ => 0.0.0 
    @lazarv/react-server-adapter-aws: workspace:^ => 0.0.0

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions