Skip to content

Support the @plone/plate document model (plate regions), and don't fail on blocks missing in blocks_layout - #99

Merged
robgietema merged 8 commits into
mainfrom
somersault-blocks
Nov 18, 2026
Merged

robgietema merged 8 commits into
mainfrom
somersault-blocks

Conversation

@sneridagh

@sneridagh sneridagh commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Aurora's shared acceptance suite against Nick (plone/aurora#370) fails 111 of 253 tests with a 500 on creating a page. Aurora's default editor is built on @plone/plate, whose document model stores the page in Plate regions (the @kitconcept/volto-plate add-on for Volto uses the same model). Aurora's fixtures send the page with the default blocks_layout, which still lists the ids of a title and a slate block that aren't in blocks. Plone accepts that. Nick crashes while indexing:

TypeError: Cannot read properties of undefined (reading '@type')
  at Document.toMarkdown (src/models/document/document.ts:2405)
  ← getIndexFields ← Document.index ← routes/content/content.ts:1097

The first two commits are the fix. The third names the block after the @plone/plate document model and links the Plone Aurora docs on it from docs/developer-guide/blocks.md, and the fourth types the document model instead of using any. The last one moves to the storage shape agreed in plone/aurora#379.

Note

Updated to the agreed storage shape (plone/aurora#379). A region is an entry of blocks keyed by its name, whose @type is plate: main for the page body, and the slot name for slots, like aboveContent. This is what plone.restapi 10.3.0 supports (plone/plone.restapi#2092), what Aurora writes after plone/aurora#412, and what volto-plate writes after kitconcept/volto-plate#122. Content saved before, with one __somersault__ region, is still read, as the main region.

{ "blocks": { "main": { "@type": "plate", "value": [ ... ] }, "aboveContent": { "@type": "plate", "value": [ ... ] } } }

1. Skip blocks missing in blocks_layout instead of failing (bugfix)

  • toMarkdown read blocks[id]['@type'] for every id in blocks_layout.items, so a dangling id, or a layout without blocks, threw. The new Document.getLayoutBlocks() skips ids without a block and treats missing blocks or blocks_layout as empty.
  • getBodytext, getBlockTypes, handleBlocks, handleBlockReferences and @replace also skip null or invalid blocks, which crashed them in the same way.
  • I chose tolerance over a 400 because Plone accepts these documents: Volto and plone.restapi don't need the layout to match blocks either.

2. Support the @plone/plate document model: Plate regions (feature)

Without the crash, the block would fall back to _default: no Markdown and no searchable text for any @plone/plate document.

  • src/helpers/plate/plate.ts converts a Plate value to Markdown and plain text: marks, links, Plate's indent lists, title and headings, blockquote, hr, code blocks, tables, and nested columns, callouts and toggles.
  • src/blocks/plate/plate.ts registers the plate block with toMarkdown, searchableText, replace and process, and the same block for the deprecated __somersault__ type. isPlateRegion finds regions by @type, never by key, getMainRegion returns main or the legacy __somersault__ region, and getPlateRegions returns the main region first, then the slots. Volto blocks wrapped in ploneBlock nodes go to their own registered block, so html blocks inside a @plone/plate document are now sanitized, and their types are in block_types.
  • Blocks can define searchableText. The default returns '' and slate returns its plaintext, so search results for Volto pages don't change.
  • Once a page has a main region, it is the page: its blocks_layout and other blocks are not used for the Markdown and the searchable text. The Markdown is the main region only. The searchable text is the text of the main region followed by the text of the slot regions, as plone.restapi indexes every plate region. This follows the model as documented in The unified block editor, and stops pages migrated from Volto, which keep their legacy blocks next to it, from being indexed twice.
  • The document model is typed in src/helpers/plate/plate.ts: PlateText, PlateElement and PlateValue mirror TText, TElement and Value of platejs without depending on it, plus the documented nodes (links, indent list items, code blocks, ploneBlock) and PlateRegion, with SomersaultBlock as a deprecated alias. The helpers read stored values through a loose PlateNode, since clients send them unvalidated, and a ploneBlock without an @type is skipped.
  • Smaller fix: the replace signature of the default block now takes self first, which is how it is called.

Why a block and not a behavior

A behavior was the other option. Nick has no blocks_layout check to get past: the blocks behavior requires nothing, and the 500 came from indexing. A behavior would only fix the types that list it, so Folder, Event, News Item and custom types would keep crashing until each one was changed and upgraded. A Plate region is a block in blocks, so the block registry is where it belongs.

Validation

  • New tests in document.test.ts, src/helpers/plate/plate.test.ts, src/blocks/plate/plate.test.ts and content.test.ts. The content.test.ts one POSTs a main region with a stale layout, like Aurora's fixtures, and checks the 201, the Markdown, html sanitizing and @search?SearchableText=. The others also cover slot regions indexed after main, the legacy __somersault__ region read as main, and regions found by @type.
  • Copied onto main, the new regression tests fail with the TypeError above. On this branch they pass.
  • Full suite locally, on PostgreSQL 14, after the move to regions: 649 passed, 2 failed. The two failures, should fold accents in query.test.ts and should collect more statistics in catalog.test.ts, fail the same way on main, most likely because of PostgreSQL 14 versus CI's 18.
  • tsc --noEmit, ESLint and Prettier are clean.

Not verified yet, so draft

  • PostgreSQL 18 (CI will run it).
  • Aurora's acceptance suite against a Nick image built from this branch.
  • Real content saved from the Aurora editor: the Plate conversion was checked against the node shapes in Aurora's packages/plate docs.

Left out

  • Teaser hrefs inside a Plate region don't get image scales in handleBlockReferences yet.
  • An existing bug: @replace writes its result to value for every block, so for html blocks it sets value instead of html.

See plone/aurora#379 for how to review and merge this PR together with the related ones.

Assisted-by: Claude Opus 5.5

Content whose blocks_layout lists ids that are not in blocks, or which
has no blocks, failed with a 500 when it was indexed (toMarkdown), and
invalid blocks broke the bodytext, the block types, the processing of
blocks, the block references and @replace. Missing and invalid blocks
are skipped now, like Plone does.

Assisted-by: Claude Opus 5.5
Plone Aurora stores the whole page in one __somersault__ block whose
value is a Plate document. Register a block for it which converts the
document to Markdown, gives its text to SearchableText, replaces text
for @replace and processes the blocks wrapped in ploneBlock nodes by
their type, so html blocks inside it are sanitized. Its wrapped block
types are added to block_types. When a page has this block, its
blocks_layout and other blocks are not used for the Markdown and the
searchable text, as documented by Plone Aurora.

Blocks get a searchableText method for this; the slate block returns
its plaintext, so the searchable text of Volto pages doesn't change.

Assisted-by: Claude Opus 5.5
@sneridagh
sneridagh requested a review from robgietema November 5, 2026 01:47
Plone Aurora's default editor is one consumer of the @plone/plate document
model; @kitconcept/volto-plate is another. Link the Plone Aurora docs on
the unified block editor.

Assisted-by: Claude Opus 5.5
@sneridagh sneridagh changed the title Support Plone Aurora's __somersault__ block, and don't fail on blocks missing in blocks_layout Support the @plone/plate document model (__somersault__ block), and don't fail on blocks missing in blocks_layout Nov 5, 2026
Add types that mirror TText, TElement and Value of platejs and the nodes
documented in @plone/plate: marks, links, indent list items, code blocks,
ploneBlock elements and the __somersault__ block. The helpers still read
stored values through a loose PlateNode, since clients send them
unvalidated, and wrapped blocks without an @type are now skipped.

Assisted-by: Claude Opus 5.5
@sneridagh
sneridagh marked this pull request as ready for review November 5, 2026 13:30
…k into somersault-blocks

* 'somersault-blocks' of github.com:plone/nick:

* 'main' of github.com:plone/nick:
  Make the i18n script deterministic and keep translations.

# Conflicts:
#	CHANGELOG.md
#	locales/nick.pot
* 'main' of github.com:plone/nick:
  Update the mail control panel example for the Microsoft 365 settings.
  Add the strings of the Microsoft 365 mail settings to the locales.
  Add a Microsoft 365 (OAuth) mail transport.

# Conflicts:
#	CHANGELOG.md
#	locales/nick.pot

@davisagli davisagli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: needs to be updated to match the new format with main region of type plate plone/plone.restapi#2092

The page body is the main region, and slots use their slot name.
Regions are found by their @type, plate. The legacy __somersault__
region is read as the main region, and is deprecated.

Assisted-by: Claude Opus 5.5
@sneridagh sneridagh changed the title Support the @plone/plate document model (__somersault__ block), and don't fail on blocks missing in blocks_layout Support the @plone/plate document model (plate regions), and don't fail on blocks missing in blocks_layout Nov 17, 2026
@sneridagh

Copy link
Copy Markdown
Member Author

@davisagli I updated it to the latest shape in the other PRs.

@sneridagh

Copy link
Copy Markdown
Member Author

@robgietema everything is ready on the Aurora side for this PR. plone/aurora#412 (the page body in the main region, with "@type": "plate") and plone/aurora#367 (the plone.plate document model in @blocks-schema) are merged, and the next Aurora release will include them. This PR is now only waiting for your blessing.

The releases have to happen in sync, because of the current Mack deployments, in this order:

  1. Merge this PR and release Nick.
  2. Release Aurora.

Aurora with plone/aurora#412 saves every page it edits as the main region, with "@type": "plate". A Nick release without this PR only knows the __somersault__ block, so it would miss those pages: their Markdown, their SearchableText, and their block types. This PR still reads the old __somersault__ block as main, so Nick can be released first without affecting pages that Aurora hasn't saved again yet.

The full merge plan is in plone/aurora#379.

Assisted-by: Claude Opus 5.5

@robgietema
robgietema merged commit a8835cb into main Nov 18, 2026
10 checks passed
@robgietema
robgietema deleted the somersault-blocks branch November 18, 2026 16:02
@sneridagh

Copy link
Copy Markdown
Member Author

🎉

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.

3 participants