hotwired / turbo

The speed of a single-page web application without having to write any JavaScript
https://turbo.hotwired.dev
MIT License
6.63k stars 421 forks source link

Turbolinks to Turbo before-cache behavior differs #102

Open smridge opened 3 years ago

smridge commented 3 years ago

Attempting to transition from Turbolinks to Turbo and coming across some differing behavior. I'm not overly familiar with this repo and full intent but curious on the before-cache behavior when switching from Turbolinks to Turbo.

In some cases, before-cache is needed for certain elements to behave as expected when clicking the back button or form submission error redirects.

Update: When going through various events turbo:submit-start did not work either.

document.addEventListener("turbo:submit-start", function() {
  $(".flatpickr-input").flatpickr('destroy');
});

Is there a new approach to solving this? Thoughts from anyone?

sstephenson commented 3 years ago

Would you mind testing with v7.0.0-beta.4 to see if the issue has been fixed?

smridge commented 3 years ago

GET requests are good (as this triggers turbo:before-cache) šŸ‘ . For POST requests, the issue persists. Is there perhaps something different that should be done for POST requests as this does not trigger turbo:before-cache? I tried playing around with turbo:submit-start, turbo:before-fetch-request etc and no success unfortunately.

Context

Form Field before submit:

<input data-behavior="datepicker" type="hidden" name="foo[referral_date]" id="foo_referral_date" class="flatpickr-input">
<input class=" form-control input" placeholder="" tabindex="0" type="text" readonly="readonly">

With Turbolinks āœ… :

<div class="field_with_errors">
  <input data-behavior="datepicker" type="hidden" value="" name="foo[referral_date]" id="foo_referral_date" class="flatpickr-input">
  <input class=" form-control input" placeholder="" tabindex="0" type="text" readonly="readonly">
</div>

With Turbo šŸ˜ž :

<div class="field_with_errors">
  <input data-behavior="datepicker" data-controller="flatpicker" type="text" value="" name="foo[referral_date]" id="foo_referral_date">
</div>
dylanfisher commented 2 years ago

I'm having this same issue with Turbo 7.1.0.

In my situation adding <meta name="turbo-cache-control" content="no-cache"> is a good enough workaround and avoids the need to deconstruct any third-party widgets.

This does seem to be counter to what the docs say in the handbook.