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

Support for React <18 #34

Closed
Atmos4 opened this issue Jul 10, 2024 · 5 comments · Fixed by #38
Closed

Support for React <18 #34

Atmos4 opened this issue Jul 10, 2024 · 5 comments · Fixed by #38
Labels
bug Something isn't working

Comments

@Atmos4
Copy link

Atmos4 commented Jul 10, 2024

Right now, there is a problem when trying to use a version that is lower than 18.

Failed to compile, check the errors for troubleshooting.
File: javascript/esm|C:\Users\Atmos4\Workspace\rsbuild-react-storybook\node_modules\@storybook\react-dom-shim\dist\react-18.mjs:1:1
  × Resolve error: Can't resolve 'react-dom/client' in 'C:\Users\Atmos4\Workspace\rsbuild-react-storybook\node_modules\@storybook\react-dom-shim\dist'
   ╭─[1:1]
 1 │ import React, { useRef, useLayoutEffect } from 'react';
 2 │ import ReactDOM from 'react-dom/client';
   ·                      ──────────────────
 3 │
 4 │ var nodes=new Map,WithCallback=({callback,children})=>{let once=useRef();return useLayoutEffect(()=>{once.current!==callback&&(once.current=callback,callback());},[callback]),children},renderElement=async(node,el,rootOptions)=>{let root=await getReactRoot(el,rootOptions);return new Promise(resolve=>{root.render(React.createElement(WithCallback,{callback:()=>resolve(null)},node));})},unmountElement=(el,shouldUseNewRootApi)=>{let root=nodes.get(el);root&&(root.unmount(),nodes.delete(el));},getReactRoot=async(el,rootOptions)=>{let root=nodes.get(el);return root||(root=ReactDOM.createRoot(el,rootOptions),nodes.set(el,root)),root};

I believe that if used correctly, @storybook/react-dom-shim will target the correct React DOM import (react-dom instead of react-dom/client).

Reproduction

From the /sandboxes/react-rsbuild, change the React version to 16 or 17.

@fi3ework
Copy link
Member

It should work. Could you try the sandbox demo in a new repository as multi-version React in a monorepo is a mess.

@Atmos4
Copy link
Author

Atmos4 commented Jul 12, 2024

@fi3ework here is the replicate of the repo I used for testing. Unfortunately I couldn't get the sandbox to run because storybook thinks the port is taken, but you should be able to access my code and reproduce it locally. I don't do anything specific, just change the React version to 17.

As soon as the compatibility with 8.2 is fixed I can test it out.

@fi3ework
Copy link
Member

fi3ework commented Jul 12, 2024

I've located where's wrong. Fixing that.

@fi3ework fi3ework added the bug Something isn't working label Jul 12, 2024
@fi3ework
Copy link
Member

Fixed in 0.0.7.

@Atmos4
Copy link
Author

Atmos4 commented Jul 13, 2024

Just tested it, it works like a charm! I will update the repo I posted in the thread.

Thank you for your help! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants