[Inertia 2.0] Allow pushing external axios abort controller signals to the router OR implement an AJAX client. #1920
Closed
danmatthews
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Closing this because Inertia 2.0 has, or at least will hopefully fix all of these problems in a more elegant way than I could have proposed. Big thanks @reinink and Joe! ❤️ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes using Inertia's router for loading, even lazy loading, is still not the answer. I'm not sure what you folks have cooking for 2.0 but I would love the ability to pass a cancel token/abort signal to the router, so if a page visit is initialised, it would cancel that request, too. We currently do this with a store in Svelte, but would be amazing if it was built in.
Scenario:
I have an overview dashboard with 5 graphs, each graph loads data using
axios.get
as using lazy loading would have to wait for all 5 to finish loading before returning the result from the server.If i click a
<Link>
to navigate to another page, it does not cancel my non-inertia-routeraxios
requests.How we do it at the moment
At the moment, we use a svelte store and push the abortcontroller to it:
This allows any component to push to the store, then the navigate event to cancel it, it has a few drawbacks, but it works for the most part.
What I would love to see
Option 1 - Router accepts
AbortController()
instances or cancel tokens from axiosImagine my code above, but being able to do something like:
Where
cancelOnNavigate
adds information to the axios instance, but then proxies thePromise
back through.Option 2 -
router.axios
becomes a thin proxyYou could make
router.axios
a thin proxy that automatically adds cancel tokens to the router for visits.Option 3: Give v2.0 it's own http client as a proxy over axios, with extra fun goodies!
So - full disclosure, this is something we use in our app that we use to automatically get the errors from Laravel so we don't have to manually do it each time. I like this approach, and i think something like this would make a valuable addition to Inertia.
Beta Was this translation helpful? Give feedback.
All reactions