Skip to content

fix: Update react dependencies to v18.1.0 - #8916

Closed
benwis wants to merge 3 commits into
remix-run:mainfrom
benwis:main
Closed

benwis wants to merge 3 commits into
remix-run:mainfrom
benwis:main

Conversation

@benwis

@benwis benwis commented Jun 1, 2022

Copy link
Copy Markdown

Issue

react-router and react-router-dom's fixed react and react-dom dependencies are causing multiple versions of react and react-dom to be bundled in my remix app.

Fix

Update package.json to version 18.1. Alternatively this could be changed to be >16 like the other Remix packages I can confirm that this fixes it in my Remix stack.

@remix-cla-bot

remix-cla-bot Bot commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

Hi @benwis,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot

remix-cla-bot Bot commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

Thank you for signing the Contributor License Agreement. Let's get this merged! πŸ₯³

@benwis benwis changed the title Updated react dependencies to v18.1.0 fix: Updated react dependencies to v18.1.0 Jun 1, 2022
@brophdawg11

Copy link
Copy Markdown
Contributor

Hey Ben! Just to clarify - are you getting 2 versions of react/react-dom in your bundles? Or are you getting type errors during development when using react@18?

@benwis

benwis commented Jun 1, 2022 •

Copy link
Copy Markdown
Author

@brophdawg11 Hey Matt, This is the error I get:

Unexpected Server Error

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

Looks like the culprit is react-router-dom, as all the other deps on react for the remix packages were >16 and not tied to a specific release.So I ended up with both v18 that I defined in my package.json and v17 for all the remix react deps.

 npm ls react
remix-rust@0.0.1 /Users/benwis/Documents/air-metal-stack
└─┬ remix-air-metal@ -> ./packages/remix-app
  β”œβ”€β”¬ @remix-run/deno@1.5.1
  β”‚ └─┬ @remix-run/server-runtime@1.5.1
  β”‚   └── react@17.0.2 deduped
  β”œβ”€β”¬ @remix-run/react@1.5.1
  β”‚ β”œβ”€β”¬ react-dom@17.0.2
  β”‚ β”‚ └── react@17.0.2 deduped
  β”‚ β”œβ”€β”¬ react-router-dom@6.3.0
  β”‚ β”‚ β”œβ”€β”¬ react-router@6.3.0
  β”‚ β”‚ β”‚ └── react@17.0.2 deduped
  β”‚ β”‚ └── react@17.0.2 deduped
  β”‚ └── react@17.0.2
  β”œβ”€β”¬ react-dom@18.1.0
  β”‚ └── react@18.1.0 deduped
  └── react@18.1.0

I've pushed a working version to the react-18 branch of this repo, I just had to override all the react dependencies listed above. If you want to see the error, feel free to go back 1 commit in the react-18 branch

Not sure if the best approach here is to change the react dependencies to be 18 or just be > 16 or > 17, I'll leave that to the team.

@benwis benwis changed the title fix: Updated react dependencies to v18.1.0 fix: Update react dependencies to v18.1.0 Jun 1, 2022
@brophdawg11

Copy link
Copy Markdown
Contributor

Thanks for the reproduction - the thing that's got me confused is why changing @types/react would have any impact on the actual react package used. I'll pull down that repo and poke around a bit and see what I can find πŸ‘

@brophdawg11 brophdawg11 self-assigned this Jun 1, 2022
@benwis

benwis commented Jun 2, 2022

Copy link
Copy Markdown
Author

@brophdawg11 Oof, this is what I get when I submit PRs before coffee. I also needed to update the main react deps, and I have done so now

@brophdawg11

Copy link
Copy Markdown
Contributor

haha, an all too common mistake!

I'm trying to get your stack running locally on an M1 MBP but getting the following on rust installation step 2:

> curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
wasm-pack-init: no precompiled binaries available for CPU architecture: arm64

Any insights on building on an M1?

I'm also curious if this double-dependency thing is deno-related - any idea if it's reproducible in a non-rust world using deno?

@benwis

benwis commented Jun 2, 2022 •

Copy link
Copy Markdown
Author

So far this is the only thing I have tried Deno with, but the build step doesn't use rust at all, so probably? I did not notice this error updating the blues stack to react 18 though, but that's node only.

I usually develop on an M1 Macbook Pro, you want to run cargo install wasm-pack, that should work fine on our computers but take a bit longer. I will update the instructions!

@brophdawg11

Copy link
Copy Markdown
Contributor

ok - I got back around to playing with this locally today (thanks for the tip on cargo install wasm-pack)

On my very first install today I had a mismatch but that was with the version of this repo I cloned last week and it had a local package-lock.json so I had already done some stuff last week which could have borked the setup.

Today I tried cloning and installing fresh (without a package-lock.json) in the repo on both branches, and I wasn't able to reproduce the mismatch.

# A fresh install on main gave me properly deduped 17.0.2 packages
> git clone git@github.com:benwis/air-metal-stack.git
> cd air-metal-stack
> npm install
> npm ls react-dom
air-metal-stacl@0.0.1 ./air-metal-stack
└─┬ remix-air-metal@ -> ./packages/remix-app
  β”œβ”€β”¬ @remix-run/deno@1.5.1
  β”‚ └─┬ @remix-run/server-runtime@1.5.1
  β”‚   └── react-dom@17.0.2 deduped
  β”œβ”€β”¬ @remix-run/react@1.5.1
  β”‚ β”œβ”€β”€ react-dom@17.0.2 deduped
  β”‚ └─┬ react-router-dom@6.3.0
  β”‚   └── react-dom@17.0.2 deduped
  └── react-dom@17.0.2

# Then I did a fresh install on the react-18 branch and got properly deduped versions there
> git checkout react-18
> rm -rf node_modules/
> rm -f package-lock.json
> npm install
> npm ls react-dom
remix-rust@0.0.1 /Users/matt/me/remix/repos/playgrounds/air-metal-stack2
└─┬ remix-air-metal@ -> ./packages/remix-app
  β”œβ”€β”¬ @remix-run/deno@1.5.1
  β”‚ └─┬ @remix-run/server-runtime@1.5.1
  β”‚   └── react-dom@18.1.0 deduped
  β”œβ”€β”¬ @remix-run/react@1.5.1
  β”‚ β”œβ”€β”€ react-dom@18.1.0 deduped
  β”‚ └─┬ react-router-dom@6.3.0
  β”‚   └── react-dom@18.1.0 deduped
  └── react-dom@18.1.0

The dependencies you're updating in this PR are the monorepo deps for local development in react-router - but they aren't the deps for the published packages - those are all specified as peerDependencies which should support 17 or 18 without issue.

  "peerDependencies": {
    "react": ">=16.8",
    "react-dom": ">=16.8"
  },

I also tried creating a new app using create-remix using a template of your local repo on the react-18 branch and that seemed ok too.

Do you want to try this fresh and see if you're still hitting the issue? See if you can find any specific steps that get you into this scenario?

@brophdawg11 brophdawg11 removed their assignment Jun 7, 2022
@benwis

benwis commented Jun 7, 2022

Copy link
Copy Markdown
Author

Really appreciate the second pair of eyes on this. You are quite correct, once I deleted package-lock.json and reinstalled everything, all the React dependencies correctly parsed. God npm frustrates me sometimes. I am closing this, as it appears to not be an issue.

@benwis benwis closed this Jun 7, 2022
brophdawg11 added a commit that referenced this pull request Mar 27, 2024
Co-authored-by: Matt Brophy <matt@brophy.org>
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