Skip to content

[LiveComponent] Fix NoModificationAllowedError when closing the error modal twice#3501

Open
Amoifr wants to merge 1 commit intosymfony:2.xfrom
Amoifr:fix_ux_3496
Open

[LiveComponent] Fix NoModificationAllowedError when closing the error modal twice#3501
Amoifr wants to merge 1 commit intosymfony:2.xfrom
Amoifr:fix_ux_3496

Conversation

@Amoifr
Copy link
Copy Markdown
Contributor

@Amoifr Amoifr commented Apr 24, 2026

Q A
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #3496
License MIT

Summary

When the server-error overlay is closed twice in quick succession (double-click, or a click + Escape within the same tick), the second close throws:

NoModificationAllowedError: Failed to set the 'outerHTML' property on 'Element': This element has no parent node.

The root cause (nicely identified by @maarten-mymmo in #3496) is that both close listeners call closeModal(modal) with the same captured reference: the first call detaches the element via modal.outerHTML = '', and the second call then hits the DOM spec rule that outerHTML can't be set on a parent-less element.

Fix

Swap modal.outerHTML = '' for Element.remove(), which is idempotent and safe on detached elements. Same observable effect (element gone), one less footgun.

Test plan

  • 4/4 tests in src/LiveComponent/assets/test/unit/controller/error.test.ts pass (3 existing + 1 new).
  • New regression test closing the error modal twice does not throw documents the invariant.
  • ℹ️ Note on the test: jsdom doesn't enforce the real-browser NoModificationAllowedError on outerHTML for detached elements, so the test can't actively catch a regression to outerHTML. It still guards the "close-twice → clean state, no throw" contract and serves as living documentation.

… modal twice

Assigning to `outerHTML` throws `NoModificationAllowedError` when the
element has no parent, which happens when the server-error overlay is
closed twice in quick succession (e.g. a double click, or a click +
Escape within the same tick).

Switch to `Element.remove()`, which is idempotent and safe to call on
a detached element. Adds a regression test that documents the
close-twice invariant.

Fixes symfony#3496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants