Skip to content

Add way to interrupt response handling for client side navigation. #603

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

Merged
merged 21 commits into from
Jul 22, 2025

Conversation

peterp
Copy link
Member

@peterp peterp commented Jul 16, 2025

When client-side navigation is initialized, we use fetch to request a new RFC payload. This RSC payload can also be an invalid response.
In which case, client-side navigation breaks. This PR includes the ability to manually handle the response and determine whether it's an error, and then to just forward the browser directly to that page so that the user gets the proper experience.

const { handleResponse } = initClientNavigation()
initClient({ handleResponse })

edit(justinvdm, 22 Jul 2025):
This PR also now includes the changes needed to get this same functionality to work with the realtime: interruptors + client navigation + realtime client:

const { handleResponse } = initClientNavigation()
initRealtimeClient({ handleResponse })

The main changes on the realtime side:

  • refactoring
    • to avoid repetition on worker and client side: ACTION_* messages (when a client triggers an action and we're getting the corresponding response) and RSC_* messages (when server sends up an update - e.g. as a result of a different client's triggering an action) now reuse logic where possible
    • packing and unpacking protocol messages now encapsulated in packMessage + unpackMessage + types for protocol messages
  • This refactoring allowed to make way for
    • including a status code to use to rehydrate Responses over websocket on client side - without refactoring this turned out to be surprisingly difficult
    • for both ACTION_* and RSC_* messages, allow for short-circuiting processing of responses using handleResponses - to integrate with client navigation

Fixes #601

Copy link

cloudflare-workers-and-pages bot commented Jul 16, 2025

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 45cf1d0
Status: ✅  Deploy successful!
Preview URL: https://08dde8ec.redwood-sdk-docs.pages.dev
Branch Preview URL: https://pp-handle-error-responses.redwood-sdk-docs.pages.dev

View logs

@peterp peterp requested a review from justinvdm July 16, 2025 13:57
@peterp
Copy link
Member Author

peterp commented Jul 16, 2025

Hey @justinvdm , one of the issues that I have is that I don't know how to make this work for real-time. Could you maybe explain to me how we deal with non-200 responses in real-time?

@justinvdm
Copy link
Collaborator

I've got it working, want to test it more thoroughly later today before merging and releasing, but looks like its working.

If you'd like to try it:

@justinvdm justinvdm merged commit ccccd4b into main Jul 22, 2025
5 checks passed
@justinvdm
Copy link
Collaborator

@peterp released in https://github.com/redwoodjs/sdk/releases/tag/v0.1.24

justinvdm added a commit that referenced this pull request Aug 18, 2025
We introduced the awesome `response.headers` in #603, but we have not yet updated starters and docs to use it.
justinvdm added a commit that referenced this pull request Aug 18, 2025
We introduced the awesome `response.headers` in #603, but we have not yet updated starters and docs to use it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server redirects break client navigation
2 participants