Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

[react-testing] Fixed a null exception if the inner root component is unmounted by the outer wrapper during an act #2612

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

melnikov-s
Copy link
Contributor

Description

This fixes an edge-case that was introduced in #1821

This is a rare occurrence but can happen if somehow the test wrapper unmounts the inner test root during an action. We found this while performing the react router 6 migration on web. Since we wrap our inner test root with a <Route> component at a given path a navigation within the test to a different route will unmount the component resulting in a cryptic error message:

TypeError: Cannot use 'in' operator to search for '_reactInternalFiber' in null

This PR prevents the root from updating when the inner wrapper is unmounted, once/if it is remounted subsequent updates will work as expected.

@melnikov-s melnikov-s requested a review from a team as a code owner March 23, 2023 19:35
@melnikov-s
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @melnikov-s! Your snapshot has been published to npm.

Test the snapshot by updating your package.json with the newly published version:

yarn add @shopify/react-testing@0.0.0-snapshot-20230323202007

Copy link
Contributor

@iAmNathanJ iAmNathanJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@melnikov-s melnikov-s force-pushed the react-testing-do-not-throw-on-unmount branch from ebd1faa to 928a344 Compare March 24, 2023 13:34
@melnikov-s
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @melnikov-s! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/koa-metrics@0.0.0-snapshot-20230324134013
yarn add @shopify/koa-performance@0.0.0-snapshot-20230324134013
yarn add @shopify/react-testing@0.0.0-snapshot-20230324134013
yarn add @shopify/statsd@0.0.0-snapshot-20230324134013

… unmounted by the outer wrapper during an act
@melnikov-s melnikov-s force-pushed the react-testing-do-not-throw-on-unmount branch from 928a344 to 2fd6bbe Compare March 24, 2023 16:11
@melnikov-s melnikov-s merged commit 39e910e into main Mar 24, 2023
@melnikov-s melnikov-s deleted the react-testing-do-not-throw-on-unmount branch March 24, 2023 16:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants