Skip to content

[CRAFTING] fix(rich-text-web): keep text color, font family and size in class style mode - #2454

Closed
samuelreichert wants to merge 1 commit into
mainfrom
fix/rich-text-class-mode-reload
Closed

samuelreichert wants to merge 1 commit into
mainfrom
fix/rich-text-class-mode-reload

Conversation

@samuelreichert

@samuelreichert samuelreichert commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

With Style data format = Class (strict CSP mode), text color, font family and font size were lost when saved content was loaded again. This is data loss for every app using class mode.

Root cause: in class mode these marks are saved as <span data-text-color|data-font-family|data-font-size class="has-…"> with no style attribute. Tiptap's TextStyle mark only parses a <span> that has a style attribute (@tiptap/extension-text-style), so these spans were dropped on load.

Fix: a new TextStyleClass extends TextStyle. In class mode it adds one parse rule for spans that carry these data attributes. Inline mode keeps the original rules unchanged, and highlight and alignment were already unaffected. The extensions' value sanitising is untouched.

The change was written test-first: the new regression test failed before the fix. Lint and the full package test suite pass, and there is a CHANGELOG entry under [Unreleased].

Note: Font size is stored without its unit in class mode (18, not 18px); that is existing behaviour and unchanged here.

Based on main (rebased after #2453 was merged).

What should be covered while testing?

  1. Set Style data format to Class.
  2. Apply a text color, a font family and a font size, then save.
  3. Reload the page. The formatting is still there, and the saved HTML still has no inline style.
  4. Repeat with Inline to confirm nothing changed.

🤖 Generated with Claude Code

@samuelreichert
samuelreichert requested a review from a team as a code owner October 6, 2026 13:55
@github-actions

This comment has been minimized.

@samuelreichert
samuelreichert force-pushed the test/rich-text-unit-coverage branch from be0a685 to a153c39 Compare October 12, 2026 09:11
Base automatically changed from test/rich-text-unit-coverage to main October 12, 2026 11:20
…yle mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@samuelreichert
samuelreichert force-pushed the fix/rich-text-class-mode-reload branch from b593a76 to 79913aa Compare October 12, 2026 12:58
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

✅ Approved — no issues found


What was reviewed

File Change
packages/pluggableWidgets/rich-text-web/CHANGELOG.md Unreleased entry for the bug fix
packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx Swap TextStyle for TextStyleClass
packages/pluggableWidgets/rich-text-web/src/extensions/TextStyleClass.ts New extension: adds class-mode parse rule
packages/pluggableWidgets/rich-text-web/src/extensions/__tests__/classFormat.spec.ts New regression tests for round-trip and parse

Skipped (out of scope): dist/, pnpm-lock.yaml

CI checks could not be fetched automatically (permission denied), but the PR description states lint and the full package test suite pass.


Positives

  • Test-first approach — the PR description explicitly states the regression test was written before the fix; both the load-form and round-trip cases are covered for all three affected marks (color, family, size).
  • consuming: false is set correctly, which allows the per-mark extensions (TextColorClass, FontFamilyClass, FontSize) to run their own parse rules on the same node — no silent data loss on load.
  • getAttrs guard (element.hasAttribute("style") ? false : {}) correctly defers to the existing TextStyle rule for spans that already carry inline style, avoiding double-application.
  • Mode isolation — the extra parse rule is gated on styleDataFormat === "class" so inline-mode behaviour is entirely unchanged; the dedicated inline-format test confirms this.
  • No TextStyle import leakage — the old direct TextStyle import is removed from both Editor.tsx and the spec; TextStyleClass re-exports everything needed.
  • CHANGELOG entry present under [Unreleased] in Keep a Changelog format; version bump correctly deferred to a release PR.

@samuelreichert

Copy link
Copy Markdown
Contributor Author

Superseded by #2495, which combines this fix with the other Rich Text fixes on top of the latest main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant