Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update next/link default legacyBehavior #42623

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
onClick,
onMouseEnter: onMouseEnterProp,
onTouchStart: onTouchStartProp,
legacyBehavior = Boolean(process.env.__NEXT_NEW_LINK_BEHAVIOR) !== true,
legacyBehavior = process.env.__NEXT_NEW_LINK_BEHAVIOR === false,
...restProps
} = props

Expand Down
30 changes: 30 additions & 0 deletions test/integration/link-with-multiple-child/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @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()
})
2 changes: 1 addition & 1 deletion test/unit/link-rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Link rendering', () => {
{
href: '/my-path',
},
React.createElement('a', {}, 'to another page')
'to another page'
)
const html = ReactDOM.renderToString(element)
expect(html).toMatchInlineSnapshot(
Expand Down