next.js
7296aa62 - Update prefetching.mdx providing more clarity on the usage of `router.prefetch()` (#84903)

Commit
275 days ago
Update prefetching.mdx providing more clarity on the usage of `router.prefetch()` (#84903) ## What Updated `prefetching.mdx` in the App Router documentation providing more clarity on the usage of `router.prefetch()`. ## Why We found the current section on `Manual Prefetching` to be lacking in detail and a bit misleading as well. The issue with the current version of the documentation is that the code snippet provided: ```tsx const router = useRouter(); router.prefetch(); ``` Makes it seem like `router.prefetch()` can be called at the same level as `useRouter()`, i.e. in the component body, even though that causes the page to crash for many possible reasons, such as `window is not defined`, or `Router action dispatched before initialization.`. I am not sure if this is helpful/correct or not, just thought this may help someone. If not feel free to close this PR. Thanks in advance for your time. ## Reproduction Here is a codesandbox reproducing the issue that occurs if you follow the code snippet trivially: https://codesandbox.io/p/devbox/s5pmsj <!-- 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. (Done) - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide (Done) Closes NEXT- Fixes # --> --------- Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Parents
Loading