Skip to content

fix(modal): restore React mount state reset in unmount() after #2632#2664

Merged
gorhom merged 1 commit into
gorhom:masterfrom
huextrat:fix/modal-unmount-reset-react-mount-state
Apr 30, 2026
Merged

fix(modal): restore React mount state reset in unmount() after #2632#2664
gorhom merged 1 commit into
gorhom:masterfrom
huextrat:fix/modal-unmount-reset-react-mount-state

Conversation

@huextrat
Copy link
Copy Markdown
Contributor

Summary

Fixes a regression introduced in v5.2.11 with #2632 (modal status refactor): after dismissing a BottomSheetModal, React state could keep mount: true, so a later present() (e.g. from useFocusEffect when navigating) would hit the fast path and call snapToIndex(index)—closed sheets appeared to reopen.

Root cause

In v5.2.10, unmount() saved whether the portal was mounted before resetVariables():

const _mounted = mounted.current; // mirrored `mount` each render
resetVariables();
// ...
if (_mounted) {
  setState(INITIAL_STATE);
}

In v5.2.11, the equivalent branch checked statusRef after resetVariables(), which always sets statusRef to INITIAL. The guard therefore never matched and setState(INITIAL_STATE) was skipped.

The condition also only considered PRESENTED and ANIMATING, while a completed dismiss ends as DISMISSED—so it would be wrong even if evaluated before reset.

Fix

Mirror mount into mountRef on every render (same pattern as mounted.current = mount in v5.2.10). In unmount(), read hadReactMount = mountRef.current before resetVariables(), then call setState(INITIAL_STATE) when hadReactMount is true.

Testing

  • yarn lint (biome) on ./src passes.
  • yarn typescript still reports existing errors in other files on this branch (unchanged by this PR).

Checklist

  • Minimal, targeted change
  • Maintainer may want a repro example or regression test for modal + navigation

Made with Cursor

unmount() must call setState(INITIAL_STATE) when the portal was
mounted. v5.2.11 checked statusRef after resetVariables(), which
always left status INITIAL, so the condition never matched and
mount stayed true—later present() could snap the sheet open again.

Made-with: Cursor
@huextrat huextrat marked this pull request as ready for review April 30, 2026 06:19
@dorupopacaliman
Copy link
Copy Markdown

I can confirm 5.2.11 made my entire app unusable, this needs to be fixed asap

@gorhom gorhom self-requested a review April 30, 2026 08:46
@gorhom gorhom self-assigned this Apr 30, 2026
@gorhom gorhom merged commit 03a215c into gorhom:master Apr 30, 2026
1 check failed
@gorhom
Copy link
Copy Markdown
Owner

gorhom commented Apr 30, 2026

thanks @huextrat for submitting this PR, tested it and going to publish a new release shortly

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.

3 participants