Skip to content

Move legacy Slate normalization to a paste boundary#155

Open
sneridagh wants to merge 2 commits into
mainfrom
legacy-paste-boundary-normalizer
Open

Move legacy Slate normalization to a paste boundary#155
sneridagh wants to merge 2 commits into
mainfrom
legacy-paste-boundary-normalizer

Conversation

@sneridagh

@sneridagh sneridagh commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

At some point, we moved all the normalization and block migration logic to run in the server exclusively. There was some leftovers in the form of PlatePlugins that run in runtime. This is a PR for cleanup. The only use case where they are required are in the "paste" from a slate block (in edit mode) since it's application-slate and it catches it and should be able to run the legacy migrations in this case too.

Legacy Slate → Plate normalization is now a server concern: the Aurora request middleware (middleware.server.tsmigrateContent) assembles the unified Somersault value and runs every legacy migration before the content reaches the client. That made the per-concern runtime plugins (LegacyBoldPlugin, LegacyItalicPlugin, LegacyStrikethroughPlugin, LegacyListPlugin, LegacyLinkPlugin) redundant — they re-ran migrations on already-normalized data on every edit.

This PR removes those always-on normalizeNode / normalizeInitialValue plugins from the kits and replaces them with a single paste-boundary normalizer.

The one case the server cannot cover is a legacy Slate fragment pasted straight out of a legacy volto-slate editor (the clipboard carries raw legacy nodes under application/x-slate-fragment, which Slate inserts verbatim). This was verified empirically: with the runtime plugins gone, a plain Plate editor left pasted legacy nodes unnormalized, while Aurora (which had the plugins) did not. The new LegacyPastePlugin handles exactly this — once, at the boundary — instead of running five normalizers on every keystroke.

What changed

New — LegacyPastePlugin (legacy-paste-plugin.ts)

  • Overrides insertFragment (same pattern as suggestion-core.ts) and runs the static migrations once on the incoming fragment via normalizeLegacyFragment(editor, fragment).
  • Order mirrors normalizeLegacyValue: bold → italic → strikethrough → links → lists. The link step is editor-aware, so it resolves the configured link type.
  • Idempotent → a no-op on native Plate fragments, including the common external-HTML paste path (Plate deserializes that to clean nodes before insertFragment).
  • Registered in the editor kits only (EditorKit, BlockEditorKit); renderers never paste.

Removed the runtime legacy plugins from the kits

  • basic-marks-kit / basic-marks-base-kit, list-kit / list-base-kit, link-kit / link-base-kit, and cmsui's link-kit.
  • Deduped config/presets/full.ts, which registered LegacyLinkPlugin twice (explicitly and via EditorKitLinkKit).
  • The Legacy*Plugin objects are still exported from their modules (not deleted), so a host such as @kitconcept/volto-plate can opt back into runtime normalization if needed. The static migrate*InValue helpers and the server pipeline are untouched.

Story fix — the LegacyLink Storybook story fed legacy data straight to the editor/renderer, which no longer self-normalize; it now pre-migrates with normalizeLegacyValue, mirroring what the server hands over.

DocsslateToPlate.md updated to document the paste boundary and the exported-but-unregistered plugins.

Tests

  • Unitlegacy-paste-plugin.test.ts: normalizeLegacyFragment (marks + links + lists, idempotency, no input mutation) and the insertFragment override.
  • Acceptancelegacy-paste.test.ts: pastes a real legacy volto-slate fragment (application/x-slate-fragment carrying strong, link.data.url, ul/li) via the editor's own insertData (the genuine clipboard-decode → insertFragment path), and asserts it renders as <a href>, bold, and list content — and that no legacy types survive in the editor value.

Results

Check Result
@plone/plate unit tests 60 passed (incl. new paste tests)
@plone/plate + @plone/cmsui typecheck clean
Aurora server-migration tests 2 passed
cmsui acceptance suite 30 passed

Notes

  • Behavior change for the renderer: base kits no longer normalize legacy nodes. This is safe because server-delivered content is already migrated; anything rendered directly (e.g. a story) must pre-migrate with normalizeLegacyValue.
  • The insertFragment override is typed with any to match Plate's generic transform signature, consistent with suggestion-core.ts.

Replace the always-on legacy Slate → Plate `normalizeNode` plugins with a
single `insertFragment` boundary normalizer (`LegacyPastePlugin`), and remove
the per-concern runtime plugins from the editor and renderer kits. Server-
delivered content is already migrated by the Aurora middleware, so the only
client-side normalization still needed is for legacy fragments pasted straight
out of a legacy volto-slate editor.

- Add LegacyPastePlugin + normalizeLegacyFragment (editor kits only)
- Remove Legacy{Bold,Italic,Strikethrough,List,Link}Plugin from the kits
  (the plugin objects stay exported for potential host reuse)
- Dedupe LegacyLinkPlugin double-registration in the full preset
- Pre-migrate the LegacyLink story via normalizeLegacyValue
- Add unit + acceptance tests and refresh slateToPlate.md
@sneridagh
sneridagh requested a review from pnicolli July 22, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants