question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing a component into the entry React component causes dismount of the whole tree

See original GitHub issue

Hi @inokawa ! First of all wanted to say thank you for this awesome library! It’s quite cool, and very niche and I love it. I encountered one issue tho, maybe it’s a bug, maybe it’s intentional, either way I wanted to ask if you could provide a solution.

Your library works great when my React entry file is a single component, for example:

const Root = () => {
    return <div>Hello</div>
}

export default renderWebView(<Root />)

But the moment I try to import another React component, let’s call it Test.js, the result I get in the RN WebView is a blank page (I assume React dismounts the whole component tree due to some kind of error, although no error listeners on the WebView trigger).

How to replicate: Use the demo app, create another react component called Test.js

const Test = () => {
    return <div>Test</div>
}

Try to import and render Test in our Root entry component like so:

import Test from './Test'
const Root = () => {
    return <div>
        Hello
        <Test />
    </div>
}

export default renderWebView(<Root />)

The result is an empty WebView in RN, without any error! Could you try and think of a solution? I was thinking maybe I should wrap my Test export in renderWebView, but I’m not sure that is the right approach. I appreciate any input on this!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tk-nicommented, Feb 17, 2022

@inokawa It works! The issue was the React import indeed. I cleared metro’s cache and build cache and rebuilt. Thanks!

0reactions
tk-nicommented, Feb 17, 2022

Still an empty screen in my env.

//Test.js
import React from 'react';
const Test = () => {
  return <div>Im test</div>;
};
export default Test;

//index.js
import React from 'react';
import {webViewRender} from 'react-native-react-bridge/lib/web';
import Test from './Test';

const Root = () => {
  return (
    <div>
      Hello
      <Test />
    </div>
  );
};

export default webViewRender(<Root />);

The webview onLoad triggers, but still no errors.

//WebView in App.js
<WebView
  ref={ref}
  source={{html: webApp}}
  onMessage={onMessage}
  onError={ev => {
    const {nativeEvent} = ev;
    console.warn('onError: ', ev, nativeEvent);
  }}
  onHttpError={ev => console.warn('onHttpError: ', ev)}
  renderError={errorDomain => console.warn('renderError: ', errorDomain)}
  onLoad={ev => console.log('onLoad:', ev)}
  onLoadingError={ev => console.warn('onLoadingError:', ev)}
  onRenderProcessGone={ev => console.warn('onRenderProcessGone', ev)}
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React.Component
An update can be caused by changes to props or state. These methods are called in the following order when a component is...
Read more >
ReactDOM – React
Render a React element into the DOM in the supplied container and return a reference to the component (or returns null for stateless...
Read more >
Error Boundaries - React
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI ......
Read more >
Reconciliation - React
When building up a new tree, new DOM nodes are inserted into the DOM. Component instances receive UNSAFE_componentWillMount() and then componentDidMount() .
Read more >
Strict Mode - React
To do this, React will support remounting trees using the same component state used before unmounting. This feature will give React better performance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found