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

React 19 support #3985

Merged
merged 13 commits into from
Dec 11, 2024
Merged

React 19 support #3985

merged 13 commits into from
Dec 11, 2024

Conversation

imjordanxd
Copy link
Contributor

@imjordanxd imjordanxd commented Dec 9, 2024

Code change checklist

  • Added/updated unit tests
  • Updated /docs. For new functionality, at least API.md should be updated N/A
  • Verified that there is no significant performance drop (yarn mobx test:performance)

Note: before merging, I think I should also dup any propType checks inside render to be compatible across multiple React versions. I also intentionally haven't bumped the types for react and react-dom to keep the propTypes types such as Validator, Requireable etc.

Copy link

changeset-bot bot commented Dec 9, 2024

🦋 Changeset detected

Latest commit: f1dbfeb

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

This PR includes changesets to release 2 packages
Name Type
mobx-react-lite Minor
mobx-react Minor

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

@imjordanxd imjordanxd marked this pull request as ready for review December 11, 2024 03:15
@@ -377,7 +377,7 @@ describe("is used to keep observable within component body", () => {
})
expect(container.querySelector("span")!.innerHTML).toBe("22")
expect(counterRender).toBe(2)
expect(observerRender).toBe(3)
Copy link
Contributor Author

@imjordanxd imjordanxd Dec 11, 2024

Choose a reason for hiding this comment

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

React now renders the observer an extra time for some reason. The reaction only fires once though when the store mutates

Copy link
Member

Choose a reason for hiding this comment

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

these hooks are all basically anti-pattern anyway, so good enough :)

Comment on lines +9 to +13
if (children && render) {
console.error(
"MobX Observer: Do not use children and render in the same time in `Observer`"
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

propTypes removed in v19 so I've duped this inside the render body

@@ -49,7 +49,7 @@ test("computed properties react to props when using hooks", async () => {
act(() => {
jest.runAllTimers()
})
expect(seen).toEqual(["parent", 0, "parent", 2])
expect(seen).toEqual(["parent", 0, "parent", 2, 2])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}, [multiplier])
useEffect(() => setMultiplier(3), [])
},
{
Copy link
Member

Choose a reason for hiding this comment

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

NIT: This pattern reoccures quite a few times in the test, might be nice to make a utility for it? (separate PR is fine if interested)

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

This looks great, thanks so much for picking this up!

@mweststrate mweststrate merged commit 2587df3 into mobxjs:main Dec 11, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Dec 11, 2024
interface IObserverProps {
children?(): React.ReactElement | null
render?(): React.ReactElement | null
}

function ObserverComponent({ children, render }: IObserverProps) {
if (children && render) {
console.error(
"MobX Observer: Do not use children and render in the same time in `Observer`"
Copy link

@levrik levrik Dec 17, 2024

Choose a reason for hiding this comment

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

typo: in the same time -> at the same time

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.

3 participants