react_on_rails icon indicating copy to clipboard operation
react_on_rails copied to clipboard

unable to use React suspense with react_on_rails gem

Open ziploker opened this issue 3 years ago • 2 comments

I'm trying to use the experimental version of react to use suspense for data fetching etc…

i installed the experimental version of react via npm (had to use --force). (not sure if the dependency issue i had was react_on_rails related)

Also, part of the install process says to change this:

ReactDOM.render(
<React.StrictMode>

</React.StrictMode>,
document.getElementById(“root”)
);

to this:

ReactDOM.unstable_createRoot(document.getElementById(“root”)).render(
<React.StrictMode>

</React.StrictMode>
);

However, with react on rails it works different.

How can i enable react experimental mode to be able to use React.suspense

Thanks for any help…

ziploker avatar Aug 11 '21 13:08 ziploker

You can make a PR to try allowing for another option here:

https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.ts#L171

      if (isServerRenderResult(reactElementOrRouterResult)) {
        throw new Error(`\
You returned a server side type of react-router error: ${JSON.stringify(reactElementOrRouterResult)}
You should return a React.Component always for the client side entry point.`);
      } else if (shouldHydrate) {
        ReactDOM.hydrate(reactElementOrRouterResult as ReactElement, domNode);
      } else {
        ReactDOM.render(reactElementOrRouterResult as ReactElement, domNode);
      }

justin808 avatar Aug 26 '21 08:08 justin808

Once this feature is non-experimental, I plan to support this.

@ziploker and others, PRs welcome!

justin808 avatar Sep 22 '21 00:09 justin808