-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Using turbolinks:before-visit causes too early unmount and components "flickering" #706
Comments
@justin808, @volkanunsal Can anyone provide me with exact scenario how to get this warning only in case of I propose to change event back to |
Dan is not familiar with how Turbolinks works. The JavaScript code is
entirely replaced between each visit. That's why we were getting that error
about a another copy of React. I think your configuration must be different
somehow if you can't reproduce it. There is no point in adding a
configuration option for this in my view, but it's up to @shakacode.
|
You are wrong in your confidence that turbolinks replaces javascript code on every page load. I can access registered ReactOnRails store even when I navigate via turbolinks ten pages away just by calling |
It doesn't replace everything. That's true. But whether React is one of the
things that get replaced is up to the user's web pack configuration. If
you're not using common chunks plugin, React will get replaced.
|
@volkanunsal @szyablitsky I'd really appreciate it if you two can work together to come up with the best recommendation for our community. Some thoughts:
CC: @robwise, @alexfedoseev |
@justin808 I did not want to use ReactRouter before it reaches major version 4, so I wrote my own lightweight router (~100 LOC), which is buggy in some places (back navigation), but I already have a plan how to fix it. Also I'm going to look at https://junctions.js.org/ Supporting both versions of turbolinks adds 5 LOC, so it is not a concern. It can be, but only in case of forking Turbolinks and changing event names. As of "shared redux stores" if you mean using one store by many independent components via @volkanunsal you mentioned some HelloWorld application in #610. Is it your own project or Dummy from this project or https://github.com/shakacode/react-webpack-rails-tutorial? Can you share it? I'd like to reproduce this error and try to fix it. Dan Abramov closed my PR, so we have to find another solution. |
ReactRouter v4 is great! We're using it already at egghead.io
With React router, it's understood that one needs to fetch the data as the page changes... We'd probably want the same behavior for shared stores since we're not re-rendering the page.
I'm not sure. Maybe the default generator plus turbolinks turned on? Maybe the /spec/dummy app. Maybe the https://github.com/shakacode/react-webpack-rails-tutorial. |
If you want to reuse shared store between page visits, you have to consider that data on the server could be changed already. There must be a mechanism that keeps the data fresh in "realtime". |
HelloWorld app is the one in the repo, not mine.
I would discourage forking Turbolinks. Tried it once. It's a nontrivial
project. It's got a ton of edge cases. If it were to use a fork of
turbolinks, react on rails would make me reconsider using its
JavaScript package in my apps.
|
@volkanunsal, are you using TurboLinks? Maybe I can create a PR that could do something like allow it to "know" that some URLs are handled by react-router? @szyablitsky In terms of page navigation, if the route is handled by rails, then we should consider invoking the store initialization with "new" data for a different page that Rails is rendering...I think any logic can be in the generator function for the custom redux store. Let's figure out the best course of action here! If any of you want slack invites to the ShakaCode slack, email me. |
I checked I changed binding event back to It clearly demonstrates IMO, that Turbolinks event and I even added a code that saved If no one is mind, I will submit the PR changing unmount event back to |
Thanks for the PR @szyablitsky. I really need you and @volkanunsal to give me a clear articulation of the tradeoffs, and whether or not this should be configurable. As I'm not using TurboLinks right now, I have no idea which is better. We should also update this file: https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/turbolinks.md |
@justin808 I fixed @volkanunsal do you use Turbolinks with ReactOnRails in any of your current projects? Can you try the same procedure as I described to check if I'm right or wrong? |
I do use Turbolinks. It's puzzling to me that you don't see the error I
saw. I've seen it reproduced elsewhere before. I don't have time to test it
again, but since the error originated from React it's possible that there
has been a change in its treatment of the issue. If it's that important to
you, then go ahead and change the event hook, but doing so without a way to
configure the event hook would open up new problems in the future if React
reintroduces the error message. So make sure to make that configurable for
future use.
|
For what it's worth, I've never seen this warning from React after the
event hook was changed to before-visit but I used to see it consistently
with before-render. That proved to me that the error was caused by the
event hook or at least was solved by the change. I strongly believe the event hook
and the error are related but I don't have time to further test the issue right now.
|
@volkanunsal: I invited you to the ShakaCode Slack. @szyablitsky: Let's find a time to screen share and go over this, maybe with Volkan. I'm quite sure that the 3 of us can nail this issue. |
@szyablitsky @justin808 I just tested the |
See #709 Do we have consensus? |
I think I will add an option |
Added an option. Updated PR. |
) * change turbolinks unmount event from before-visit to before-render * Addresses #706
) * change turbolinks unmount event from before-visit to before-render * Addresses #706
renchap/webpacker-react#14 (comment) |
@szyablitsky Thanks for looking into this! |
Changing unmount event to
turbolinks:before-render
causes warning. See #610If
ReactDOM.unmountComponentAtNode
can leave rendered markup after component unmounting, then we can useturbolinks:before-visit
and get rid of "flickering" components causing bad UX.I filled a pull request to React adding
shouldLeaveMarkup
flag forunmountComponentAtNode
facebook/react#8928
Tested these changes on my local copies of libraries and they resolve this issue.
The text was updated successfully, but these errors were encountered: