Skip to content

Commit 509c790

Browse files
timneutkensijjk
andauthored
Remove legacy next/link prefetch={true} warning (#68326)
## What? Removes the warning shown in Pages Router when you use the `prefetch` prop on `next/link`. In App Router using `prefetch={true}` opts in to full page prefetching even when the route is dynamically rendered. When you're working on an application that uses both pages router and app router where the components are shared using `<Link prefetch>` would then cause this warning in Pages Router but not in App Router. With this change there won't be a warning in Pages Router. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> --------- Co-authored-by: JJ Kasper <[email protected]>
1 parent af267a2 commit 509c790

File tree

2 files changed

+0
-48
lines changed

2 files changed

+0
-48
lines changed

packages/next/src/client/link.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,6 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
433433
const _: never = key
434434
}
435435
})
436-
437-
// This hook is in a conditional but that is ok because `process.env.NODE_ENV` never changes
438-
// eslint-disable-next-line react-hooks/rules-of-hooks
439-
const hasWarned = React.useRef(false)
440-
if (props.prefetch && !hasWarned.current && !isAppRouter) {
441-
hasWarned.current = true
442-
console.warn(
443-
'Next.js auto-prefetches automatically based on viewport. The prefetch attribute is no longer needed. More: https://nextjs.org/docs/messages/prefetch-true-deprecated'
444-
)
445-
}
446436
}
447437

448438
if (process.env.NODE_ENV !== 'production') {

test/development/basic/misc.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,43 +79,5 @@ describe.each([[''], ['/docs']])(
7979
expect(text).toEqual(basePath + '/%2fexample.com')
8080
})
8181
})
82-
83-
async function getLogs$(path) {
84-
let foundLog = false
85-
let browser
86-
try {
87-
browser = await webdriver(next.url, path)
88-
const browserLogs = await browser.log()
89-
90-
browserLogs.forEach((log) => {
91-
if (log.message.includes('Next.js auto-prefetches automatically')) {
92-
foundLog = true
93-
}
94-
})
95-
} finally {
96-
if (browser) {
97-
await browser.close()
98-
}
99-
}
100-
return foundLog
101-
}
102-
describe('Development Logs', () => {
103-
it('should warn when prefetch is true', async () => {
104-
const foundLog = await getLogs$(basePath + '/development-logs')
105-
expect(foundLog).toBe(true)
106-
})
107-
it('should not warn when prefetch is false', async () => {
108-
const foundLog = await getLogs$(
109-
basePath + '/development-logs/link-with-prefetch-false'
110-
)
111-
expect(foundLog).toBe(false)
112-
})
113-
it('should not warn when prefetch is not specified', async () => {
114-
const foundLog = await getLogs$(
115-
basePath + '/development-logs/link-with-no-prefetch'
116-
)
117-
expect(foundLog).toBe(false)
118-
})
119-
})
12082
}
12183
)

0 commit comments

Comments
 (0)