Skip to content

[LiveComponent] Release the loading state before any redirect. #2689

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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ class Component {
if (!controls.shouldRender) {
return;
}
this.hooks.triggerHook('loading.state:finished', this.element);
if (backendResponse.response.headers.get('Location')) {
if (this.isTurboEnabled()) {
Turbo.visit(backendResponse.response.headers.get('Location'));
Comment on lines +2155 to 2158
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to trigger the "finished" event before Turbo does its work.

Here you could do something just before the

window.location.href = backendResponse.response.headers.get('Location') || '';

Expand All @@ -2161,7 +2162,6 @@ class Component {
}
return;
}
this.hooks.triggerHook('loading.state:finished', this.element);
const modifiedModelValues = {};
Object.keys(this.valueStore.getDirtyProps()).forEach((modelName) => {
modifiedModelValues[modelName] = this.valueStore.get(modelName);
Expand Down
10 changes: 5 additions & 5 deletions src/LiveComponent/assets/src/Component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ export default class Component {
return;
}

// remove the loading behavior now so that when we morphdom
// "diffs" the elements, any loading differences will not cause
// elements to appear different unnecessarily
this.hooks.triggerHook('loading.state:finished', this.element);

if (backendResponse.response.headers.get('Location')) {
// action returned a redirect
if (this.isTurboEnabled()) {
Expand All @@ -362,11 +367,6 @@ export default class Component {
return;
}

// remove the loading behavior now so that when we morphdom
// "diffs" the elements, any loading differences will not cause
// elements to appear different unnecessarily
this.hooks.triggerHook('loading.state:finished', this.element);

/**
* For any models modified since the last request started, grab
* their value now: we will re-set them after the new data from
Expand Down
Loading