Skip to content
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

data-turbo-permanent elements (the whole page in general) get reloaded after many link clicks #158

Open
scratchoo opened this issue Apr 6, 2021 · 0 comments

Comments

@scratchoo
Copy link

scratchoo commented Apr 6, 2021

I have put a countdown timer on the sidebar between a div

<div id="timer" data-turbo-permanent>
  <!-- timer here -->
</div>

When I start clicking links... the countdown timer keeps the same numbers again and again which is fantastic,

but if I keep clicking different links in the navbar then other links in the sidebar (I just keep clicking and clicking for a while) at certain moment the page gets reloaded and the timer stops and gets back to it's original state,

if I click the same link many times, it gives the same behavior so it's not a matter of clicking different links or same link!

I thought maybe it's because I'm clicking links continuously very quick so I tried to click at a lower rate, but it happens regardless whether I click fast or a little slower, after many clicks the page gets reloaded!

is this something expected to happen in this case? or it's a bug maybe?

Update: not sure but in the dev console whenever this happens I see something like:

Uncaught (in promise) DOMException: The user aborted a request. VM3761 turbo.es2017-esm.js:347
when I click on it, it comes from turbo js file and all it gives me is : TypeError: Cannot read property 'requestContent' of undefined

UPDATE 2 If my finding is correct, there is a function called async perform() at line 323, here is the full function:

async perform() {
        const { fetchOptions } = this;
        dispatch("turbo:before-fetch-request", { detail: { fetchOptions } });
        try {
            this.delegate.requestStarted(this);
            const response = await fetch(this.url.href, fetchOptions);
            return await this.receive(response);
        }
        catch (error) {
            this.delegate.requestErrored(this, error);
            throw error;
        }
        finally {
            this.delegate.requestFinished(this);
        }
    }

The error is coming from the CATCH block, I commented both lines and replaced them like follows:

//this.delegate.requestErrored(this, error);
//throw error;
console.log('daaaaamn!!');
console.log(error);

Now, the issue of page reloading disappeared completely, and my countdown timer never stops :) and the output of console.log(error) is showing me DOMException: The operation was aborted.

So yeah I think the issue is coming from there! would commenting these lines out (for now) cause any issue? and is that something that would be corrected?

Another issue related to the events of data-turbo-permanent element:

By commenting the above lines in the catch block solved the issue of reloading the page (specifically the elements with data-turbo-permanent), I started noticing that my timer numbers get frozen once the catch block gets hit, so I think that part should be corrected, please if anyone have a quick fix I will be very thankful.

I confirm that going back to turbolinks and using data-turbolinks-permanent works perfectly, all the described issue above happens only with turbo

@scratchoo scratchoo changed the title data-turbo-permanent elements get reloaded after many link clicks data-turbo-permanent elements (the whole page in general) get reloaded after many link clicks Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant