Skip to content

Commit cce82cd

Browse files
authoredApr 22, 2021
Fix side effects in router-is-ready tests (#24360)
Fixes the [failing react@experimental tests](https://github.com/vercel/next.js/actions/workflows/test_react_experimental.yml).
1 parent 1e9f459 commit cce82cd

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed
 

‎test/integration/router-is-ready/pages/auto-export/[slug].js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useRouter } from 'next/router'
2+
import { useLayoutEffect } from 'react'
23

34
export default function Page(props) {
45
const router = useRouter()
56

67
if (typeof window !== 'undefined') {
7-
if (!window.isReadyValues) {
8-
window.isReadyValues = []
9-
}
10-
window.isReadyValues.push(router.isReady)
8+
// eslint-disable-next-line react-hooks/rules-of-hooks
9+
useLayoutEffect(() => {
10+
if (!window.isReadyValues) {
11+
window.isReadyValues = []
12+
}
13+
window.isReadyValues.push(router.isReady)
14+
}, [router])
1115
}
1216

1317
return (

‎test/integration/router-is-ready/pages/auto-export/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useRouter } from 'next/router'
2+
import { useLayoutEffect } from 'react'
23

34
export default function Page(props) {
45
const router = useRouter()
56

67
if (typeof window !== 'undefined') {
7-
if (!window.isReadyValues) {
8-
window.isReadyValues = []
9-
}
10-
window.isReadyValues.push(router.isReady)
8+
// eslint-disable-next-line react-hooks/rules-of-hooks
9+
useLayoutEffect(() => {
10+
if (!window.isReadyValues) {
11+
window.isReadyValues = []
12+
}
13+
window.isReadyValues.push(router.isReady)
14+
}, [router])
1115
}
1216

1317
return (

‎test/integration/router-is-ready/pages/gip.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useRouter } from 'next/router'
2+
import { useLayoutEffect } from 'react'
23

34
export default function Page(props) {
45
const router = useRouter()
56

67
if (typeof window !== 'undefined') {
7-
if (!window.isReadyValues) {
8-
window.isReadyValues = []
9-
}
10-
window.isReadyValues.push(router.isReady)
8+
// eslint-disable-next-line react-hooks/rules-of-hooks
9+
useLayoutEffect(() => {
10+
if (!window.isReadyValues) {
11+
window.isReadyValues = []
12+
}
13+
window.isReadyValues.push(router.isReady)
14+
}, [router])
1115
}
1216

1317
return (

‎test/integration/router-is-ready/pages/gsp.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useRouter } from 'next/router'
2+
import { useLayoutEffect } from 'react'
23

34
export default function Page(props) {
45
const router = useRouter()
56

67
if (typeof window !== 'undefined') {
7-
if (!window.isReadyValues) {
8-
window.isReadyValues = []
9-
}
10-
window.isReadyValues.push(router.isReady)
8+
// eslint-disable-next-line react-hooks/rules-of-hooks
9+
useLayoutEffect(() => {
10+
if (!window.isReadyValues) {
11+
window.isReadyValues = []
12+
}
13+
window.isReadyValues.push(router.isReady)
14+
}, [router])
1115
}
1216

1317
return (

‎test/integration/router-is-ready/pages/gssp.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useRouter } from 'next/router'
2+
import { useLayoutEffect } from 'react'
23

34
export default function Page(props) {
45
const router = useRouter()
56

67
if (typeof window !== 'undefined') {
7-
if (!window.isReadyValues) {
8-
window.isReadyValues = []
9-
}
10-
window.isReadyValues.push(router.isReady)
8+
// eslint-disable-next-line react-hooks/rules-of-hooks
9+
useLayoutEffect(() => {
10+
if (!window.isReadyValues) {
11+
window.isReadyValues = []
12+
}
13+
window.isReadyValues.push(router.isReady)
14+
}, [router])
1115
}
1216

1317
return (

0 commit comments

Comments
 (0)
Please sign in to comment.