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

"TypeError: Cannot read property 'setState' of null" when using React.lazy #29004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yrlmanoharreddy
Copy link

Title: "TypeError: Cannot read property 'setState' of null" when using React.lazy
Description:
When using React.lazy to lazily load a component, users are reporting a "TypeError: Cannot read property 'setState' of null" error in certain scenarios. This issue seems to occur when a lazily loaded component is unmounted before it finishes loading, leading to a null state and the error.

Expected Behavior:
The lazy component should load without any errors, even if it's unmounted before it finishes loading.
Actual Behavior:
A "TypeError: Cannot read property 'setState' of null" error is thrown in the console, and the lazy component fails to load properly.

Possible Solution:
A potential solution could involve modifying the React.lazy implementation to check if the component instance still exists before attempting to set its state during the loading process.
Please let me know if you need any additional information or have any suggestions for addressing this issue.

@facebook-github-bot
Copy link

Hi @yrlmanoharreddy!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@react-sizebot
Copy link

Comparing: 9b13002...70c0f28

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.66 kB 6.66 kB +0.11% 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 492.61 kB 492.61 kB = 87.88 kB 87.88 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB +0.11% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 498.86 kB 498.86 kB = 88.92 kB 88.93 kB
facebook-www/ReactDOM-prod.classic.js = 591.22 kB 591.22 kB = 103.96 kB 103.96 kB
facebook-www/ReactDOM-prod.modern.js = 567.44 kB 567.44 kB = 100.36 kB 100.36 kB
test_utils/ReactAllWarnings.js Deleted 64.26 kB 0.00 kB Deleted 16.02 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react/cjs/react.react-server.production.js +1.11% 14.96 kB 15.13 kB +0.96% 4.07 kB 4.11 kB
oss-stable/react/cjs/react.react-server.production.js +1.11% 14.99 kB 15.15 kB +1.00% 4.10 kB 4.14 kB
oss-stable-semver/react/cjs/react.production.js +0.98% 16.87 kB 17.03 kB +0.87% 4.39 kB 4.43 kB
oss-stable/react/cjs/react.production.js +0.98% 16.89 kB 17.06 kB +0.91% 4.42 kB 4.46 kB
oss-experimental/react/cjs/react.production.js +0.93% 17.91 kB 18.08 kB +0.86% 4.66 kB 4.70 kB
oss-experimental/react/cjs/react.react-server.production.js +0.89% 18.62 kB 18.78 kB +0.79% 4.96 kB 5.00 kB
facebook-www/React-prod.modern.js +0.72% 23.10 kB 23.26 kB +0.71% 5.93 kB 5.97 kB
facebook-www/React-prod.classic.js +0.72% 23.10 kB 23.27 kB +0.71% 5.93 kB 5.98 kB
facebook-react-native/react/cjs/React-prod.js +0.72% 23.20 kB 23.37 kB +0.62% 5.97 kB 6.00 kB
facebook-www/React-profiling.modern.js +0.71% 23.53 kB 23.70 kB +0.68% 6.01 kB 6.05 kB
facebook-www/React-profiling.classic.js +0.71% 23.53 kB 23.70 kB +0.67% 6.01 kB 6.05 kB
facebook-react-native/react/cjs/React-profiling.js +0.70% 23.64 kB 23.80 kB +0.63% 6.05 kB 6.08 kB
oss-stable-semver/react/cjs/react.react-server.development.js +0.35% 69.04 kB 69.28 kB +0.36% 19.30 kB 19.36 kB
oss-stable/react/cjs/react.react-server.development.js +0.35% 69.07 kB 69.31 kB +0.37% 19.32 kB 19.39 kB
oss-experimental/react/cjs/react.react-server.development.js +0.32% 74.63 kB 74.87 kB +0.32% 20.91 kB 20.97 kB
oss-stable-semver/react/cjs/react.development.js +0.26% 93.35 kB 93.59 kB +0.25% 25.57 kB 25.63 kB
oss-stable/react/cjs/react.development.js +0.26% 93.37 kB 93.61 kB +0.25% 25.60 kB 25.66 kB
oss-experimental/react/cjs/react.development.js +0.25% 94.82 kB 95.06 kB +0.23% 25.95 kB 26.01 kB
facebook-react-native/react/cjs/React-dev.js +0.21% 114.70 kB 114.94 kB +0.25% 30.02 kB 30.10 kB
facebook-www/React-dev.modern.js +0.21% 116.30 kB 116.54 kB +0.22% 30.15 kB 30.21 kB
facebook-www/React-dev.classic.js +0.21% 116.79 kB 117.03 kB +0.23% 30.25 kB 30.32 kB
test_utils/ReactAllWarnings.js Deleted 64.26 kB 0.00 kB Deleted 16.02 kB 0.00 kB

Generated by 🚫 dangerJS against 70c0f28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants