Preventing Reload of Permanent Element?
See original GitHub issueTurbo is really great. Thanks for building it.
So, I coded up a video tray to persist across navigation. A user can click a button, which will load an iframe into a fixed positioned element that persists across navigation. This sort of works, but not quite. On navigation, the permanent element flashes in and out, and the iframe has to reload.
Here are some iterations I tried;
<html>
<head>
</head>
<body>
{{ rest of page }}
<div id="video-tray" turbo-data-permanent>
{{ iframe dynamically added here }}
</div>
</body>
</html>
That has the problem with the iframe load on navigation. So I tried this:
<html>
<head>
</head>
<body>
<turbo-frame id="main_outlet" data-turbo-action="advance" >
{{ rest of page }}
</turbo-frame>
<div id="video-tray" turbo-data-permanent>
{{ iframe dynamically added here }}
</div>
</body>
</html>
This solves the problem with the video tray! It does not reload any more on navigation.
HOWEVER, a whole lot of other far worse problems arise. The head section is not merged on navigation. This doesn’t end up as a true solution.
So we can try this:
<html>
<head>
</head>
<body>
<turbo-frame id="main_outlet" data-turbo-action="advance" target="_top">
{{ rest of page }}
</turbo-frame>
<div id="video-tray" turbo-data-permanent>
{{ iframe dynamically added here }}
</div>
</body>
</html>
This ends up being identical to the first attempt. There is a reload flash on navigation.
So, how can this problem be solved without creating new problems?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
You can solve this problem by wrapping your app into another root element instead of the
body
element. I’m currently using this monkey patch to change thebody
reference internally. Here’s the code:And markup example:
@dhh @sstephenson @ctrochalakis would you be interested in a PR that makes this part of Turbo as an option?