-
-
Notifications
You must be signed in to change notification settings - Fork 35
feat: support react 19 #654
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
Draft
huyenltnguyen
wants to merge
3
commits into
freeCodeCamp:main
Choose a base branch
from
huyenltnguyen:feat/support-react-19
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Runtime `renderHook` helper that picks a compatible implementation based on | ||
| * the installed testing-library packages: | ||
| * | ||
| * - Prefer `@testing-library/react`'s `renderHook` (available in newer RTL). | ||
| * - Fallback to `@testing-library/react-hooks` for older setups. | ||
| * | ||
| * This keeps tests working across React versions (React 16/17/18 with RHTL, | ||
| * React 18/19 with RTL's `renderHook`). | ||
| */ | ||
|
|
||
| import * as rtl from "@testing-library/react"; | ||
| import * as rhtl from "@testing-library/react-hooks"; | ||
|
|
||
| type ActFn = (cb: () => void) => void; | ||
|
|
||
| type RenderHookResult<T = unknown> = { | ||
| result: { current: T }; | ||
| }; | ||
|
|
||
| // Generic renderHook signature used by our tests: accepts a callback returning | ||
| // a value and returns an object with a `result.current` property. | ||
| let renderHook: <T = unknown>(cb: () => T) => RenderHookResult<T>; | ||
| let actImpl: ActFn | undefined; | ||
|
|
||
| type RTLLike = { | ||
| renderHook?: <T = unknown>(cb: () => T) => RenderHookResult<T>; | ||
| act?: ActFn; | ||
| }; | ||
|
|
||
| if (typeof (rtl as unknown as RTLLike).renderHook === "function") { | ||
| const r = rtl as unknown as Required<RTLLike>; | ||
| renderHook = r.renderHook; | ||
| actImpl = r.act; | ||
| } else { | ||
| const h = rhtl as unknown as Required<RTLLike>; | ||
| renderHook = h.renderHook; | ||
| actImpl = h.act; | ||
| } | ||
|
|
||
| const act: ActFn = (cb: () => void) => { | ||
| if (actImpl) return actImpl(cb); | ||
| // Fallback synchronous runner for environments without `act`. | ||
| return cb(); | ||
| }; | ||
|
|
||
| export { renderHook, act }; | ||
| export default renderHook; |
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.
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.
This is a temporary solution.
CI failed for the React 19 matrix because hook tests used
@testing-library/react-hooks, which internally callsReactDOM.render— a function removed in React 19. This causedTypeError: ReactDOM.render is not a functionin tests.Once /learn is upgraded to React 19. I'll update the library to drop support for older React versions and remove this test util.