Skip to content

Let React commit into its containers while a plugin mount is pending - #5837

Merged
ymichael merged 1 commit into
get-bb:mainfrom
zom-2018:fix/dom-guard-react-containers
Oct 20, 2026
Merged

ymichael merged 1 commit into
get-bb:mainfrom
zom-2018:fix/dom-guard-react-containers

Conversation

@zom-2018

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

runWithPluginDomIsolationAsync keeps isolationDepth > 0 until a content-script mount promise settles. Keeping it across await is intended and tested, but it also covers bb's own React commits that run in that window. refusePluginReparent allows a fresh React-owned node (parentNode === null) only when the new parent has a React fiber. React's root container and portal containers have no fiber; React marks them with __reactContainer$… / _reactListening… instead. So while any plugin's async mount is pending, React's insert of bb's <div data-bb-plugin-app-overlays> into #root is refused, and no plugin's app overlays reach the page. Repro and evidence: #5836.

What changed

apps/app/src/lib/foreign-dom-mutation-guard.ts: when a fresh React-owned node is inserted, a React root or portal container now counts as a React parent, the same way a fiber-backed element already did. Moves of attached React nodes to a new parent are still refused during isolation, and isolation across await is unchanged.

This deviates from the direction suggested in #5836 (drop isolation across await), because the existing test "keeps isolation across await and event listeners" pins that behavior as intended.

One trade-off: a plugin that first detaches a React-owned node and then inserts it directly into a React container (for example document.body once it hosts a portal) is no longer refused. Moving a node out of its current React parent is still refused.

No wire, CLI, or plugin API changes.

How you verified

  • New test in foreign-dom-mutation-guard.test.tsx: while an async isolation is pending, React commits a child into its root container and into a portal container. Without the fix it fails (expected null to be an instance of HTMLDivElement); with the fix it passes, with zero refusals and no warning.
  • pnpm exec vitest run --config vitest.config.ts src/lib/foreign-dom-mutation-guard.test.tsx src/lib/plugin-frontend-reload.test.ts: 52 passed
  • pnpm exec turbo run typecheck --filter=@bb/app: passes
  • oxfmt / oxlint on the two files: clean
  • Not run: the full app test suite, or a live build of this branch. The live repro in Pending async content-script mount makes the DOM guard refuse bb's own React commits (plugin overlay container never mounts) #5836 was on bb 0.46.2-nightly.39288295552.1.

Fixes #5836

AGENT GENERATED

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @zom-2018 for the PR. This repo approves new contributors before it reviews their PRs, so this PR now closes on its own. That is expected. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to this PR, and explain what it changes and why. A maintainer then adds you to the allow list and can reopen the PR.

@github-actions github-actions Bot closed this Oct 20, 2026
@ymichael

Copy link
Copy Markdown
Collaborator

/approve @zom-2018

@github-actions

Copy link
Copy Markdown
Contributor

Approved @zom-2018 for PRs. The name now stays on the allow list. The author can open a PR now.

@ymichael ymichael reopened this Oct 20, 2026
@ymichael
ymichael merged commit 8f68a64 into get-bb:main Oct 20, 2026
27 checks passed
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.

Pending async content-script mount makes the DOM guard refuse bb's own React commits (plugin overlay container never mounts)

2 participants