Skip to content
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

Throw error when attempting to redefine ReactOnRails #1562

Merged

Conversation

rubenochiavone
Copy link
Contributor

@rubenochiavone rubenochiavone commented Jul 20, 2023

Summary

Webpack configuration could cause react-on-rails to be imported multiple times in each runtime chunk, leading to the global ReactOnRails variable being overridden and client rendering crashes. This should be avoided by relying on a single runtime chunk.

Read more at #1558.

Pull Request checklist

  • Update documentation
  • Update CHANGELOG file

Screenshots

image


This change is Reviewable

@rubenochiavone rubenochiavone force-pushed the rubenochiavone/throw-error-when-redefining-react-on-rails branch 2 times, most recently from f8d635f to 58b1d5a Compare July 20, 2023 19:00
@rubenochiavone rubenochiavone self-assigned this Jul 20, 2023
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shakapacker and not webpacker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the new troubleshooting docs to docs/javascript/troubleshooting-when-using-shakapacker.md, but kept the old one since it is related to webpacker. See c6d7da9.

throw new Error(`
The ReactOnRails value exists in the ${ctx} scope, it may not be safe to overwrite it.

This could be caused by setting Webpack's optimization.runtimeChunk to "true" or "multiple" - please check your Webpack configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be caused by setting Webpack's optimization.runtimeChunk to "true" or "multiple," rather than "single." Check your Webpack configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cbde473.

@rubenochiavone rubenochiavone force-pushed the rubenochiavone/throw-error-when-redefining-react-on-rails branch from 58b1d5a to 972fabb Compare July 21, 2023 16:34
@rubenochiavone rubenochiavone changed the title Throw error when attempting to redefine ReactOnRails global Throw error when attempting to redefine ReactOnRails Jul 21, 2023
Webpack configuration could cause react-on-rails to be imported multiple times
in each runtime chunk, leading to the global ReactOnRails variable being
overridden and client rendering crashes. This should be avoided by relying on a
single runtime chunk.

Read more at #1558.
@rubenochiavone rubenochiavone force-pushed the rubenochiavone/throw-error-when-redefining-react-on-rails branch from cbde473 to 38910f2 Compare July 21, 2023 18:47
@justin808 justin808 merged commit 69109e4 into master Jul 21, 2023
@justin808 justin808 deleted the rubenochiavone/throw-error-when-redefining-react-on-rails branch July 21, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants