Unverified Commit b95f0129 authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

test: fix next-form tests when running on react 18 (#70704)

Fixes some broken tests from #68333. They were skipped, but still crash
in `start` mode, because they try to use `useActionState` and crash
during prerendering (because 18 doesn't have that). We turn those pages
into noops instead -- the tests that use them are skipped anyway.
parent 772b0ea2
'use client'
import * as React from 'react'
import { useActionState, useState } from 'react'
import Form from 'next/form'
import { useRouter } from 'next/router'
export default function Page() {
const isReact18 = typeof React.useActionState !== 'function'
export default isReact18 ? DummyPage : Page
function DummyPage() {
return <>This test cannot run in React 18</>
}
function Page() {
const destination = '/pages-dir/redirected-from-action'
const router = useRouter()
const [, dispatch] = useActionState(() => {
const [, dispatch] = React.useActionState(() => {
const to = destination + '?' + new URLSearchParams({ query })
router.push(to)
}, undefined)
const [query, setQuery] = useState('')
const [query, setQuery] = React.useState('')
return (
<Form action={dispatch} id="search-form">
<input
......
'use client'
import * as React from 'react'
import { type ComponentProps, useActionState, useState } from 'react'
import Form from 'next/form'
import { useRouter } from 'next/router'
export default function Page() {
const isReact18 = typeof React.useActionState !== 'function'
export default isReact18 ? DummyPage : Page
function DummyPage() {
return <>This test cannot run in React 18</>
}
function Page() {
const destination = '/pages-dir/redirected-from-action'
const [query, setQuery] = useState('')
const [query, setQuery] = React.useState('')
return (
<Form action="/pages-dir/search" id="search-form">
<input
......@@ -25,9 +32,9 @@ export default function Page() {
function NavigateButton({
to,
...props
}: { to: string } & ComponentProps<'button'>) {
}: { to: string } & React.ComponentProps<'button'>) {
const router = useRouter()
const [, dispatch] = useActionState(() => {
const [, dispatch] = React.useActionState(() => {
router.push(to)
}, undefined)
return <button type="submit" formAction={dispatch} {...props} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment