-
Notifications
You must be signed in to change notification settings - Fork 759
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
bug: Prevent roots from being re-created when using React 18 #1305
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 |
@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
My ruby version is:
My node version is:
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
@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? |
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?
def assert_counter_count(page, timer_name, count) | ||
assert page.has_content?("#{timer_name} - #{count}"), <<~MSG | ||
#{page.body} | ||
#{page.driver.browser.logs.get(:browser).inspect} |
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:
#{page.driver.browser.logs.get(:browser).inspect} | |
#{page.driver.browser.manage.logs.get(:browser).inspect} |
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! |
Prevent root from being recreated on react 18 (recreation of #1305)
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:
And one from after the fix:
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
~
.