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

fix(nuxt): return RenderResponse for redirects #20496

Merged
merged 7 commits into from Apr 28, 2023
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Apr 25, 2023

πŸ”— Linked issue

#20244 (comment)
resolves #20294
resolves #20432

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This adds an internal way for Nuxt composables to predetermine the type of response from the render handler, rather than directly interacting with event.node.res. It then updates navigateTo handling to use this internal ._renderResponse property for indicating status code, etc. There is space here for improving this, including maybe using h3's sendRedirect method behind the scenes in nitro so we don't have to generate the HTML body, for example.

The hook app:redirected was also only added for the purpose of setting cookies before immediately returning a response. But now app:rendered is just as good a response, and we might consider deprecating app:redirected in favour of app:rendered. Thoughts welcome.

Finally, we resolve an issue with setup functions loading even after a redirect by switching from beforeEach to afterEach, and add a test fixture.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Apr 25, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Smart solution love it πŸ’―

packages/nuxt/src/app/composables/router.ts Show resolved Hide resolved
@danielroe danielroe merged commit f73bb1d into main Apr 28, 2023
17 checks passed
@danielroe danielroe deleted the fix/redirect-response branch April 28, 2023 10:18
This was referenced Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants