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

Update react to 18 #1290

Merged
merged 13 commits into from
Jul 27, 2023
Merged

Update react to 18 #1290

merged 13 commits into from
Jul 27, 2023

Conversation

Judahmeek
Copy link
Collaborator

@Judahmeek Judahmeek commented Jul 20, 2023

This change upgrades React-Rails' embedded react to v18.2.0 & uses node polyfill plugin & fast-text-encoder for SSR text encoding (react-dom.server requires a reference to a TextEncoder constructor).

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file

ahangarha
ahangarha previously approved these changes Jul 21, 2023
Copy link
Collaborator

@ahangarha ahangarha left a comment

Choose a reason for hiding this comment

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

Great 👍🏾

Except for the format of the changelog, everything looks good.
I approve to prevent block for merge.

Update:
When I started the review, we had a passing CI! So I removed the review.

CHANGELOG.md Outdated
Comment on lines 12 to 19
### Breaking Changes
- Remove support & testing for Webpacker 3/4.
- Add support & testing for Shakapacker v6
## Breaking Changes
### Removed
- Support & testing for Webpacker 3/4.
- WebpackManifestContainer, which searched for assets in the webpack manifest
### Added
- Support & testing for Shakapacker v6
- SeparateServerBundleContainer, which expects a single server bundle file & does not use the webpack manifest at all.
### Usage
- Requires separate compilations for server & client bundles (see [Webpack config](https://github.com/reactjs/react-rails/tree/master/test/dummy/config/webpack))
- Replaces WebpackManifestContainer, which searched for assets in the webpack manifest, with SeparateServerBundleContainer, which expects a single server bundle file & does not use the webpack manifest at all.
- All in one PR! #1274
### Dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to follow our convention, we need to add each change in the appropriate category and then add the PR number. It is fine to repeat the PR number in multiple entries.

This way, we won't have any line saying "All in one PR..."

Also since this is a changelog for the release, we shouldn't both say add support for Shakapacker 6 and also add support for Shakapacker 7. We basically drop support for Shakapacker 6. We jump to Shakapacker 7.

@ahangarha ahangarha self-requested a review July 21, 2023 22:26
@ahangarha ahangarha dismissed their stale review July 21, 2023 22:28

Changes while reviewing

Copy link
Collaborator

@ahangarha ahangarha left a comment

Choose a reason for hiding this comment

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

Great 👍🏾

@ahangarha ahangarha marked this pull request as ready for review July 22, 2023 02:54
@Judahmeek Judahmeek requested a review from justin808 July 22, 2023 03:41
CHANGELOG.md Outdated
## Breaking Changes
### Removed
- Support & testing for Webpacker & Shakapacker v6. #1274
- WebpackManifestContainer, which searched for assets in the webpack manifest. #1274
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add

- Requires upgrading to Shakapacker v7

Does it?

or only the generator?

can a shakapacker v6 or webpacker v5 project update?

can you use without any shakapacker? and only sprockets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, Shakapacker v7 is currently required because we have code that calls Shakapacker.config

If you want, we could change the constant back to Webpacker for backwards compatibility.

@justin808
Copy link
Collaborator

@ahangarha was this tested with React 17 from shakapacker?

Sprockets will only having react 18

@Judahmeek Judahmeek force-pushed the update-react-to-18 branch from d571dcd to 1b6b7ad Compare July 25, 2023 23:00
@@ -143,7 +147,7 @@ var ReactRailsUJS = {

for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
ReactDOM.unmountComponentAtNode(node);
ReactDOM.createRoot ? this.unmountRoot(node) : ReactDOM.unmountComponentAtNode(node);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use an if statement

@@ -131,6 +132,9 @@ var ReactRailsUJS = {
} else {
const root = createReactRootLike(node)
component = root.render(component);
if(ReactDOM.createRoot) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

make variable

// Means React 18 or greater
const supportsRootsApi  = typeof(ReactDOM.createRoot) !== "undefined"

@@ -155,6 +163,15 @@ var ReactRailsUJS = {
detectEvents(this)
},

unmountRoot: function(node) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment

// only for supportsRootsApi

@@ -155,6 +163,15 @@ var ReactRailsUJS = {
detectEvents(this)
},

unmountRoot: function(node) {
var targetRoots = this.roots.filter(function(rootElement) {return rootElement["node"] && (rootElement["node"] === node)})
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should have at least eslint -- this formatting is bad...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree.
Once I tried to add eslint configuration, but the result was much worse than adding Rubocop. Then I stopped it.

@@ -7,7 +7,7 @@ var constructorFromGlobal = require("./src/getConstructor/fromGlobal")
var constructorFromRequireContext = require("./src/getConstructor/fromRequireContext")
var constructorFromRequireContextWithGlobalFallback = require("./src/getConstructor/fromRequireContextWithGlobalFallback")
var constructorFromRequireContextsWithGlobalFallback = require("./src/getConstructor/fromRequireContextsWithGlobalFallback")
const { supportsHydration, reactHydrate, createReactRootLike } = require("./src/renderHelpers")
const { supportsHydration, reactHydrate, createReactRootLike, supportsRootsApi } = require("./src/renderHelpers")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why mix var and const?

Copy link
Collaborator

Choose a reason for hiding this comment

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

requires should be const

rootElement["root"].unmount();
rootElement["root"] = null;
rootElement["node"] = null;
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

eslint passing? weird

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't check linter!

@@ -1,3 +1,10 @@
// polyfill TextEncoder & TextDecoder onto `util` b/c `node-util` polyfill doesn't include them
// https://github.com/browserify/node-util/issues/46
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment on b/c react 18

CHANGELOG.md Outdated

## Breaking Changes
### Removed
- Support & testing for Webpacker & Shakapacker v6. #1274
Copy link
Collaborator

Choose a reason for hiding this comment

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

not a breaking change

just remove ^^^ line

CHANGELOG.md Outdated
### Added
- Add support & testing for Shakapacker 7 #1274 and #1285

- Support & testing for Shakapacker v7. #1274 and #1285
Copy link
Collaborator

Choose a reason for hiding this comment

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

Updated not added that gem tests now use shakapacker v7 and not ...

CHANGELOG.md Outdated
- Replaces WebpackManifestContainer, which searched for assets in the webpack manifest, with SeparateServerBundleContainer, which expects a single server bundle file & does not use the webpack manifest at all. #1274

## Breaking Changes
### Removed
Copy link
Collaborator

Choose a reason for hiding this comment

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

only put what's breaking under breaking

don't have subtopics

only provide list of what updates an upgrader needs to do

CHANGELOG.md Outdated
#### Changed
- Requires separate compilations for server & client bundles (see [Webpack config](https://github.com/reactjs/react-rails/tree/master/test/dummy/config/webpack)). #1274
Copy link
Collaborator

Choose a reason for hiding this comment

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

emphasize that this is a potentially breaking change if NOT using sprockets and using SSR. Clarity! and that goes under the breaking changes.

@justin808
Copy link
Collaborator

CI failing also

@Judahmeek Judahmeek force-pushed the update-react-to-18 branch from df72cdc to 8d4cf3d Compare July 27, 2023 07:05
@Judahmeek Judahmeek force-pushed the update-react-to-18 branch from 8d4cf3d to 48c21f3 Compare July 27, 2023 07:08
@Judahmeek Judahmeek merged commit 81cea75 into master Jul 27, 2023
@Judahmeek Judahmeek deleted the update-react-to-18 branch July 27, 2023 07:35
@@ -170,7 +193,6 @@ ReactRailsUJS.handleUnmount = function(e) {
if (e && e.target) {
target = e.target;
}
ReactRailsUJS.unmountComponents(target);

Choose a reason for hiding this comment

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

With this change, ReactRailsUJS.handleUnmount is now a no-op. That doesn't seem intentional ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants