-
Notifications
You must be signed in to change notification settings - Fork 30
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
Components don't re-mount after Turbolinks navigation #27
Comments
Thanks for the report @phil-monroe! @sevos do you remember why this check was needed? |
Hi, I'm new to React and I'm trying to render a component in my layout file. I'm not sure if this issue is related to what I'm facing. The components do render when I visit different links but I'm getting the following error every time I visit another link:
In my layout file, I am rendering a simple component:
Here's in the root pack that I'm calling:
Obviously, the error disappears when I remove turbolinks. I think that it's great having it there, I feel that the page loads sluggishly without it ;) Appreciate the help! |
What versions of the gem and npm package are you using? @igikorn |
@renchap I have no idea why we have this line there. Imho it shouldn't be there, but I may be wrong. |
@sevos Thanks for the reply! Yarn"webpack": "^2.3.3", Gemfilewebpacker (1.1) |
Could you please provide a minimum repository reproducing the problem? I will take a second look in the evening |
Hi @sevos, I've reproduced the issue in a minimum repository: https://github.com/igikorn/webpacker-react-turbolinks Thank you very much! |
Hi @sevos any luck with this? Appreciate the help! |
@igikorn can you tell me if https://github.com/shakacode/react_on_rails has the same Turbolinks issue? |
Hi,
This app is really helpful. I am facing an issue with turbolinks adding to component.
Thanks |
@zeeshan-za-ahmad @renchap I've released it as the @justin808 It's rude to go into other people's repos and pitch your gem, please try to HELP people if you're visiting other projects. |
Hey, I've bumped into this issue as well.
So this way the navigation still occurss with turbolinks, but it won't display a cached versions of the page (which renders the components Html but isn't handled by React AFAIK) bur rather hit the server and re mount the components just like on first visit. |
Any news on this issue? I've tried the "no-cache" approach but it won't work for me. Emptied the cache, still nothing. The component just won't mount after a Turbolinks navigation. 😕 EDIT: seems to be working when I use |
You could try disabling Turbolinks Page cache globally, and see if the cache is actually the reason why your react component is not getting mounted.
|
Someone just needs to port over the detection fixes from React_UJS to this NPM package. |
According to this line a react component will only mount if the
innerHTML
is empty.This works well for initial page loads that are not rendered via the Turbolinks cache, but components will not re-mount after navigating around an app that utilize Turbolinks caching. This can be replicated with the following steps:
react_component
onpage one
which mount's just fine.page two
.page one
's html is cached, the component is unmounted andpage two
is rendered.page one
is rendered from the Turbolinks cache and the component will not be re-mounted as the components innerHTML is not emptyThis is not noticeable for simple components that render static text, but becomes immediately apparent if a component that changes state over time (showing the current time, polling for new data, etc.).
Is there a reason for ensuring
innerHTML
is empty before mounting a component? Or perhaps the components should be un-mounted onturbolinks:before-cache
to avoid being cached all together?The text was updated successfully, but these errors were encountered: