fix(block-editor): preserve hard breaks on load for restricted fields - #36600
Conversation
Add `hardBreak` to the always-allowed `basicNodes` map so `purifyNodeTree`/`removeInvalidNodes` no longer strips Shift+Enter line breaks when Block Editor content is re-opened for editing on a field configured with allowed-block restrictions (allowedBlocks.length > 1). Also fixes the latent `paragrah` -> `paragraph` typo so the paragraph basic-node fallback works as intended. Adds parser.utils regression coverage. Closes #35985
|
Meticulous was unable to execute a test run for this PR because the most recent commit is associated with multiple PRs. To execute a test run, please try pushing up a new commit that is only associated with this PR. Last updated for commit |
|
Claude finished @oidacra's task in 3m 7s —— View job Claude finished @oidacra's task in 1m 3s —— View job Code Review
I reviewed the diff. This is a correct, well-scoped fix. New IssuesNo issues found. Notes
Optional (non-blocking): the recursion in LGTM. ✅ |
…ading/array paths Address code review on #35985 fix: - Reference NodeTypes.PARAGRAPH/TEXT/DOC/HARD_BREAK instead of string literals in basicNodes (prevents the typo class that caused the bug). - Add parser.utils tests for the isHeading composite-key branch and the bare-array input branch of removeInvalidNodes.
|
Tick the box to add this pull request to the merge queue (same as
|
Summary
The legacy Block Editor silently stripped
hardBreak(Shift+Enter) nodes when re-opening content for editing on fields configured with allowed-block restrictions.setEditorJSONContentruns loaded JSON throughremoveInvalidNodes→purifyNodeTree, which drops any node whose type isn't in the allowed map.hardBreakwas never in the map, so every line break was lost on load — causing silent formatting/data loss on the next save.This adds
hardBreakto the always-allowedbasicNodesmap and fixes the latentparagrah→paragraphtypo in the same map (the paragraph basic-node fallback was previously dead code).Only affects fields with
allowedBlocks.length > 1; unrestricted fields never entered the filtering path. The new Block Editor (@dotcms/new-block-editor) does not filter on load and was never affected.Closes #35985
Acceptance Criteria
hardBreaktreated as an always-allowed basic node sopurifyNodeTree/removeInvalidNodesnever strips itparagrah→paragraphtypo fixedhardBreaksurvivesremoveInvalidNodeson a restricted editorTest Plan
pnpm nx test block-editor --testPathPatterns=parser.utils— 8 tests pass (parser.utils.ts at 97% coverage)Changed Files
core-web/libs/block-editor/src/lib/shared/utils/parser.utils.tscore-web/libs/block-editor/src/lib/shared/utils/parser.utils.spec.ts(new)This PR fixes: #35985