-
Notifications
You must be signed in to change notification settings - Fork 433
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
Add turbo:fetch-request-error event on frame and form network errors #640
Conversation
closes hotwired#462 This PR adds a new event called `turbo:fetch-error` that dispatches when a form or frame fetch request errors. This event will let developers respond appropriately when a fetch request fails due network errors (such as on flaky wifi). At the moment, if a frame navigation fetch request fails due to a network error an error is thrown so https://github.com/hotwired/turbo/blob/2d5cdda4c030658da21965cb20d2885ca7c3e127/src/http/fetch_request.ts#L107 never runs and therefore the `turbo:before-fetch-response` event is not dispatched.
Co-authored-by: Keith Cirkel <[email protected]>
Co-authored-by: Keith Cirkel <[email protected]>
Thank you for proposing this! Is it possible to add test coverage? Does playwright have the ability to force the Chrome or Firefox browser running behind the scenes into Offline mode? |
…rt32/turbo into st-add-turbo-fetch-error-event
I've got something ugly in ecdd1c9 and curious if you know of a good way to determine which browser we need to pull in. |
@seanpdoyle thanks for your help here! This change should be green and ready to go. I bumped into some recursion issues with the test helper so I opted to not serialize the |
Thanks for the thumb! What do we need to do to get this PR merged? |
I've opened #685 to include |
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to hotwired#640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
Follow-up to #640 Related to hotwired/turbo-site#110 When a `Visit` results in a `fetch` error (like when the browser is offline), dispatch a `turbo:fetch-request-error` event in the same style as `<turbo-frame>`- and `<form>`-initiated `fetch` errors. For the sake of consistency, also make the `TurboFetchRequestErrorEvent` cancelable. Along with the implementation change, this commit also adds test coverage to ensure that the `Event.target` is correct for `<turbo-frame>` and `<form>` error events.
closes #462 and possible #460
This PR adds a new event called
turbo:fetch-error
that dispatcheswhen a form or frame fetch request errors.
This event will let developers respond appropriately when a fetch request
fails due network errors (such as on flaky wifi). A developer could reload the page or show an error message of some kind.
At the moment, if a frame navigation fetch request fails due to a network
error an error is thrown so
turbo/src/http/fetch_request.ts
Line 107 in 2d5cdda
and therefore the
turbo:before-fetch-response
event is not dispatched.Here is a demo using http://127.0.0.1:9000/src/tests/fixtures/tabs.html as a fixture:
error.mp4
I'm very open to feedback or other ideas on a good direction to go here.