Skip to content

fix(#168): use hast property names for mapped component props - #183

Merged
BearToCode merged 1 commit into
BearToCode:masterfrom
itsmunzir:fix/component-data-attributes
Oct 1, 2026
Merged

BearToCode merged 1 commit into
BearToCode:masterfrom
itsmunzir:fix/component-data-attributes

Conversation

@itsmunzir

Copy link
Copy Markdown
Contributor

Closes #168

Problem

Attributes of a matched element are passed to the mapped component with their raw DOM attribute names on the client (data-item-id), but with their hast property names on the server (dataItemId). A component like:

<script>
  let { dataItemId } = $props();
</script>

receives the value during SSR, but undefined after initializeComponents runs on the client — so data-* attributes are effectively unreachable.

Fix

initializeComponents now maps placeholder attributes through property-information, so client-side props use the same names as the server (data-item-id → dataItemId, class → className, aria-label → ariaLabel, …). data-component is still excluded. Also documented the prop naming in the component plugin docs.

Verification

The repo has no test suite, so I verified with a scripted repro (jsdom + a compiled Svelte component) running against the built package:

  • Before: CSR captured {"data-item-id":"12345"} vs SSR {"dataItemId":"12345"}
  • After: CSR captured {"dataItemId":"12345","className":"a b","ariaLabel":"label","href":"/x"} (matches SSR)

Checks: pnpm run lint ✅ · pnpm run check ✅ (0 errors/0 warnings) · pnpm run build ✅ (all packages + docs).

@BearToCode

Copy link
Copy Markdown
Owner

Thanks for your contribution ♥️

@BearToCode
BearToCode merged commit 3310d24 into BearToCode:master Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version @cartamd/plugin-component-v1.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-component and node attributes

2 participants