Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/LiveComponent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.35

- Allow Symfony UX 3.x packages
- Fix `NoModificationAllowedError` thrown when closing the server-error modal twice in quick succession

## 2.33

Expand Down
7 changes: 4 additions & 3 deletions src/LiveComponent/assets/src/Component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,10 @@ export default class Component {
}

const closeModal = (modal: HTMLElement | null) => {
if (modal) {
modal.outerHTML = '';
}
// Element.remove() is idempotent: safe to call again after the
// first close detached the modal from the DOM (unlike assigning
// to outerHTML, which throws on a parent-less element).
modal?.remove();
document.body.style.overflow = 'visible';
};

Expand Down
27 changes: 27 additions & 0 deletions src/LiveComponent/assets/test/unit/controller/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ describe('LiveController Error Handling', () => {
expect(test.element).toHaveTextContent('Original component text');
});

it('closing the error modal twice does not throw', async () => {
const test = await createTest(
{},
(data: any) => `
<div ${initComponent(data)}>
<button data-action="live#action" data-live-action-param="save">Save</button>
</div>
`
);

test.expectsAjaxCall()
.serverWillReturnCustomResponse(500, '<html><body><h1>Boom</h1></body></html>')
.expectActionCalled('save');

getByText(test.element, 'Save').click();

await waitFor(() => expect(getErrorElement()).not.toBeNull());

const modal = getErrorElement() as HTMLElement;
modal.click();
// Second close (e.g. a quick double-click or a simultaneous Escape) must not throw
// even though the element is already detached from the DOM after the first close.
expect(() => modal.click()).not.toThrow();

expect(getErrorElement()).toBeNull();
});

it('triggers response:error hook', async () => {
const test = await createTest(
{},
Expand Down
Loading