Do not trigger unsaved changes alert for action modals that cannot contain unsaved changes - #20331
Open
grafst wants to merge 1 commit into
Open
Do not trigger unsaved changes alert for action modals that cannot contain unsaved changes#20331grafst wants to merge 1 commit into
grafst wants to merge 1 commit into
Conversation
…ntain unsaved changes The panel-level unsaved changes alert hooked `beforeunload` whenever any action was mounted, so read-only modals such as `ViewAction`'s warned about unsaved changes that cannot exist. Mounted actions now expose a `hasUnsavedChangesAlert` flag that the client-side guard checks, which defaults to `false` for actions with a disabled schema and can be controlled per action with `unsavedChangesAlert()`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
When
unsavedChangesAlerts()is enabled for a panel, thebeforeunloadguard for action modals fires whenever any action is mounted —setUpUnsavedActionChangesAlert()only checks$wire.mountedActions.length. A read-only modal such asViewAction's therefore triggers the browser's "unsaved changes" warning when the user closes the tab or navigates away, even though the modal contains no editable inputs and no unsaved state can exist. (Previously reported in #13766, which was closed for an invalid reproduction repository.)Reproduction: enable
->unsavedChangesAlerts()on a panel, open aViewActionmodal from a table, then close the browser tab — the browser warns that entered information may not be saved (e.g. Firefox: "This page is asking you to confirm that you want to leave — information you've entered may not be saved"), despite the modal being read-only.With this PR, each mounted action stamps a
hasUnsavedChangesAlertflag into itsmountedActionsentry, and the client-side guard only warns if at least one mounted action has the flag set:true(current behavior), unless the action's schema is disabled.ViewActioncallsdisabledSchema(), so its modals no longer trigger the alert — and neither do custom actions that usedisabledSchema().unsavedChangesAlert()method on actions allows opting in or out per action, e.g.->unsavedChangesAlert(false)for a read-only modal that renders an infolist without disabling its schema. It accepts a closure, consistent with the other modal configuration methods.Visual changes
None — the only change is that the native browser leave-confirmation dialog is no longer requested while a read-only action modal is open. The dialog itself is browser chrome and cannot be screenshotted meaningfully.
Functional changes
composer cscommand.New tests cover the default flag for editable schemas, disabled schemas, the
unsavedChangesAlert(false)opt-out, the closure/re-opt-in path, andViewActionmounting (tests/src/Actions/ActionTest.php,tests/src/Actions/ViewActionTest.php). The fulltests/src/Actionsandtests/src/Tables/Actionssuites plusRelationManagerTestpass, and PHPStan reports no errors on the changed files. Documentation was added topackages/actions/docs/02-modals.mdanddocs/05-panel-configuration.md.🤖 Generated with Claude Code