React-native-web: AppRegistry.runApplication replaces DOM node in dev but appends in prod

Created on 21 Jun 2019  路  4Comments  路  Source: necolas/react-native-web

The problem
In dev mode, AppRegistry.runApplication replaces the children of the target DOM node as expected. In prod mode, however, the react app is appended to a nested DOM element.

How to reproduce

Simplified test case:
Dev: https://codesandbox.io/s/issue-react-native-for-web-g512l
Prod: https://csb-g512l.netlify.com/

Steps to reproduce:

  1. Add child nodes to the targeted DOM element.
  2. Deploy app.
  3. See app appended to child node.

Expected behavior
I expect the DOM element's children to be replaced, not appended. As it does in dev.

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.11.x
  • React (version): 16.8.4
  • Browser: Chrome 75.0.3770.100

I'm trying to create a loading screen using DOM elements in the index.html file.

Most helpful comment

What I think I'll do is add a field hydrate to the application params, and that can be used on the client to opt into hydrating the app if you know you server rendered.

ApplicationRegistry.runApplication('App', {
  initialProps: {},
  rootTag: document.getElementById('root'),
  hydrate: true
});

All 4 comments

That's probably down to this line and ReactDOM leaving existing HTML alone when hydrating

What I think I'll do is add a field hydrate to the application params, and that can be used on the client to opt into hydrating the app if you know you server rendered.

ApplicationRegistry.runApplication('App', {
  initialProps: {},
  rootTag: document.getElementById('root'),
  hydrate: true
});

Any progress with this issue?

This change is in master if you want to try it out before I cut a pre-release version that includes it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SamyPesse picture SamyPesse  路  3Comments

ndbroadbent picture ndbroadbent  路  3Comments

EvanBacon picture EvanBacon  路  3Comments

blairio picture blairio  路  3Comments

bcpugh picture bcpugh  路  3Comments