`cookies` seems to work in Client Components when dynamically imported
Unanswered
Lenz Weber-Tronic posted this in #help-forum
Someone just pointed out in our issues that this code seems to work inside of Client Components:
To my knowledge,
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
@Lenz Weber-Tronic Someone just pointed out in our issues that this code seems to work inside of Client Components:
js
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?
Yes it’s a bug, or at least an undocumented behaviour. Undocumented behaviours are not semver’d hence should not be used
Thank you, I'll pass that on!