Skip to content

Queue hangs when response callbacks has an error, all subsequent inertia requests fail to process #2466

@pintend

Description

@pintend

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)

return queue.add(() => this.process())

If we take a look inside the queue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions