Skip to content

Conversation

@matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Sep 11, 2025

This PR continues the work from #1991, fixing parsing of textColor and backgroundColor props. To do this, the attributes representing these props have been moved in the underlying ProseMirror schema from blockContainer nodes to blockContent nodes (e.g. paragraphs and headings). The reasoning for this can also be found in #1991.

Because the ProseMirror has changed, existing collaborative documents lose any textColor and backgroundColor props that were set, as the ProseMirror editor attempts to read the attributes from a different node to where they actually are. Therefore, the SchemaMigrationPlugin has been added, which updates existing collaborative documents to the new schema. This plugin runs whenever a collaborative document is initially loaded and traverses it. When it finds content that doesn't align with the editor schema, it can dispatch transactions to correct any issues caused by the mismatch between the document & editor schemas. Each correction is a separate piece of code that targets a specific change in the schema, and is called a MigrationRule. Currently, there is just one MigrationRule, which moves the textColor and backgroundColor attributes as described above. Thanks to the MigrationRule design, it should be fairly easy to deal with any additional ProseMirror schema changes that we might have to make in the future.

Besides these major changes, there are also a few minor ones:

  • List item HTML export has been slightly changed, so that we can actually put the color styles on the li elements rather than their children.
  • Color styles no longer export a CSS variable and then read it, the color is just set directly to the value we'd previously assign to the variable.

@vercel
Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
blocknote Error Error Sep 12, 2025 0:48am
blocknote-website Ready Ready Preview Sep 12, 2025 0:48am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 11, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@1998

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@1998

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@1998

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@1998

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@1998

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@1998

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@1998

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@1998

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@1998

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@1998

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@1998

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@1998

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@1998

commit: 2b7a83b

Comment on lines +8 to +14
// This plugin allows us to update collaboration YDocs whenever BlockNote's
// underlying ProseMirror schema changes. The plugin reads the current Yjs
// fragment and dispatches additional transactions to the ProseMirror state, in
// case things are found in the fragment that don't adhere to the editor schema
// and need to be fixed. These fixes are defined as `MigrationRule`s within the
// `migrationRules` directory.
export class SchemaMigrationPlugin extends BlockNoteExtension {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this handles the case where the attributes were stored in Y.js, what about if the user was using json or HTML as their storage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With JSON we don't need to change anything as the props field abstracts away having the prop attributes on blockContainer vs blockContent nodes.

With HTML, existing documents will indeed lose textColor/backgroundColor props when they get parsed under the new schema. However, we do explicitly state in the docs that you should use JSON for storing documents to the backend, and in general the use case of having HTML for document storage is not officially supported. So I don't think this is worth implementing. If it turns out there's demand for this then we can implement it. Unlike with the Yjs document migration, with HTML it can just be a simple function to transform the HTML string.

The more relevant HTML use case though is for static rendering, as we want old documents to still be displayed correctly with the new schema. Fortunately, the CSS changes in this PR are backwards compatible with the old schema, so this should be fine.

Copy link
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

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

I think it is fine to scope out the html migration

@matthewlipski matthewlipski merged commit f629634 into parse-export-fixes Sep 12, 2025
11 of 12 checks passed
@matthewlipski matthewlipski deleted the parse-export-fixes-breaking branch September 12, 2025 15:53
matthewlipski added a commit that referenced this pull request Sep 12, 2025
* WIP parse export fixes

* Fixed color style parsing

* Made default props get exported to inline styles in external HTML

* Small fix

* Updated snapshots

* Updated snapshot

* Updated e2e snaps

* Fixed snapshot???

* fix: External HTML parse/export cases cont. (#1998)

* Added plugin for collab schema migration

* Moved color props to block content nodes

* Fixed export for list items and updated unit test snapshots

* Rename

* Updated test snapshots

* Implemented PR feedback

* Fixed build
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