fix: redirect when using RSC #292
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR fixes redirects when using RSC rendering, including redirecting when using navigation with
<Link>component from@lazarv/react-server/navigation.As redirects are throwing a redirect error, this means that this PR implements enhanced error handling for RSC payloads, handling the request gracefully when an error is included in the RSC payload. In case there's a client-side error during the RSC request, a new RSC payload is constructed with the error included.
The
redirect()function is now aware of what type of response is expected using the rendering context and sets an RSC payload as the redirect response for RSC requests.The file-system based router was fixed to handle middleware redirects when using a web standard
Response.redirectresponse with an RSC context. When detected, the response will be changed to an RSC redirect error.Client-side redirect handling is now aware about external redirects and in case of the redirect location is external, it fires a browser page navigation using replace.
Error boundary components are now handling browser history change with a page reload when needed, to re-render the page after navigation.
The
file-routerexample app was extended to include various redirect use cases, and the test suite for the example app was also extended to test redirects too.