Skip to content

Conversation

DipakHalkude
Copy link

  • Change fragment links from tags to NextLink components in MDX/Link.tsx
  • Set history.scrollRestoration = 'auto' for all browsers in _app.tsx
  • This prevents multiple new pages in backStack and maintains scroll position
  • Similar to how Wikipedia handles fragment links

- Change fragment links from <a> tags to NextLink components in MDX/Link.tsx
- Set history.scrollRestoration = 'auto' for all browsers in _app.tsx
- This prevents multiple new pages in backStack and maintains scroll position
- Similar to how Wikipedia handles fragment links
@meta-cla meta-cla bot added the CLA Signed label Sep 25, 2025
@DipakHalkude
Copy link
Author

This PR fixes the browser "back" button issue when clicking on fragment links (links that start with # ) in the React documentation.

Problem: When users clicked on fragment links like Link and then used the browser's back button, the page would not return to the previous scroll position.

Solution:

  • Updated src/components/MDX/Link.tsx : Changed fragment links from tags to components to use Next.js's client-side routing
  • Updated src/pages/_app.tsx : Set history.scrollRestoration = 'auto' for all browsers (not just Safari) to enable proper scroll position restoration

Copy link

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 110.5 KB (🟢 -44 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 128.09 KB (-3 B) 238.58 KB
/500 128.1 KB (-3 B) 238.59 KB
/[[...markdownPath]] 130.46 KB (-3 B) 240.95 KB
/errors 128.34 KB (-3 B) 238.84 KB
/errors/[errorCode] 128.32 KB (-3 B) 238.81 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant