Skip to content

fix: memory leak in Link due to IntersectionObserver - #12326

Merged
slorber merged 1 commit into
facebook:mainfrom
SimonSiefke:agent/fix-link-intersection-observer-leak
Aug 21, 2026
Merged

fix: memory leak in Link due to IntersectionObserver#12326
slorber merged 1 commit into
facebook:mainfrom
SimonSiefke:agent/fix-link-intersection-observer-leak

Conversation

@SimonSiefke

@SimonSiefke SimonSiefke commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Details

Docusaurus Link created a new callback ref on every render. React detached the old ref with null, but that path did not disconnect its IntersectionObserver, so the document's observer controller retained the old callback closure.

Change

Keep the callback ref stable while its inputs are unchanged, and disconnect and clear the active observer whenever the ref target changes or unmounts.

Before

When navigating between Playwright's Installation and Writing tests pages 37 times, the observer callback, innerRef, and interaction callback each grow by 3,922 instances:

before

After

No more matching Link observer leak is detected.

Test Video

test-video.webm

Additional Info

  • PR is AI-generated
  • Model: Codex (GPT-5.6)
  • Worktime: 46 minutes, 38 seconds

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jul 29, 2026
@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 038e216
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a6a68ffb505fe00085c64e2
😎 Deploy Preview https://deploy-preview-12326--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber slorber changed the title fix: memory leak in Link fix: memory leak in Link due to IntersectionObserver Aug 21, 2026

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

I could confirm with Chrome devtools memory heap snapshots that IntersectionObserver is leaking in prod, and not in this deploy preview PR. The prefetching behavior on viewport enter keeps working as before.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Aug 21, 2026
@slorber
slorber merged commit 3525a81 into facebook:main Aug 21, 2026
36 of 38 checks passed
@SimonSiefke
SimonSiefke deleted the agent/fix-link-intersection-observer-leak branch August 21, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants