fix: Unmounting actions dispatches close-modal when modal is already closed #14200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This addresses the issue described in #10581.
The modal's close() function already closes the current modal and it also dispatches the
modal-closed
event, which when caught will cause the action's unmount function to be called. This function, however, does not take this into account and will always dispatch theclose-modal
event again.This PR introduces a new variable
$shouldDispatchCloseModal
for the actions' unmount function, which when set tofalse
will prevent theclose-modal
event from being dispatched again. Since this variable has a default value oftrue
it should not break any other uses of the functions.Visual changes
Improved UX when rapidly closing and reopening modals on complex pages or when the user has a slower connection.
Actions
Delete button
Before: https://demo.filamentphp.com/shop/orders/1/edit
After: https://demo.filament.thenines.be/shop/orders/1/edit
Table actions
Edit button
Before: https://demo.filamentphp.com/blog/categories
After: https://demo.filament.thenines.be/blog/categories
Form actions
Reset button
Before: https://demo.filamentphp.com/shop/orders/1/edit
After: https://demo.filament.thenines.be/shop/orders/1/edit
Infolist Actions
Author's suffix action
Before: not present in the demo
After: https://demo.filament.thenines.be/blog/posts/1
Functional changes
composer cs
command.