Skip to content

Commit d6bff60

Browse files
committed
reintroduce 17 and 16.8
1 parent faa74f4 commit d6bff60

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
"peerDependencies": {
9494
"@jest/globals": "*",
9595
"expect": "*",
96-
"react": "^18.0.0 || >=19.0.0-rc",
97-
"react-dom": "^18.0.0 || >=19.0.0-rc"
96+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc",
97+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc"
9898
},
9999
"scripts": {
100100
"build": "tsup",

‎src/renderStream/__tests__/passiveEffects.test.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('passive effects', () => {
4040
const received: number[] = []
4141
const stream = createRenderStream<{value: number}>()
4242
let update: React.Dispatch<React.SetStateAction<number>>
43-
let parentRenders = 0
43+
let parentCommits = 0
4444
function Subscriber() {
4545
const [value, setValue] = React.useState(0)
4646
update = setValue
@@ -55,7 +55,9 @@ describe('passive effects', () => {
5555
return null
5656
}
5757
function Parent() {
58-
parentRenders++
58+
React.useLayoutEffect(() => {
59+
parentCommits++
60+
})
5961
return <Subscriber />
6062
}
6163

@@ -67,7 +69,7 @@ describe('passive effects', () => {
6769

6870
expect(render.snapshot).toEqual({value: 1})
6971
expect(received).toEqual([1])
70-
expect(parentRenders).toBe(1)
72+
expect(parentCommits).toBe(1)
7173
},
7274
)
7375

‎src/renderStream/createRenderStream.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ export function createRenderStream<
242242
})
243243
} finally {
244244
pendingCommits.set(`${id}:${commitTime}`, stream.renders.length)
245+
if (/^(16|17)\./.test(React.version)) {
246+
// React 16/17 have no onPostCommit hook. Let the commit finish scheduling
247+
// passive effects before yielding a task for them to run.
248+
void Promise.resolve().then(() => {
249+
setTimeout(() => profilerOnPostCommit(id, phase, 0, commitTime), 0)
250+
})
251+
}
245252
}
246253
}
247254

‎src/renderWithoutAct.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as ReactDOMClient from 'react-dom/client'
2+
import * as ReactDOM from 'react-dom'
23
import {type RenderOptions} from '@testing-library/react/pure.js'
34
import {
45
BoundFunction,
@@ -156,7 +157,11 @@ async function _renderWithoutAct(
156157
let root: ReturnType<typeof createConcurrentRoot>
157158
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first.
158159
if (!mountedContainers.has(container)) {
159-
root = createConcurrentRoot(container)
160+
root = (
161+
ReactDOM.version.startsWith('16') || ReactDOM.version.startsWith('17')
162+
? createLegacyRoot
163+
: createConcurrentRoot
164+
)(container)
160165
mountedRootEntries.push({container, root})
161166
// we'll add it to the mounted containers regardless of whether it's actually
162167
// added to document.body so the cleanup method works regardless of whether
@@ -182,6 +187,22 @@ async function _renderWithoutAct(
182187
})
183188
}
184189

190+
function createLegacyRoot(container: ReactDOMClient.Container) {
191+
// These runtime APIs are absent from React 19's types.
192+
const legacyReactDOM = ReactDOM as unknown as {
193+
render(element: React.ReactNode, container: ReactDOMClient.Container): void
194+
unmountComponentAtNode(container: ReactDOMClient.Container): boolean
195+
}
196+
return {
197+
render(element: React.ReactNode) {
198+
legacyReactDOM.render(element, container)
199+
},
200+
unmount() {
201+
legacyReactDOM.unmountComponentAtNode(container)
202+
},
203+
}
204+
}
205+
185206
function createConcurrentRoot(container: ReactDOMClient.Container) {
186207
const anyThis = globalThis as any as {IS_REACT_ACT_ENVIRONMENT?: boolean}
187208
if (anyThis.IS_REACT_ACT_ENVIRONMENT) {

‎yarn.lock‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,8 +2644,8 @@ __metadata:
26442644
peerDependencies:
26452645
"@jest/globals": "*"
26462646
expect: "*"
2647-
react: ^18.0.0 || >=19.0.0-rc
2648-
react-dom: ^18.0.0 || >=19.0.0-rc
2647+
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc
2648+
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc
26492649
languageName: unknown
26502650
linkType: soft
26512651

0 commit comments

Comments
 (0)