-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
qol(cookies): warn when cookies are set after the headers have been sent #9627
Conversation
🦋 Changeset detectedLatest commit: 3a04310 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (this.#consumed) { | ||
console.error(new Error( | ||
"Astro.cookies.set() was called after the cookies have already been sent to the browser.\n" + | ||
"This may have happened if this method was called in an imported component.\n" + | ||
"Please make sure that Astro.cookies.set() is only called in the frontmatter of the main page." | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this.#consumed) { | |
console.error(new Error( | |
"Astro.cookies.set() was called after the cookies have already been sent to the browser.\n" + | |
"This may have happened if this method was called in an imported component.\n" + | |
"Please make sure that Astro.cookies.set() is only called in the frontmatter of the main page." | |
)); | |
} | |
if (this.#consumed) { | |
console.error(new Error( | |
"Astro.cookies.set() was called after the cookies were already sent to the browser.\n" + | |
"This may have happened if this method was called in an imported component.\n" + | |
"Please make sure that Astro.cookies.set() is only called in the frontmatter of the main page." | |
)); | |
} |
console.error(new Error( | ||
"Astro.cookies.set() was called after the cookies have already been sent to the browser.\n" + | ||
"This may have happened if this method was called in an imported component.\n" + | ||
"Please make sure that Astro.cookies.set() is only called in the frontmatter of the main page." | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be console.warn
with a plain string instead according to the PR title? It feels like if we report an error, it usually means the request failed and returns 500 (or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I addressed this in e29b456
(#9627)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much better, but we still need to provide some context as to where cookies.set()
was called. Instantiating the error was one way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes
Testing
Warning only. Does not affect behavior.
Docs
Does not affect usage. Although general elaboration on streaming is overdue.