Skip to content

Commit

Permalink
Fix side effects in router-is-ready tests (#24360)
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll authored Apr 22, 2021
1 parent 1e9f459 commit cce82cd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
12 changes: 8 additions & 4 deletions test/integration/router-is-ready/pages/auto-export/[slug].js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useRouter } from 'next/router'
import { useLayoutEffect } from 'react'

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

if (typeof window !== 'undefined') {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
}, [router])
}

return (
Expand Down
12 changes: 8 additions & 4 deletions test/integration/router-is-ready/pages/auto-export/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useRouter } from 'next/router'
import { useLayoutEffect } from 'react'

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

if (typeof window !== 'undefined') {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
}, [router])
}

return (
Expand Down
12 changes: 8 additions & 4 deletions test/integration/router-is-ready/pages/gip.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useRouter } from 'next/router'
import { useLayoutEffect } from 'react'

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

if (typeof window !== 'undefined') {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
}, [router])
}

return (
Expand Down
12 changes: 8 additions & 4 deletions test/integration/router-is-ready/pages/gsp.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useRouter } from 'next/router'
import { useLayoutEffect } from 'react'

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

if (typeof window !== 'undefined') {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
}, [router])
}

return (
Expand Down
12 changes: 8 additions & 4 deletions test/integration/router-is-ready/pages/gssp.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useRouter } from 'next/router'
import { useLayoutEffect } from 'react'

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

if (typeof window !== 'undefined') {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
if (!window.isReadyValues) {
window.isReadyValues = []
}
window.isReadyValues.push(router.isReady)
}, [router])
}

return (
Expand Down

0 comments on commit cce82cd

Please sign in to comment.