Skip to content

Fix React unrecognized-prop warning for style field data attributes - #175

Merged
sneridagh merged 1 commit into
mainfrom
fix-data-style-attr-casing
Sep 18, 2026
Merged

sneridagh merged 1 commit into
mainfrom
fix-data-style-attr-casing

Conversation

@sneridagh

Copy link
Copy Markdown
Member

Problem

The console showed:

React does not recognize the data-style-blockWidth prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase data-style-blockwidth instead.

Cause

toStyleFieldDataAttributes in packages/plate/components/editor/plugins/style-fields-plugin.ts built the attribute as data-style-${fieldName} using the raw field name. For blockWidth that yields data-style-blockWidth. React only forwards data-* attributes whose suffix is lowercase, so it dropped the attribute and warned.

Fix

Kebab-case the field name before building the attribute, so it becomes data-style-block-width — the idiomatic HTML data-attribute form, which also round-trips cleanly via dataset.styleBlockWidth.

  • Single-word fields (align, theme) are unchanged, so existing CSS selectors like [data-style-align='left'] keep working.
  • The acceptance tests read the --block-width CSS variable, not this attribute, so they are unaffected.
  • Updated the affected unit-test expectations in block-width-plugin.test.ts; all 26 tests pass.

Notes

Swept the repo for any consumer of the old camelCase form — none remained.

Style field data attributes were emitted with the raw (camelCase) field
name, producing e.g. data-style-blockWidth. React only forwards data-*
attributes whose suffix is lowercase, so it dropped the attribute and
warned in the console. Kebab-case the field name -> data-style-block-width.
Single-word fields (align, theme) are unchanged.
@sneridagh
sneridagh merged commit 95c42ac into main Sep 18, 2026
32 checks passed
@sneridagh
sneridagh deleted the fix-data-style-attr-casing branch September 18, 2026 14:49
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.

1 participant