You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Save and Activate" saves but does not activate in Safari (button detected via document.activeElement) #606
Environment: Code Snippets 4.0.0, WordPress 7.1.3, Safari on macOS.
What happens: on the Add New and Edit Snippet screens, clicking Save and Activate saves the code but leaves the snippet inactive. After the page reloads we have to switch it on with the Active toggle. The same thing makes Save and Deactivate leave a snippet active.
Likely cause: the form's submit handler works out which button was pressed from the focused element, in js/components/EditMenu/SnippetForm/SnippetForm.tsx (handleSubmit):
In Safari (and Firefox on macOS), clicking a button does not give it focus, so focus stays in the code editor, no action matches, and the request goes out as a plain save with "active": false (useSubmitSnippet.tsx only sets active for SAVE_AND_ACTIVATE). In Chrome the click focuses the button, so it works there. The REST endpoint itself honours active correctly.
To reproduce in Chrome: cancel the button's mousedown (so focus stays in the editor), then click Save and Activate: the POST to /wp-json/code-snippets/v1/snippets carries "active": false and the snippet is saved inactive.
Suggested fix: read the form's submitter instead of the focused element, e.g.
Activity