Next.js Discord

Discord Forum

`cookies` seems to work in Client Components when dynamically imported

Unanswered
Lenz Weber-Tronic posted this in #help-forum
Open in Discord
Someone just pointed out in our issues that this code seems to work inside of Client Components:

const forwardCookieLink = setContext(async () => {
  return import("next/headers").then(({ cookies }) => {
    const headers = {
      headers: {
        cookie: cookies()
          .getAll()
          .map(({ name, value }) => `${name}=${value}`)
          .join(";"),
      },
    };
    console.log(headers);
    return headers;
  });
});


To my knowledge, "next/headers" is not intended to work in Client Components. Am I right to assume that this is a bug and should not be used?

2 Replies