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

Fixed an issue with mounting a parcel when StrictMode is enabled #206

Merged
merged 4 commits into from
Sep 14, 2024

Conversation

nickbosland
Copy link
Contributor

StrictMode in React 18 renders a component an extra time where the component is unmounted and mounted again. This sets the unmounted value to true which prevent to component from actually mounting.

Fixes #160

Copy link

changeset-bot bot commented Feb 23, 2024

🦋 Changeset detected

Latest commit: cf6b87d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
single-spa-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@MilanKovacic MilanKovacic self-requested a review May 12, 2024 08:24
@lipsumar
Copy link

We are anxiously waiting for this PR to land. We've tested it and it seems to work fine.

@MilanKovacic
Copy link
Contributor

I will take a look.

@aaronbates
Copy link

Hi @MilanKovacic did you get a chance to take a look? We'd very much appreciate it!

Copy link
Contributor

@MilanKovacic MilanKovacic left a comment

Choose a reason for hiding this comment

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

Reviewed

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a new test that renders in strict mode using the https://testing-library.com/docs/react-testing-library/api/#configure-option option, and leave existing tests as-is.
Reason for this is that strict mode alters the behaviour, and tests no longer test how library will behave in production.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I have pushed the changes where I updated @testing-library/react to 13.4.0. This is the version that added the proposed configure function and I also updated the parcel test where it run all the test with and without strict mode enabled.

@aaronbates
Copy link

Thank you @MilanKovacic — appreciated.

@nickbosland if you get chance to take a look at the feedback that would be great, or equally we'd be happy to submit a PR if you're short on time. Thanks all

Copy link
Contributor

@MilanKovacic MilanKovacic left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you.

@aaronbates
Copy link

@nickbosland are you OK to merge this if you have rights? TY

@lipsumar
Copy link

@MilanKovacic what are the next steps to get this released ?

@MilanKovacic
Copy link
Contributor

It is waiting for approval from Joel.

Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

The code change makes sense. I've left one comment on the tests.

@@ -26,6 +26,7 @@ export default class Parcel extends React.Component {
}
}
componentDidMount() {
this.unmounted = false;
Copy link
Member

Choose a reason for hiding this comment

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

I ran this code locally to see which tests failed in strict mode when this line was commented versus uncommented.

All tests pass regardless of whether this line of code is included. Please add a new test that demonstrates that this.unmounted = false is necessary.

Choose a reason for hiding this comment

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

cc @nickbosland thanks

Copy link
Contributor Author

@nickbosland nickbosland Jul 1, 2024

Choose a reason for hiding this comment

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

Thanks for the CC. I somehow missed the notification.

I have updated the @testing-library/react to 14.2.0 which actually adds the option to configure whether strict mode is used in the tests or not. I also messed up the property name of the option somehow 🤦. I had to move the configure to the beforeEach as it does not work in the beforeAll.

Now multiple tests fail when this is line is removed.

Choose a reason for hiding this comment

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

Thanks @nickbosland — cc @joeldenning would you be happy to proceed with the PR now? Appreciate you taking a look!

Choose a reason for hiding this comment

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

@MilanKovacic @joeldenning any chance this can be reviewed again ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've contacted Joel to re-review it.

@joeldenning joeldenning merged commit 986149d into single-spa:main Sep 14, 2024
2 checks passed
@github-actions github-actions bot mentioned this pull request Sep 14, 2024
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.

Parcel never mounts component with StrictMode enabled
5 participants