这是indexloc提供的服务,不要输入任何密码
Skip to content

Turbo doesn't gracefully shutdown stimulus controllers when visiting easyadmin #1433

@Deksor

Description

@Deksor

Hello, I stumbled across a very annoying bug with turbo on symfony + easyadmin.
I have enabled turbo drive which works great on my website ... except when I go to visit easyadmin.

Easyadmin has its own JS environment and it has disabled turbo on the entire thing.

Then I noticed that when going from my website to the easyadmin section, I don't see any logs saying that the stimulus controllers were properly disconnected.
Even worse, if I press "back" on the browser's history, it seems that the old controllers are still there, and no matter what I try, some part of them still remains in memory and completely mess up my website.

For instance I have a page with a controller that listens to window.addEventListener("hashchange"). Then if I click on links that change the hash, it works obviously. But then if I go to easyadmin, and then come back to that page, the controller doesn't react properly to the page's hashchanges anymore, however pressing "back" will trigger it ... And if I go back even further to a different page that also changes the hash but meant to be used by another controller, it will trigger again even though it never belonged to that page in the first place, and obviously will cause errors.

None of this happens until I visit easyadmin and go back from history.
I tried to perform this

window.addEventListener('pageshow', function (event) {
            if (event.persisted || performance.getEntriesByType("navigation")[0].entryType === 'back_forward') {
                console.log('Page was loaded from cache or back/forward navigation detected');
                window.location.reload();
            }
        });

But the problem remains

I also tried

document.addEventListener('turbo:before-visit', (event) => {
    const url = event.detail.url;
    if (url.includes('/dashboard/')) {
        // Mark that we're going to admin
        console.log('Navigating to dashboard, stopping Stimulus app');
        app.controllers.forEach((controller) => {
            controller.disconnect();
        });
    }
});

But again to no avail.

I also added "data-turbo="false"" on the links leading to easyadmin but again that doesn't fix the issue ...

What should I do from now ? I feel like I've tried everything ...

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