React: Cannot read property 'return' of null

Created on 24 Mar 2018  路  10Comments  路  Source: facebook/react

Running into a strange issue that i cannot reproduce, it happens when running tests in Karma using 16.3.0-alpha.3

image

The issue is here:

https://github.com/facebook/react/blob/208b490ed907346ae3e37159535299899f74312d/packages/react-reconciler/src/ReactFiberScheduler.js#L864-L877

My test is throwing an error because of a missing onChange handler when rendering a checkbox with checked but no handler. What appears to be happening is that nextUnitOfWork is not null and misses the first branch, replayUnitOfWork is run, after which nextUnitOfWork _is_ null and sourceFiber doesn't exist and so access of return fails.

I've tried for a while to reproduce it, the following codesandbox is a simplified version of the code that is throwing, but the error isn't present there :/ https://codesandbox.io/s/0332y243zp

Bug

Most helpful comment

I've upgraded to React v16.3.2 and am seeing a similar error:

screen shot 2018-04-19 at 3 02 50 pm

It's referencing a similar area of the React codebase, without a null check:

screen shot 2018-04-19 at 3 06 20 pm

All 10 comments

Hmm, I was concerned this might happen. We assume that replayUnitOfWork will be idempotent but looks like you've found a case where it's not. I'll take a look at this.

Changing line 877 to

const sourceFiber: Fiber = failedUnitOfWork;

isn't a sufficient fix because if it's not equal to nextUnitOfWork, that means the stack is misaligned.

One option is to add an invariant that throws if nextUnitOfWork !== failedUnitOfWork. Usually we avoid DEV-only invariants, but since this should only be possible in an error case, anyway, maybe we can get away with it.

Btw, there's another potentially related bug that happens if you remove this feature flag override that manifests as an Unexpected pop warning. Maybe we should change this test suite to use the feature flag that people use in real bundles? This doesn't leave me very confident.

Cheers, this PR just saved us from what would have been a confusing day!

I've upgraded to React v16.3.2 and am seeing a similar error:

screen shot 2018-04-19 at 3 02 50 pm

It's referencing a similar area of the React codebase, without a null check:

screen shot 2018-04-19 at 3 06 20 pm

Please file a new issue with a reproducing case. Thanks.

To everyone who "+1"s the previous comment: sorry, but this doesn't help us solve the issue at all.

If you're seeing this after upgrading both react and react-dom to 16.3.2 or higher, please file a new issue with a minimal reproducing case extracted from your project. This will be very helpful to everyone, and we'll be able to quickly diagnose and fix this.

Was this page helpful?
0 / 5 - 0 ratings