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

Fix React.lazy infinite loop on passing undefined #15222

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@raunofreiberg
Copy link
Contributor

commented Mar 27, 2019

Related to #15019

The following code no longer produces a loop.

const Component = React.lazy(() => Promise.resolve(undefined));
      ReactDOM.render(
        <div>
          <h1>Hello World!</h1>
          <React.Suspense fallback="..">
            <Component />
          </React.Suspense>
        </div>,
        document.getElementById('container')
      );

Instead, an error is shown: (tried on dev.html standalone fixture)

Uncaught Invariant Violation: Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function.
@kunukn
Copy link
Contributor

left a comment

_result and result are used. Should only be _result

@@ -50,9 +50,9 @@ export function readLazyComponentType<T>(lazyComponent: LazyComponent<T>): T {
thenable.then(
moduleObject => {
if (lazyComponent._status === Pending) {
const defaultExport = moduleObject.default;
const _result = moduleObject ? moduleObject.default : moduleObject;

This comment has been minimized.

Copy link
@eps1lon

eps1lon Apr 1, 2019

Contributor
Suggested change
const _result = moduleObject ? moduleObject.default : moduleObject;
const _result = moduleObject != null ? moduleObject.default : moduleObject;

It's probably a bit exotic to check for strings or numbers but it's closer to the original behavior.

Show resolved Hide resolved packages/react-reconciler/src/ReactFiberLazyComponent.js Outdated
Update packages/react-reconciler/src/ReactFiberLazyComponent.js
Co-Authored-By: raunofreiberg <freiberggg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.