From 580e750ba2c9a57483d95bcc8678a4cb368f6866 Mon Sep 17 00:00:00 2001 From: Valentin Hervieu Date: Tue, 8 Nov 2022 11:22:57 +0100 Subject: [PATCH 1/4] Update next/link default legacyBehavior --- packages/next/client/link.tsx | 2 +- .../test/index.test.js | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/integration/link-with-multiple-child/test/index.test.js diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 22fe09d5a0d6..b02ef72613c4 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -378,7 +378,7 @@ const Link = React.forwardRef( onClick, onMouseEnter: onMouseEnterProp, onTouchStart: onTouchStartProp, - legacyBehavior = Boolean(process.env.__NEXT_NEW_LINK_BEHAVIOR) !== true, + legacyBehavior = 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() +}) From e8b806be82bc4827fadd7a923a547894fd10fe58 Mon Sep 17 00:00:00 2001 From: Valentin Hervieu Date: Wed, 9 Nov 2022 04:27:00 +0100 Subject: [PATCH 2/4] Update existing unit test --- test/unit/link-rendering.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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( From f455f0b6c19f95947baff74c8f8b966626f1390e Mon Sep 17 00:00:00 2001 From: Valentin Hervieu Date: Fri, 18 Nov 2022 03:55:41 +0100 Subject: [PATCH 3/4] Add __NEXT_NEW_LINK_BEHAVIOR back but reversed --- packages/next/client/link.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 87344a09a2d2..65f03a0f4742 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -375,7 +375,7 @@ const Link = React.forwardRef( onClick, onMouseEnter: onMouseEnterProp, onTouchStart: onTouchStartProp, - legacyBehavior = false, + legacyBehavior = process.env.__NEXT_NEW_LINK_BEHAVIOR === false, ...restProps } = props From 5d985f033871bc39d796f5be2ef3b8131f39aabc Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 30 Nov 2022 19:30:50 -0800 Subject: [PATCH 4/4] Fix type error --- packages/next/client/link.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index ead8b422a88f..80d34bc9b0dd 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -375,6 +375,7 @@ const Link = React.forwardRef( onClick, onMouseEnter: onMouseEnterProp, onTouchStart: onTouchStartProp, + // @ts-expect-error this is inlined as a literal boolean not a string legacyBehavior = process.env.__NEXT_NEW_LINK_BEHAVIOR === false, ...restProps } = props