Repository navigation
fix(frontmatter): preserve form values and allow a custom editor - #998
Conversation
petyosi
left a comment
There was a problem hiding this comment.
Thanks for taking on #19. The current form does lose data: main drops false, 0 and "" and turns dates into ISO timestamps. Keeping the original bytes on an unchanged save is good. But replacing the default frontmatter UI with a recursive typed editor is more than I want to maintain in the core package. I'd split this into two parts:
1. A small fix to the existing editor. Stop filtering falsy values, use CORE_SCHEMA so dates stay strings, and skip the write when nothing changed. That can merge quickly.
2. An extension point. Add frontmatterPlugin({ FrontmatterEditor }), stored in a cell and used by FrontmatterNode.decorate(), the same way imagePlugin({ ImageDialog }) works. The recursive editor can then ship as a separate package.
If parts of the current implementation stay, these need fixing:
- The raw fallback can store delimiters. js-yaml accepts a leading
---. If you save---\ntitle: fixedin the raw fallback, the delimiter is stored inside the node and export adds a second pair. On reload the frontmatter is empty andtitle: fixedlands in the document body. - The root type can be changed. If you switch the root type select to
stringand save, the output is---\n''\n---. The root should stay an object. frontmatterHistory.tswrites to@lexical/historyinternals. Core already manages that history insrc/plugins/core/lexicalExtensions.ts. If there is an undo bug, please fix it there, with a test that fails on main.- The new labels and error messages are not translated.
- Please drop the
table-image-dialog.spec.tshunk. That fixture is on main now.
Integrate current main without rewriting branch history. Restore the small default form, preserve falsy/date/unchanged values and row identity, expose the requested component cell, and remove recursive UI and local history manipulation.
|
Narrowed this in
Local checks passed: 25 focused tests, 265 full-suite tests (1 existing skip, 1 todo), lint, typecheck and build. Exact-head CI is green, including 141 browser tests across Chromium/Firefox/WebKit, packed React 18/19 consumers and cross-version Markdown replay. The PR description now reflects this smaller scope. |
|
Merged, thanks. This is the shape I was after: a small fix for the existing form plus the I added a follow-up commit (b017477) for a few cases the form still changed on save:
|
|
🎉 This PR is included in version 4.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Related to #19.
Narrowed implementation
false,0, empty strings, nulls and structured values when editing unrelated fields. Load/dump withCORE_SCHEMAso dates remain strings. Object/array values are retained but not edited through text inputs.frontmatterPlugin({ FrontmatterEditor }),frontmatterEditor$and exported component props. Existing nodes update when the option changes; omitting it restores the default. Components receive delimiter-freeyamlandonChange.Current main is integrated without rewriting branch history; the already-landed Firefox fixture has no feature diff. The former recursive implementation is preserved separately, not shipped as the default.
Verification
Head:
f9922bee2aa8784f9f13a1a3584a07c7866802b8. Published tree72758517d1d518187854edfbb0f70150fbe50030matches the tested local tree exactly.Exact-head CI run 40541095166 completed successfully: Test, Build JS, Build Docs and Browser compatibility. Browser coverage passed 141 tests (47 each on Chromium, Firefox and WebKit). Build JS also passed packed React 18/19 consumer checks and the cross-version Markdown replay.
Maintainer re-review remains pending; successful tests do not constitute acceptance or merge.