[LiveComponent] NoModificationAllowedError when closing error modal twice
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start in src/LiveComponent/assets/src/Component/index.ts and inspect closeModal, including the click and keydown listeners that invoke it. Reproduce the error-overlay close action with two rapid triggers, then verify the modal closes without a console error when the element is already detached.
Written by the indexing model from the issue text.
Description
Problem
When a LiveComponent request fails and the error overlay (#live-component-error) is displayed, closing it twice in quick succession throws an uncaught error:
NoModificationAllowedError: Failed to set the 'outerHTML' property on 'Element': This element has no parent node.
Expected: The modal closes cleanly regardless of how many times the close action is triggered.
Actual: The second close attempt throws because the element has already been removed from the DOM.
Steps to reproduce
- Set up a LiveComponent that triggers a server error (e.g., a 500 response)
- Wait for the full-screen error overlay to appear
- Either double-click the overlay quickly, or click it while pressing Escape at the same time
- Observe NoModificationAllowedError in the browser console
Details
Version: 2.34.0
Browsers: All
The closeModal function in https://github.com/symfony/ux/blob/2.x/src/LiveComponent/assets/src/Component/index.ts uses modal.outerHTML = '' to remove the element:
const closeModal = (modal: HTMLElement | null) => {
if (modal) {
modal.outerHTML = '';
}
document.body.style.overflow = 'visible';
};
Both the click and keydown listeners call this function with the same captured modal reference. After the first call removes the element from the DOM, the reference still passes the if (modal) check but setting outerHTML requires the element to have a parent node, so the second call throws.
Suggested fix
Replace modal.outerHTML = '' with modal.remove(), which is idempotent and safe to call on detached elements:
const closeModal = (modal: HTMLElement | null) => {
if (modal) {
modal.remove();
}
document.body.style.overflow = 'visible';
};
Happy to open a PR if this approach looks good.
- Dominant language
- PHP
- Stars
- 1.1k
- Forks
- 431
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 70
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from symfony/ux
-
Notify RFC
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Documentation Toolkit
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
LiveComponent
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
TwigComponent
Difficulty 4/5 3-5 days Newbie friendliness 58/100
-
RFC
Difficulty 5/5 Over a week Newbie friendliness 45/100
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·