Skip to content

fix: memory leak in embedded Snack - #697

Open
SimonSiefke wants to merge 1 commit into
expo:mainfrom
SimonSiefke:fix/memory-leak-embedded-snack
Open

fix: memory leak in embedded Snack#697
SimonSiefke wants to merge 1 commit into
expo:mainfrom
SimonSiefke:fix/memory-leak-embedded-snack

Conversation

@SimonSiefke

Copy link
Copy Markdown

Details

Inline embedded Snacks register a global message callback that captures their iframe while waiting for expoFrameLoaded. When a host removes the container during client-side navigation, the callback stays registered and keeps the detached iframe reachable.

Change

Track pending callbacks per iframe, unregister them after the handshake or explicit removal, and observe host-driven DOM removal so abandoned embeds are cleaned up. Register the callback before insertion to avoid missing a synchronous load message.

Before

When navigating between the React Native Introduction and Core Components pages 37 times, the embedded Snack message callback grows by 74:

before

After

No more matching embedded Snack message callback growth is detected.

after

Test Video

react-native-docs-core-components.webm

@SimonSiefke
SimonSiefke requested a review from byCedric as a code owner August 4, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant