-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Fixed an issue with mounting a parcel when StrictMode is enabled #206
Conversation
🦋 Changeset detectedLatest commit: cf6b87d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
We are anxiously waiting for this PR to land. We've tested it and it seems to work fine. |
I will take a look. |
Hi @MilanKovacic did you get a chance to take a look? We'd very much appreciate it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
src/parcel.test.js
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this 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.
@nickbosland are you OK to merge this if you have rights? TY |
@MilanKovacic what are the next steps to get this released ? |
It is waiting for approval from Joel. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @nickbosland thanks
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
StrictMode in React 18 renders a component an extra time where the component is unmounted and mounted again. This sets the
unmounted
value totrue
which prevent to component from actually mounting.Fixes #160