reactjs / React.NET

.NET library for JSX compilation and server-side rendering of React components
https://reactjs.net/
MIT License
2.3k stars 937 forks source link

React 18 root support #1286

Open LinusCenterstrom opened 2 years ago

LinusCenterstrom commented 2 years ago

fixes #1285 This is mostly unrelated to #1265 and still uses the renderToString API

Things that should probably be done before this is merged (happy to help with this if you want)

  1. Update the documentation.
  2. Update the code for ReactRouter to make this work there as well.

I have not looked into making this work with the automatically bundled versions of React & ReactDOM if LoadReact is set to true.

For anyone else looking to make this work: To make the js code run server-side you have to change the import of react-dom/server to instead be eact-dom-server-legacy.browser.production.min.js or react-dom/cjs/react-dom-server-legacy.browser.development since the new server-renderer uses classes that do not exist in the .net JS environment and instantly crashes.

The globally exposed window.ReactDOM object on the clientside should be imported from react-dom/client instead of react-dom

cb-eli commented 2 years ago

@LinusCenterstrom, In your PR, is it possible to control the used API per root component? Or, it's a global configuration?

LinusCenterstrom commented 2 years ago

It's currently only a global configuration

dustinsoftware commented 2 years ago

Thanks!!

I see the PR checks are failing, is that new to this PR?

On Mon, Apr 11, 2022 at 02:40, LinusCenterstrom @.***> wrote:

It's currently only a global configuration

— Reply to this email directly, view it on GitHub https://github.com/reactjs/React.NET/pull/1286#issuecomment-1094610599, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHGCFRY5WQT5VP3VQR52FTVEPCOXANCNFSM5SIVUTMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

LinusCenterstrom commented 2 years ago

Thanks!!

I see the PR checks are failing, is that new to this PR?

Don't think so, looks like they are failing on all PR:s from what I can see

magnusottosson commented 2 years ago

I also need this. Is the project dead? Any alternatives to get React 18 support?

LinusCenterstrom commented 1 year ago

@magnusottosson If you are still looking, you could use the main branch of our fork here https://github.com/MultinetInteractive/React.NET which I made to fix it for my company's use. It is only supported if you supply your own version of React & ReactDOMServer. (.SetLoadReact(false) during startup)

The initialization code for our serverbundle looks like this (we bundle through webpack) (Make sure the relative paths for the imports are correct if you copy paste)

var ReactDOMServer = require(process.env.NODE_ENV !== "production"
    ? "../node_modules/react-dom/cjs/react-dom-server-legacy.browser.development"
    : "../node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.min.js");

var React = require("react");
var ReactDOM = require("react-dom");

if (!global) {
    global = {};
}

global.React = React;
global.ReactDOM = ReactDOM;
global.ReactDOMServer = ReactDOMServer;

We've been using it in production pretty much since I opened this PR and it seems to work fine. It is not very likely that we will add support for anything other than what we use internally however.

va-timorris commented 1 year ago

It feels like the repo is dead - nobody managing it. What a shame.

rshackleton commented 1 year ago

@va-timorris check out https://github.com/DaniilSokolyuk/NodeReact.NET