Skip to content

renderToHtmlParts: expose granular css/js/tags - #38

Merged
ivoIturrieta merged 3 commits into
mainfrom
feat/granular-html-parts
Jul 4, 2026
Merged

renderToHtmlParts: expose granular css/js/tags#38
ivoIturrieta merged 3 commits into
mainfrom
feat/granular-html-parts

Conversation

@ivoIturrieta

@ivoIturrieta ivoIturrieta commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

What

Non-breaking addition: renderToHtmlParts now returns the granular pieces alongside the pre-assembled strings:

const { head, body, css, js, tags } = renderToHtmlParts(<Email>...</Email>);
// head/body — unchanged, exactly as before
// css  — raw component stylesheet (no <style> wrapper), e.g. for inlining pipelines
// js   — raw script content (empty for most email designs)
// tags — individual head tags contributed by components

Restores symmetry with the chunk mental model from editor exports for anyone composing their own document shell. Deliberately no fonts field: Elements has no font registry, and an always-empty array would misrepresent parity — callers pass font stylesheet URLs explicitly via renderToHtml's fonts option instead.

Tests

New test asserts the granular fields exist, css has no wrapper, and the assembled head is byte-exactly the granular pieces composed. Full suite 412 green.

🤖 Generated with Claude Code


📖 Storybook Preview: https://unlayer.github.io/elements/pr/38/

Non-breaking: head and body are unchanged; the pieces the assembled
head is built from are now also returned, for pipelines that need them
separately (CSS inlining, injecting into an existing style pipeline,
dropping scripts for email sends). No fonts field — Elements has no
font registry, and an always-empty array would misrepresent parity
with editor chunk exports.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 4, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the React package’s renderToHtmlParts API to expose granular head contributions (css, js, tags) alongside the existing assembled head/body strings, enabling downstream pipelines (e.g. CSS inlining) to consume the raw pieces directly while preserving the prior output.

Changes:

  • Extend the HtmlParts return shape to include css, js, and tags in addition to head and body.
  • Add a test asserting presence/shape of the new fields and that head is exactly the composition of the granular pieces.
  • Update package README to document the new granular fields and example usage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/react/src/utils/render-to-html.tsx Extends HtmlParts and renderToHtmlParts to return granular css/js/tags alongside head/body.
packages/react/src/utils/extract-head.test.tsx Adds coverage for the new granular return fields and validates head composition.
packages/react/README.md Documents the expanded renderToHtmlParts return shape and provides an example for CSS inlining use cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/utils/render-to-html.tsx
Comment thread packages/react/src/utils/extract-head.test.tsx
ivoIturrieta and others added 2 commits July 4, 2026 15:55
The editor's documented chunks are body/css/js/fonts. Elements exposes
tags additionally because component head functions can contribute
them — reassembling from css + js alone would silently drop tags —
and omits fonts (no font registry; renderToHtml's fonts option covers
font links). Both deviations are now stated in the types and README.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ivoIturrieta
ivoIturrieta merged commit 44899cc into main Jul 4, 2026
2 checks passed
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.

2 participants