-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
React 19 support #3985
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
Merged
Merged
React 19 support #3985
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
71f03ee
deprecate `IObserver` options and its properties in JSDoc
imjordanxd 763fea1
Merge branch 'mobxjs:main' into main
imjordanxd e160182
Preparing for React 19 - some tests fail
imjordanxd 461c5e7
RTL hooks error
imjordanxd b9da1d6
skipping legacy context tests
imjordanxd 92b9b2d
skipping propTypes and defaultProps forwarding tests
imjordanxd 907dd70
skipping class propTypes test
imjordanxd 90a2272
render time check
imjordanxd 9ce6d94
changed some assertions
imjordanxd 012bf17
added extra render
imjordanxd 1532c2e
added todo
imjordanxd 58b3605
added warning for legacy context types in function components
imjordanxd f1dbfeb
added changeset
mweststrate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import * as mobx from "mobx" | ||
| import * as React from "react" | ||
| import { renderHook } from "@testing-library/react-hooks" | ||
| import { act, cleanup, fireEvent, render } from "@testing-library/react" | ||
| import { act, cleanup, fireEvent, render, renderHook } from "@testing-library/react" | ||
|
|
||
| import { Observer, observer, useLocalObservable } from "../src" | ||
| import { useEffect, useState } from "react" | ||
|
|
@@ -440,75 +439,108 @@ describe("enforcing actions", () => { | |
| mobx.configure({ enforceActions: "never" }) | ||
| consoleWarnMock = jest.spyOn(console, "warn").mockImplementation(() => {}) | ||
|
|
||
| const { result } = renderHook(() => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| const onError = jest.fn() | ||
| const { result } = renderHook( | ||
| () => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }, | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| wrapper: class extends React.Component<React.PropsWithChildren> { | ||
| componentDidCatch = onError | ||
| render() { | ||
| return this.props.children | ||
| } | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| expect(result.error).not.toBeDefined() | ||
| expect(onError).not.toBeCalled() | ||
| expect(consoleWarnMock).not.toBeCalled() | ||
| }) | ||
| it("only when 'observed' should work", () => { | ||
| mobx.configure({ enforceActions: "observed" }) | ||
| consoleWarnMock = jest.spyOn(console, "warn").mockImplementation(() => {}) | ||
|
|
||
| const { result } = renderHook(() => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| const onError = jest.fn() | ||
| renderHook( | ||
| () => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }, | ||
| { | ||
| wrapper: class extends React.Component<React.PropsWithChildren> { | ||
| componentDidCatch = onError | ||
| render() { | ||
| return this.props.children | ||
| } | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| expect(result.error).not.toBeDefined() | ||
| expect(onError).not.toBeCalled() | ||
| expect(consoleWarnMock).not.toBeCalled() | ||
| }) | ||
| it("'always' should work", () => { | ||
| mobx.configure({ enforceActions: "always" }) | ||
| consoleWarnMock = jest.spyOn(console, "warn").mockImplementation(() => {}) | ||
|
|
||
| const { result } = renderHook(() => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| const onError = jest.fn() | ||
| renderHook( | ||
| () => { | ||
| const [multiplier, setMultiplier] = React.useState(2) | ||
| const store = useLocalObservable(() => ({ | ||
| multiplier, | ||
| count: 10, | ||
| get multiplied() { | ||
| return this.multiplier * this.count | ||
| }, | ||
| inc() { | ||
| this.count += 1 | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }, | ||
| { | ||
| wrapper: class extends React.Component<React.PropsWithChildren> { | ||
| componentDidCatch = onError | ||
| render() { | ||
| return this.props.children | ||
| } | ||
| } | ||
| })) | ||
| useEffect(() => { | ||
| store.multiplier = multiplier | ||
| }, [multiplier]) | ||
| useEffect(() => setMultiplier(3), []) | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| expect(result.error).not.toBeDefined() | ||
| expect(onError).not.toBeCalled() | ||
| expect(consoleWarnMock).toBeCalledTimes(2) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.