Skip to content

fix(Android): guard against re-adding an attached fragment in ScreenStack.onUpdate#4157

Open
JacquesLeupin wants to merge 1 commit into
software-mansion:mainfrom
JacquesLeupin:fix/screenstack-fragment-already-added
Open

fix(Android): guard against re-adding an attached fragment in ScreenStack.onUpdate#4157
JacquesLeupin wants to merge 1 commit into
software-mansion:mainfrom
JacquesLeupin:fix/screenstack-fragment-already-added

Conversation

@JacquesLeupin

@JacquesLeupin JacquesLeupin commented Jun 11, 2026

Copy link
Copy Markdown

Description

Fixes an IllegalStateException: Fragment already added: ScreenStackFragment crash in ScreenStack.onUpdate.

When the top screen is translucent and visibleBottom's fragment is not added, the re-attach loop adds every wrapper from visibleBottom upward without checking whether it is already attached. If a fragment above visibleBottom is still attached — we hit this in production after background/resume cycles with a transparentModal on top and enableFreeze(true) — the add throws on commit.

Closes #4156.

Changes

  • Skip wrappers whose fragment is already added in the re-attach loop, mirroring the !newTop.fragment.isAdded guard in the sibling branch below.
  • Wrappers in dismissedWrappers are exempt from the skip: their removal is queued earlier in the same transaction, so remove + add is the existing (legal) re-attach path and behavior there is unchanged.

The guard only changes behavior in states that currently throw — for any wrapper that isn't attached, the transaction is identical to before.

Test plan

Checklist

  • Included code example that can be used to test this change.
  • Ensured that CI passes

…tack.onUpdate

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Crash on Android: "Fragment already added" in ScreenStack.onUpdate with transparentModal after background/resume

2 participants