fix: render link/action values to the shape exporters expect#15
Merged
Conversation
Button.href, Image.action, Menu items, Video.href and Timer.action all
rendered with href="" (or no anchor at all) regardless of the shape the
caller passed. The schema stores links as `{ name, values: { href, target } }`
but exporters read `e.url`, so the value never reached the rendered HTML.
The editor avoids this by running the link property-editor's `renderValue()`
between storage and exporter; React-elements skipped that step.
Add `normalizeLinkValue` (string / `{ url }` / `{ name, values }` -> render
shape) and `normalizeValuesForExporter` which walks known link-bearing
paths (top-level `href`/`action`, `menu.items[].link`). Call it from
`createItemComponent` between `mergeValues` and the exporter handoff. The
`renderToJson` path uses the propMapper directly and is untouched, so JSON
output still round-trips into the editor with the storage shape intact.
Also extend the existing string shorthand in `mapSemanticProps` to cover
`action` (was only `href`), so a string `<Image action="..." />` is wrapped
to the same storage shape before merge.
Tests:
- 11 new unit tests for the helpers in semantic-props.test.ts
- 4 regression tests in Button.test.tsx (string / storage / values escape
hatch / email mode)
- 3 regression tests in Image.test.tsx (string / storage / email mode)
- snapshots regenerated; only diff is `target="_blank"` now correctly
emitted on default-href anchors, matching what the editor produces
Verified end-to-end: 275 unit tests pass, packed tarball smoke tests
pass, live Next.js RSC dev server returns correct hrefs.
omerzahidbajwa
approved these changes
May 8, 2026
There was a problem hiding this comment.
Pull request overview
Fixes React renderer output so link-bearing fields (e.g., Button.href, Image.action, Menu item links) are handed to exporters in the render-value shape they actually read ({ url, target, ... }), instead of the editor/schema storage shape ({ name, values: { href, target } }), preventing href="" / missing anchors in rendered HTML.
Changes:
- Extend
mapSemanticPropsstring shorthand wrapping to cover bothhrefandaction(wrapping into the schema storage shape). - Add
normalizeLinkValue+normalizeValuesForExporterhelpers in shared utils and call normalization increateItemComponentbefore invoking exporters. - Add/adjust regression tests and regenerate snapshots to reflect correct anchor attributes and Menu link rendering.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/utils/semantic-props.ts | Adds link normalization helpers and extends mapper shorthand wrapping. |
| packages/shared/src/utils/semantic-props.test.ts | Adds unit tests for new normalization helpers and updated mapper expectations. |
| packages/shared/src/index.ts | Re-exports the new normalization helpers from the shared package. |
| packages/react/src/utils/create-component.tsx | Normalizes values before passing them to exporters during React render. |
| packages/react/src/components/Image.test.tsx | Adds regression tests to ensure action renders to an <a href="...">. |
| packages/react/src/components/Button.test.tsx | Adds regression tests to ensure href reaches rendered <a href="..."> across shapes/modes. |
| packages/react/src/components/snapshots/snapshots.test.tsx.snap | Snapshot updates for correct link target emission. |
| packages/react/src/snapshots/golden-template.test.tsx.snap | Snapshot updates showing Menu items now render as anchors with correct href/target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+240
to
+246
| // Storage shape from the schema: { name, values: { href, target } }. | ||
| if ("name" in v && v.values && typeof v.values === "object") { | ||
| const inner = v.values as Record<string, any>; | ||
| return { | ||
| url: inner.href ?? "", | ||
| target: inner.target ?? "_blank", | ||
| ...(v.attrs ?? {}), |
Comment on lines
+273
to
+286
| it("resolves storage shape ({name, values: {href, target}}) to render shape", () => { | ||
| expect( | ||
| normalizeLinkValue({ | ||
| name: "web", | ||
| values: { href: "https://example.com", target: "_blank" }, | ||
| }) | ||
| ).toEqual({ url: "https://example.com", target: "_blank" }); | ||
| }); | ||
|
|
||
| it("defaults missing target to '_blank'", () => { | ||
| expect( | ||
| normalizeLinkValue({ name: "email", values: { href: "mailto:a@b.com" } }) | ||
| ).toEqual({ url: "mailto:a@b.com", target: "_blank" }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Button.href, Image.action, Menu items, Video.href and Timer.action all rendered with href="" (or no anchor at all) regardless of the shape the caller passed. The schema stores links as
{ name, values: { href, target } }but exporters reade.url, so the value never reached the rendered HTML. The editor avoids this by running the link property-editor'srenderValue()between storage and exporter; React-elements skipped that step.Add
normalizeLinkValue(string /{ url }/{ name, values }-> render shape) andnormalizeValuesForExporterwhich walks known link-bearing paths (top-levelhref/action,menu.items[].link). Call it fromcreateItemComponentbetweenmergeValuesand the exporter handoff. TherenderToJsonpath uses the propMapper directly and is untouched, so JSON output still round-trips into the editor with the storage shape intact.Also extend the existing string shorthand in
mapSemanticPropsto coveraction(was onlyhref), so a string<Image action="..." />is wrapped to the same storage shape before merge.Tests:
target="_blank"now correctly emitted on default-href anchors, matching what the editor producesVerified end-to-end: 275 unit tests pass, packed tarball smoke tests pass, live Next.js RSC dev server returns correct hrefs.
Summary
What does this PR do? Keep it brief.
Changes
Test Plan
pnpm buildpassespnpm testpassesNotes
Any additional context for reviewers.
📖 Storybook Preview: https://unlayer.github.io/elements/pr/15/