react_on_rails icon indicating copy to clipboard operation
react_on_rails copied to clipboard

Turbolinks 5.2 deferred caching strategy support

Open risinglf opened this issue 6 years ago • 4 comments

Hi guys,

after hours of headache I've noticed that Turbolinks 5.2 does not work with React On Rails 11 due to the new Deferred caching strategy introduced in turbolinks 5.2

Turbolinks 5.2 Deferred caching PR

Do you have plan to support turbolinks 5.2? It would be nice, it's faster than the 5.1 with the new deferred caching strategy.

Thank you so much

risinglf avatar Oct 23 '18 11:10 risinglf

@risinglf and others that would like to migrate to Turbolinks 5.2:

PRs Welcome

I'm very open to taking a PR on this. Would you be interested in creating one? I can provide some guidance.


Pro Support

I can do this for your company if you join ShakaCode Pro Support plan. Please email me for more info.

Here are a couple of references for what we do:

Thanks,

Justin [email protected]

justin808 avatar Oct 23 '18 18:10 justin808

I did read up a bit on the PR mentioned. I'm not clear on what the change would be.

Here is the relevant code to hack on:

function renderInit() {
  // Install listeners when running on the client (browser).
  // We must do this check for turbolinks AFTER the document is loaded because we load the
  // Webpack bundles first.
  if (!turbolinksInstalled() || !turbolinksSupported()) {
    debugTurbolinks('NOT USING TURBOLINKS: calling reactOnRailsPageLoaded');
    reactOnRailsPageLoaded();
    return;
  }

  if (turbolinksVersion5()) {
    debugTurbolinks(
      'USING TURBOLINKS 5: document added event listeners ' +
      'turbolinks:before-render and turbolinks:render.');
    document.addEventListener('turbolinks:before-render', reactOnRailsPageUnloaded);
    document.addEventListener('turbolinks:render', reactOnRailsPageLoaded);
    reactOnRailsPageLoaded();
  } else {
    debugTurbolinks(
      'USING TURBOLINKS 2: document added event listeners page:before-unload and ' +
      'page:change.');
    document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
    document.addEventListener('page:change', reactOnRailsPageLoaded);
  }
}

The current test suite does test turbolinks: I did read up a bit on the PR mentioned. I'm not clear on what the change would be.

Here is the relevant code to hack on:

function renderInit() {
  // Install listeners when running on the client (browser).
  // We must do this check for turbolinks AFTER the document is loaded because we load the
  // Webpack bundles first.
  if (!turbolinksInstalled() || !turbolinksSupported()) {
    debugTurbolinks('NOT USING TURBOLINKS: calling reactOnRailsPageLoaded');
    reactOnRailsPageLoaded();
    return;
  }

  if (turbolinksVersion5()) {
    debugTurbolinks(
      'USING TURBOLINKS 5: document added event listeners ' +
      'turbolinks:before-render and turbolinks:render.');
    document.addEventListener('turbolinks:before-render', reactOnRailsPageUnloaded);
    document.addEventListener('turbolinks:render', reactOnRailsPageLoaded);
    reactOnRailsPageLoaded();
  } else {
    debugTurbolinks(
      'USING TURBOLINKS 2: document added event listeners page:before-unload and ' +
      'page:change.');
    document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
    document.addEventListener('page:change', reactOnRailsPageLoaded);
  }
}

The current test suite does test turbolinks:

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/Gemfile.lock#L288

If you want to try out updating to 5.2 turbolinks, let me know how it goes.

justin808 avatar Oct 26 '18 02:10 justin808

@risinglf did you ever find the solution?

justin808 avatar Jan 10 '21 19:01 justin808

Hi @justin808 no I did not. We lock the Turbolinks version to 5.1.

Thanks

risinglf avatar Jan 11 '21 15:01 risinglf