Skip to content

fix(BottomSheetModal): don't fire onDismiss when sheet was never presented#2704

Open
olivier-bouillet wants to merge 1 commit into
gorhom:masterfrom
olivier-bouillet:fix/ondismiss-fires-when-never-presented
Open

fix(BottomSheetModal): don't fire onDismiss when sheet was never presented#2704
olivier-bouillet wants to merge 1 commit into
gorhom:masterfrom
olivier-bouillet:fix/ondismiss-fires-when-never-presented

Conversation

@olivier-bouillet

Copy link
Copy Markdown

Motivation

BottomSheetModal's unmount() fires the user-provided onDismiss callback unconditionally, even when the modal was never presented. Calling ref.current?.dismiss() on a modal that was never present()-ed therefore triggers a phantom onDismiss.

The function already computes hadReactMount and uses it to gate the React unmount (setState), but onDismiss is fired without the same guard — which is inconsistent, since onDismiss means "a presented sheet was dismissed".

This breaks consumers that run side effects in onDismiss (e.g. navigation.goBack()): a phantom dismiss on a permanently-mounted, never-presented modal navigates the user away. Reproducible on react-native@0.85 / the new architecture.

Fixes #2703.

Change

Gate the callback on the already-computed hadReactMount, mirroring the setState guard:

if (hadReactMount && _providedOnDismiss) {
  _providedOnDismiss();
}

One-line behavioral change; onDismiss now only fires for a sheet that was actually presented.

Verification

In an app that permanently mounts a BottomSheetModal and calls dismiss() from an effect when it should be hidden, onDismiss no longer fires unless the sheet was presented first. Normal present → dismiss flows are unaffected (hadReactMount is true once presented).

…ented

`unmount()` fired the user-provided `onDismiss` callback unconditionally, even
when the modal was never presented. Calling `dismiss()` on a never-presented
(e.g. permanently-mounted) modal therefore fired a phantom `onDismiss`.

`hadReactMount` is already computed and used to gate the React unmount
(`setState`); extend the same guard to the callback so `onDismiss` only fires
for a sheet that was actually presented.

Closes gorhom#2703
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.

BottomSheetModal fires onDismiss when dismiss() is called on a sheet that was never presented

1 participant