Skip to content

Support data-* attributes in DOM JSX - #933

Merged
anmonteiro merged 12 commits into
mainfrom
anmonteiro/proposal-data-attrs
Nov 16, 2026
Merged

anmonteiro merged 12 commits into
mainfrom
anmonteiro/proposal-data-attrs

Conversation

@anmonteiro

@anmonteiro anmonteiro commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Support string-valued data props in DOM JSX, including optional attributes. Match ml-in-barcelona/server-reason-react#420's name conversion and collision checks, with invalid-name diagnostics and preserved Merlin support. Extends #934, #935, and #946. Fixes #230; related to melange-re/melange#2004.

01a17001-efda-7320-8b10-3844e629533f

@davesnx

davesnx commented Sep 28, 2026

Copy link
Copy Markdown
Member

Note on digits: server-reason-react's ppx converts data attribute names differently when a digit follows a letter.

JSX name this PR server-reason-react
dataVersion2 data-version2 data-version-2

server-reason-react puts a dash before every character that is unchanged by Char.uppercase_ascii, and digits are unchanged, so each digit gets a dash. This PR puts a dash only before A–Z.

If one component is rendered on the server with server-reason-react and hydrated with reason-react, the attribute names will not match. We should agree on one rule. data-version2 looks like the better choice to me (it matches how dataset maps data-version2 to version2), so we can change server-reason-react to match this PR.

@anmonteiro
anmonteiro force-pushed the anmonteiro/proposal-data-attrs branch from 5d27b57 to 6f1ef6b Compare October 24, 2026 23:14
@anmonteiro anmonteiro changed the title proposal: support data-* attributes in DOM JSX Support data-* attributes in DOM JSX Oct 24, 2026
@anmonteiro
anmonteiro force-pushed the anmonteiro/proposal-data-attrs branch 3 times, most recently from 3d44983 to efa1f26 Compare November 1, 2026 19:40
@anmonteiro

Copy link
Copy Markdown
Member Author

@davesnx to confirm, does it make sense to change server-reason-react, or will that be a breaking change for folks who may be using it?

@davesnx

davesnx commented Nov 3, 2026

Copy link
Copy Markdown
Member

I prefer to keep the server-reason-react intact and update the logic here, there's no user of data-* aside from ahrefs afaik and this code is new.

@anmonteiro

Copy link
Copy Markdown
Member Author

@davesnx for sure, open to that!

I was just confirming what you had said above:

data-version2 looks like the better choice to me (it matches how dataset maps data-version2 to version2), so we can change server-reason-react to match this PR.

It sounds like we'll change this one to match instead!

@davesnx

davesnx commented Nov 4, 2026

Copy link
Copy Markdown
Member

The output of the attributes are often critical in some cases where a 3rd party integration asks for a specific name, and not being able to represent those are a big blocker.

I push a PR ml-in-barcelona/server-reason-react#412 to improve the output, maybe we can align? Sorry for the back and forth but I think it might be worth it

Use an erased DOM prop checker for typing and Merlin while emitting a single object constructor. Preserve identifier locations without duplicating complex expressions, restore the generated JavaScript snapshot, and cover nested JSX completion.
Hyphenate digits and underscores, and accept data-prefixed names while keeping standard data and datatype props on their existing DOM path. Update output snapshots, runtime coverage, and documentation.
@anmonteiro
anmonteiro force-pushed the anmonteiro/proposal-data-attrs branch from 19ab611 to 238b9b3 Compare November 9, 2026 14:01
@anmonteiro
anmonteiro merged commit 4a034a3 into main Nov 16, 2026
3 checks passed
@anmonteiro
anmonteiro deleted the anmonteiro/proposal-data-attrs branch November 16, 2026 04:51
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.

Allow data-* in DOM elements

2 participants