-
Notifications
You must be signed in to change notification settings - Fork 439
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
Snapshot caching issue after upgrading from turbolinks to turbo #117
Comments
i believe that #102 is also related with my experience after upgrading to Turbo drive. |
Would you mind testing with v7.0.0-beta.4 to see if the issue has been fixed? |
branch with sample project testing turbo-v7.0.0beta4 Edit - discard this comment. |
I am really sorry, i think i shouldn't have used // Visit The Stimulus Handbook for more details
// https://stimulusjs.org/handbook/introduction
//
// This example controller works with specially annotated HTML like:
//
// <div data-controller="hello">
// <h1 data-target="hello.output"></h1>
// </div>
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["output"];
connect() {
console.log("Connecting");
const p = document.createElement("p");
p.innerHTML = "hellos stimulus";
this.outputTarget.appendChild(p);
if (this.isPreview) {
console.log("Connecting from a preview");
}
}
disconnect() {
console.log("disconnecting");
const child = this.outputTarget.firstElementChild;
console.log(child);
this.outputTarget.removeChild(child);
console.log(this.outputTarget);
}
get isPreview() {
return document.documentElement.hasAttribute("data-turbo-preview");
}
} Moreover and most importantly i checked it with some controllers that would reset some libraries (uppy, tiny-slider, flatpickr), or my custom controllers and the problem seems to have disappeared.. I will do some more checks though in order to be sure.. Again i am really sorry for my previous message. Thanks a lot for your efforts and your work. |
I might be having a similar problem in which a stimulus controller is being connected twice on a return to a page even though I am telling my connect logic to only run if it is not a preview. This is actually an even bigger deal because I am trying to establish an action cable connection and perhaps because of this race condition issue (not sure) I often don't get a confirmation and lose cable connection to the server. What is even more strange is that if I add a no-preview meta tag to the page then the issue does not happen so I am pretty sure that a preview of some sort is happening. I don't know the turbo code at all but the little I look at it I am wondering if perhaps isPreview is just always coming out false: https://github.com/hotwired/turbo-rails/blob/main/app/assets/javascripts/turbo.js#L2544. Any updates would be great and if there is anyway I can help with debugging or solving this problem I am happy to contribute. |
Closes hotwired#117 Closes hotwired#159 --- When restoring from a cached snapshot, pass along the `isPreview` flag to `View.renderPage`. Also, always issue the request within `Visit.issueRequest`, since process of restoring the cached preview is initiated prior to the request intended to re-fetch the cached content.
@thanosbellos thank you for opening this. Is the behavior restored by #162? |
Closes hotwired#117 Closes hotwired#159 --- When restoring from a cached snapshot, pass along the `isPreview` flag to `View.renderPage`.
@seanpdoyle I would also really like to try out your branch to see if it will fix my problem but I am not quite sure of how to use it locally since I am requiring turbo-rails but your branch is just turbo and I am not quite sure how to replace my installation to use it. Please advise, thanks! |
@seanpdoyle Hi and thanks for your response. I finally got some time to test this pull request out. data-turbo-preview behaviour is restored. Moreover some issues with back/forward to a page with a controller i had (stimulus-components/stimulus-lightbox) were also fixed. Just for reference: Here the fixed behaviour after using #162 Thanks a lot for your efforts and your work. @jonsgreen |
This definitely gets a 👍 from me. I am now able to block subscribing by the usual check for preview which prevents the race condition I was observing. I am curious how soon this might get merged in to master @seanpdoyle? Seems like this is an important bugfix? Thanks so much for attending to this. Thanks @thanosbellos for reporting this issue and the tips for how to test locally. |
Closes hotwired#117 Closes hotwired#159 --- When restoring from a cached snapshot, pass along the `isPreview` flag to `View.renderPage`.
Hm.. Interesting.. As i mentioned above, when i tried the #162 there was an unexpected gain in one of my controllers besides the restoration of turbo preview.
I just tried the same controller with the main branch (after #169 was merged). The date-preview issue is gone. In my surprise though, the issue with that controller, that was gone using the #162, is now still there. I will dive into it in the weekend. |
I am curious if there are any updates on this fix? Has this actually been merged and if so when would we expect it to be in a new release? |
@jonsgreen #169 has been merged into |
Just for clarity, i close this issue due to the fact that since the problems i initially described have been solved with the release v7.0.0.beta4. The following related issue has been resolved on the main branch.
Thanks a lot for your work and help!! |
Closes hotwired#117 Closes hotwired#159 --- While the original implementation change for this commit was covered elsewhere, there is still value in the tests to add coverage for the behavior.
Hello.
Since the Turbolinks - Deferred snapshot caching pull request was merged, i have been using disconnect method to teardown my controller(i.e deinitialize my uppy file uploader and remove the custom file input from the dom).
I have upgraded to use Turbo (Drive) recently and i have noticed that i got a different behaviour using the exact same code
In order to be sure that it hadn't something to do with my config or with the js library i was using(uppy), i created two demo projects, one that uses turbo drive and one that uses turbolinks and a simple stimulus controller that adds/removes elements when connecting/disconnecting:
The stimulus controller is adding an element when connecting and removing the element when disconnecting:
The behaviour with turbo drive:
![demo-turbodrive](https://user-images.githubusercontent.com/425283/104839941-1e9bd080-58cd-11eb-8d5c-c2e0bc04a602.gif)
The behaviour with turbolinks
![demo-turbolinks](https://user-images.githubusercontent.com/425283/104839947-20fe2a80-58cd-11eb-9032-b3f75937f7f0.gif)
Tested on Mac Os Big Sur on latest Safari and Mozilla firefox developer edition (latest version)
Rails 6.1.0 with latest version of turbo-rails and turbolinks.
The text was updated successfully, but these errors were encountered: