Components aren't mounted on turbolinks cache
See original GitHub issueHelp us help you! Have you looked for similar issues? Do you have reproduction steps? Contributing Guide
Steps to reproduce
Place a component on your page. Navigation to that page, then to another, then back to the page with the component.
In the period between turbolinks showing you the cached page, and fetching the new one, no components are mounted.
Expected behavior
The cached page should at least show the component. If remounting it temporarily has too many side effect. I know stimulus just mounts and unmounts it as the cache is replaced.
Actual behavior
The components don’t show up at all. There’s just empty space.
System configuration
Sprockets or Webpacker version: 3.5 React-Rails version: 2.4 Rect_UJS version: 2.4.4 Rails version: 5.2.2 Ruby version: 2.4.5
I’m not actually sure if I should be posting this here or over at turbolinks, but seeing as not even data-turbolinks-permanent
, I feel like it must be something react-rails is doing.
If you render a component, navigate away, and navigate back, the component is gone until turbolinks finishes loading. Even if the component has a data-turbolinks-permanent tag, or if its parent has it. The component just doesn’t exist.
So if I have a slow page load, I end up with many seconds of elements just… not there. It’s not very pretty.
Here’s a gif of what I mean. After navigation back to the first page, the table doesn’t mount.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top GitHub Comments
To re-render components immediately, I added:
That avoids flickering when loading a cached page, but it ends up calling
mountComponents
twice: once after rendering the cached version, and again after rendering the fresh version, which may or may not be what you want.If anyone has a better workaround, I’d be interested.
For future people who see this I had a same symptoms that I fixed by moving
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
the the last line of<head></head>