Skip to content
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

Merged
merged 8 commits into from
Jan 10, 2024

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Jan 5, 2024

Changes

Testing

Warning only. Does not affect behavior.

Docs

Does not affect usage. Although general elaboration on streaming is overdue.

Copy link

changeset-bot bot commented Jan 5, 2024

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 5, 2024
@github-actions github-actions bot added the pr: docs A PR that includes documentation for review label Jan 5, 2024
@lilnasy lilnasy marked this pull request as ready for review January 5, 2024 22:51
Comment on lines 153 to 159
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."
));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
));
}

Comment on lines 154 to 158
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."
));
Copy link
Member

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)

Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@sarah11918 sarah11918 removed the pr: docs A PR that includes documentation for review label Jan 9, 2024
@lilnasy lilnasy requested a review from bluwy January 9, 2024 16:22
@lilnasy lilnasy merged commit a700a20 into main Jan 10, 2024
13 checks passed
@lilnasy lilnasy deleted the 7715 branch January 10, 2024 14:51
@astrobot-houston astrobot-houston mentioned this pull request Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not delete cookie when in function scope
5 participants