Skip to content

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jun 26, 2025

🔗 Linked issue

resolves #32472

📚 Description

this uses appendResponseHeader so set-cookie can be merged (by browser).

Co-authored-by: Peter Graugaard <pgn@altinget.dk>
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Jun 26, 2025

Walkthrough

The code was updated to modify how HTTP response headers are set when handling errors. Specifically, the import from the 'h3' library now includes the appendResponseHeader function. In the process of copying headers from an error page response, the code checks if the header is set-cookie. If it is, appendResponseHeader is used to add the header, allowing multiple set-cookie values to be sent. For all other headers, the existing setResponseHeader function continues to be used. No changes were made to exported or public entity declarations.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67cf2bf and f697af0.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/runtime/nitro/handlers/error.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: Follow standard TypeScript conventions and best practices

**/*.ts: Follow standard TypeScript conventions and best practices

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • packages/nuxt/src/core/runtime/nitro/handlers/error.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: codeql (actions)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (2)
packages/nuxt/src/core/runtime/nitro/handlers/error.ts (2)

3-3: LGTM! Appropriate import addition.

The addition of appendResponseHeader to the h3 import is correctly positioned and necessary for the set-cookie header handling functionality.


77-80: Excellent fix for set-cookie header handling.

This implementation correctly addresses the issue where multiple set-cookie headers would be overwritten. The conditional logic properly:

  • Uses appendResponseHeader for set-cookie headers to preserve multiple values
  • Maintains existing behaviour for all other headers
  • Follows HTTP standards where set-cookie headers must be sent separately

The continue statement ensures the normal setResponseHeader call is skipped for set-cookie headers, preventing any potential conflicts.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix/set-cookie-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jun 26, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32483

nuxt

npm i https://pkg.pr.new/nuxt@32483

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32483

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32483

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32483

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32483

commit: f697af0

Copy link

codspeed-hq bot commented Jun 26, 2025

CodSpeed Performance Report

Merging #32483 will not alter performance

Comparing fix/set-cookie-error (f697af0) with main (67cf2bf)

Summary

✅ 10 untouched benchmarks

@@ -74,6 +74,10 @@ export default <NitroErrorHandler> async function errorhandler (error, event, {

const html = await res.text()
for (const [header, value] of res.headers.entries()) {
if (header === 'set-cookie') {
appendResponseHeader(event, header, value)
Copy link
Member

@pi0 pi0 Jun 26, 2025

Choose a reason for hiding this comment

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

Parse + using setCookie might be much safer for merging.

(append does not merges but sends duplicate headers, clients/browser should respect and merge)

Copy link
Member Author

@danielroe danielroe Jun 26, 2025

Choose a reason for hiding this comment

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

this is an already-serialised 'set-cookie' header, not a raw value. what we're doing here is very similar to the mergeHeaders function in h3:

https://github.com/unjs/h3/blob/67af0575eb2078ba4c2ed1c535dfc168a4e578e6/src/response.ts#L101-L111

Copy link
Member Author

@danielroe danielroe Jun 26, 2025

Choose a reason for hiding this comment

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

the issue is that we want to preserve the existing headers, as they are, rather than flattening them into a single set-cookie header.

merging to iterate, but let me know if you have any concerns 🙏

@danielroe danielroe merged commit 7bbddea into main Jun 26, 2025
83 of 85 checks passed
@danielroe danielroe deleted the fix/set-cookie-error branch June 26, 2025 13:53
@github-actions github-actions bot mentioned this pull request Jun 26, 2025
danielroe added a commit that referenced this pull request Jul 1, 2025
Co-authored-by: Peter Graugaard <pgn@altinget.dk>
@github-actions github-actions bot mentioned this pull request Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error page discards all but the last Set-Cookie header from response
2 participants