diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 6da55598e464..80d34bc9b0dd 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -375,7 +375,8 @@ const Link = React.forwardRef( onClick, onMouseEnter: onMouseEnterProp, 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 } = props diff --git a/test/integration/link-with-multiple-child/test/index.test.js b/test/integration/link-with-multiple-child/test/index.test.js new file mode 100644 index 000000000000..a1434ee113af --- /dev/null +++ b/test/integration/link-with-multiple-child/test/index.test.js @@ -0,0 +1,30 @@ +/** + * @jest-environment jsdom + */ +import { render, screen } from '@testing-library/react' +import Link from 'next/link' + +test('single child', () => { + render(Hello world) + expect(screen.getByRole('link')).not.toBeNull() +}) + +test('multiple child with default legacyBehavior', () => { + render( + + Hello world + ! + + ) + expect(screen.getByRole('link')).not.toBeNull() +}) + +test('multiple child with forced legacyBehavior=false', () => { + render( + + Hello world + ! + + ) + expect(screen.getByRole('link')).not.toBeNull() +}) diff --git a/test/unit/link-rendering.test.ts b/test/unit/link-rendering.test.ts index 7b79b5ebc90e..0af74027480a 100644 --- a/test/unit/link-rendering.test.ts +++ b/test/unit/link-rendering.test.ts @@ -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(