Skip to content

Support data-* attributes in DOM JSX - #933

Open
anmonteiro wants to merge 6 commits into
mainfrom
anmonteiro/proposal-data-attrs
Open

anmonteiro wants to merge 6 commits into
mainfrom
anmonteiro/proposal-data-attrs

Conversation

@anmonteiro

@anmonteiro anmonteiro commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Support arbitrary string-valued data attributes in DOM JSX, including optional attributes. Extends the coverage merged in #934 and #935 to exercise JSX support. 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?

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.
@anmonteiro
anmonteiro force-pushed the anmonteiro/proposal-data-attrs branch from d133e9a to b1fc8ff Compare November 3, 2026 07:32
@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!

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.
@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

This branch has not been deployed

No deployments
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