-
Notifications
You must be signed in to change notification settings - Fork 515
Description
Inertia adapter(s) affected
- React
- Vue 3
- Svelte
- Not Applicable
JS package version
2.0.17
Backend stack (optional)
Laravel 12.x
PHP 8.x (not applicable)
Describe the problem
If you have a form which does some processing after it's submitted but before the page is redirected and in that processing there is an uncaught error (issue is with inertia router not only the form)
For example:
form.submit('some-route', {
onSuccess: () => {
throw new Error('simulated error');
}
})
The page will still render the new component as expected. The problem is on the new page all Inertia requests get stuck in the processing stage. So now we cant render new components and the application gets stuck until a full page refresh
form.submit('some-other-route', {
onSuccess: () => {
// This never runs
},
onBefore: () => {}, // runs
onStart: () => {}, // runs
onFinish: () => {}, // runs
onError: () => {}, // doesnt run, and we dont expect it to run
})
Now when this form gets submitted, the request gets successfully sent to the server, inertia response received, but when inertia tries to process the response it returns the error from the previous request. this response get added to the queue for processing but never gets processed (every new Inertia request will just get added to the queue and the queue is stuck in a endless loop of returning the previous failed request)
inertia/packages/core/src/response.ts
Line 32 in 6241efe
return queue.add(() => this.process()) |
If we take a look inside the queue
inertia/packages/core/src/queue.ts
Line 11 in 6241efe
this.processingPromise ??= this.processNext().then(() => { |
we see we only
processNext
when processingPromise
is null but when an item on the queue fails processingPromise
holds the error and will then always return the error
(this was discovered in an old project which was updated to v2, the error which was happening didnt affect anything so it was never discovered until v2 caused inertia to stop routing)
Steps to reproduce
form.submit('some-route', {
onSuccess: () => {
throw new Error('simulated error');
}
})
new inertia requests dont process