Unverified Commit 30c96271 authored by Valentin Hervieu's avatar Valentin Hervieu Committed by GitHub

Update next/link default legacyBehavior (#42623)

## Bug
Fixes #42621

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 1bb05961
...@@ -375,7 +375,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>( ...@@ -375,7 +375,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
onClick, onClick,
onMouseEnter: onMouseEnterProp, onMouseEnter: onMouseEnterProp,
onTouchStart: onTouchStartProp, onTouchStart: onTouchStartProp,
legacyBehavior = Boolean(process.env.__NEXT_NEW_LINK_BEHAVIOR) !== true, // @ts-expect-error this is inlined as a literal boolean not a string
legacyBehavior = process.env.__NEXT_NEW_LINK_BEHAVIOR === false,
...restProps ...restProps
} = props } = props
......
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react'
import Link from 'next/link'
test('single child', () => {
render(<Link href="https://nextjs.org/blog/next-13">Hello world</Link>)
expect(screen.getByRole('link')).not.toBeNull()
})
test('multiple child with default legacyBehavior', () => {
render(
<Link href="https://nextjs.org/blog/next-13">
<span>Hello world</span>
<span>!</span>
</Link>
)
expect(screen.getByRole('link')).not.toBeNull()
})
test('multiple child with forced legacyBehavior=false', () => {
render(
<Link href="https://nextjs.org/blog/next-13" legacyBehavior={false}>
<span>Hello world</span>
<span>!</span>
</Link>
)
expect(screen.getByRole('link')).not.toBeNull()
})
...@@ -10,7 +10,7 @@ describe('Link rendering', () => { ...@@ -10,7 +10,7 @@ describe('Link rendering', () => {
{ {
href: '/my-path', href: '/my-path',
}, },
React.createElement('a', {}, 'to another page') 'to another page'
) )
const html = ReactDOM.renderToString(element) const html = ReactDOM.renderToString(element)
expect(html).toMatchInlineSnapshot( expect(html).toMatchInlineSnapshot(
......
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