[lexical] Deprecate CAN_UNDO_COMMAND and CAN_REDO_COMMAND in favour of HistoryExtension's signals - #8918
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
I think the better solution here is to simply deprecate CAN_UNDO_COMMAND and CAN_REDO_COMMAND because HistoryExtension has signals that are always correct. Even with this fix, there are still bootstrapping issues if you start observing the commands after the editor is initialized because there's no way to know the initial states.
|
Agreed, and I checked before replying: Happy to repoint this PR at the deprecation instead: |
|
Feel free to submit a PR with the deprecations and documentation, it's not a priority for me to personally create those kinds of PRs |
|
Done in c4dd9a9 — retitled and repointed at the deprecation.
I left the original 26/26 in |
etrepum
left a comment
There was a problem hiding this comment.
I don’t think it makes sense to add code or tests relevant to the deprecated path, everything from the initial commit can be dropped.
The react-like code example would be better off using the useExtensionSignalValue hook than a manual effect (which would have to be in a useEffect in that environment)
A command only reports a change, so a listener registered after the editor is initialized never sees the current value and has no way to read it. HistoryExtension's canUndo / canRedo signals are derived from the history stacks and always hold the current value. Point both commands at the signals and document the replacement in the @lexical/history README.
c4dd9a9 to
2668e99
Compare
|
Done. Rebuilt the branch on |
Description
Per the review:
CAN_UNDO_COMMANDandCAN_REDO_COMMANDare deprecated in favour ofHistoryExtension'scanUndo/canRedosignals.A command only reports a change. A listener registered after the editor is initialized never sees the current value and has no way to read it, so there is no correct way to bootstrap a toolbar button from these commands. The signals are derived from the history stacks by
syncFromHistoryStateand always hold the current value.@deprecatedJSDoc on both commands, pointing at the signals.@lexical/historyREADME: an "Undo/redo availability" section with a React example usinguseExtensionSignalValue, and a non-React one reading the signal viagetExtensionDependencyFromEditor.The commands are still dispatched, matching how
KEY_MODIFIER_COMMANDwas handled.Test plan
Docs and JSDoc only — nothing to test.
tsc --noEmitclean, prettier and eslint clean. No deprecation lint rule in the repo, andKEY_MODIFIER_COMMANDis still dispatched internally while deprecated, so no call sites needed changing.