-
Notifications
You must be signed in to change notification settings - Fork 752
bug: Prevent roots from being re-created when using React 18 #1305
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
Conversation
react_ujs/index.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have a test that fails without this change? And passes with this change?
Can you extract some code from
I made a reproduction repo to showcase the bug happening and as a test case for the fix. Feel free to try it out for yourselves.
into https://github.com/reactjs/react-rails/blob/master/test/dummy
and add a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I'll do that in the next few days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @justin808, the dummy project's appraisals are missing some of the dependencies I've used in the reproduction case, such as Turbo and sqlite for creating the Timer records. Can I add those or would you prefer another approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diogobeda feel free to add them.
@diogobeda let me know when you added tests.
We need CI to pass.
@diogobeda, I'd like to merge. Let me know when you added tests.
We need CI to pass.
Hey @justin808, sorry! I haven't been having much time to work on this, but I'll try to prioritize this for next week.
@diogobeda thanks! Let's get this PR merged!
89cdc9f
to
e9d1b5e
Compare
@justin808 added a test case and confirmed it failed on master
with React 18, so we should be good to go if there's nothing else to fix on CI
@ahangarha @Judahmeek @diogobeda are the CI errors legit?
I was trying these out locally and I can see the failures but I'm not sure what's wrong because I can't debug them for some reason. It's hard trying to log things in those tests and I'm not sure what to do next for them, so I could use some help.
Seem integration tests fail with Sprockets 3 and 4, but work with shakapacker.
@diogobeda does that help?
See
https://github.com/reactjs/react-rails/blob/master/.github/workflows/ruby.yml#L61
https://github.com/reactjs/react-rails/blob/master/gemfiles/sprockets_3.gemfile
I get the following error with running the test suite for both sprockets_3
and sprockets_4
:
bundle exec appraisal sprockets_3 rake test
>> BUNDLE_GEMFILE=/Users/diogobeda/workspace/podia/react-rails/gemfiles/sprockets_3.gemfile bundle exec rake test
warning package.json: No license field
warning No license field
Coverage report generated for Unit Tests to /Users/diogobeda/workspace/podia/react-rails/coverage. 659 / 1641 LOC (40.16%) covered.
Run options: --seed 45280
# Running:
dyld[54325]: missing symbol called
rake aborted!
Command failed with status (): [/Users/diogobeda/.asdf/installs/ruby/2.7.8...]
/Users/diogobeda/.asdf/installs/ruby/2.7.8/bin/bundle:23:in `load'
/Users/diogobeda/.asdf/installs/ruby/2.7.8/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
My ruby version is:
ruby -v
ruby 2.7.8p225 (2023年03月30日 revision 1f4d455848) [arm64-darwin22]
My node version is:
node -v
v18.18.2
I've researched for what the error could be and the few results I can find are M1/M2 related, so I've tried running with arch -x86_64
to no avail:
arch -x86_64 bundle exec appraisal sprockets_4 rake test
>> BUNDLE_GEMFILE=/Users/diogobeda/workspace/podia/react-rails/gemfiles/sprockets_4.gemfile bundle exec rake test
warning package.json: No license field
warning No license field
Coverage report generated for Unit Tests to /Users/diogobeda/workspace/podia/react-rails/coverage. 659 / 1625 LOC (40.55%) covered.
Run options: --seed 9016
# Running:
dyld[55666]: missing symbol called
rake aborted!
Command failed with status (): [/Users/diogobeda/.asdf/installs/ruby/2.7.8...]
/Users/diogobeda/.asdf/installs/ruby/2.7.8/bin/bundle:23:in `load'
/Users/diogobeda/.asdf/installs/ruby/2.7.8/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
@justin808 would you be willing to pair on this some time this week?
@diogobeda please join our slack for react-rails and ping @Judahmeek to pair on this.
I truly appreciate your help!
@ahangarha @G-Rath should this be merged once CI passes? Might be the same issue at #1306 for CI.
@diogobeda can you rebase on master?
e9d1b5e
to
b05c8a7
Compare
I'd love to get this merged, but we have spec failures and rubocop issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually able to run the full test suite locally due to my setup (it requires a higher version of selenium-webdrivers
than what's supported by Ruby 2.7), but besides the logs
error (which I've suggested a fix for) I'm not see anything indicating this isn't just a general issue in your tests since they're now passing on the default branch.
It would be good if someone who can run the full test suite locally could confirm if this errors are reproducable.
I'm also curious to why you're only installing turbo-rails
for the shakapacker
gemfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what's causing the log error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And using headless=new
option for the driver can fix this issue. Why not apply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did recommend applying it back when we were doing the CI fixing PRs, but we ended up going the other direction.
Overall that change is out of scope for this PR, but I also think it might also not be possible on the current gem versions which is why I've not done a PR myself - I'm happy to review a PR if you want to give it a try, but it'll eventually get done after dropping support for Ruby 2.7 etc if it's not done before then.
@diogobeda can you please check test failures?
Hey @justin808 @G-Rath, I'm gonna close this PR because it's been too hard to deal with the project's test suite and I can't keep on top of it. Feel free to take my commits/changes and run with it, but I can no longer contribute.
Reopen so I don't forget!
b05c8a7
to
6b65463
Compare
Prevent root from being recreated on react 18 (recreation of #1305)
Uh oh!
There was an error while loading. Please reload this page.
Summary
When dynamically adding components to a page by using, for example, Turbo streams and either manually calling
ReactRailsUJS.mountComponents
or passingReactRailsUJS.handleMount
to a Turbo event, there's a bug where the react roots are re-created on a node instead of being re-used. That resets the local state of components that were already mounted and may also cause visual glitches with the component flashing.Other Information
I made a reproduction repo to showcase the bug happening and as a test case for the fix. Feel free to try it out for yourselves.
Here's a gif from before the fix:
CleanShot 2023年08月31日 at 10 37 40
And one from after the fix:
CleanShot 2023年08月31日 at 10 40 58
Please let me know if there's anything else I should add to this PR 🙏
Pull Request checklist
Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by
~
.