Skip to content

fix(newsletters): render layout previews correctly in Safari/WebKit#274

Open
thomasguillot wants to merge 1 commit into
mainfrom
fix/newsletter-preview-webkit-styles
Open

fix(newsletters): render layout previews correctly in Safari/WebKit#274
thomasguillot wants to merge 1 commit into
mainfrom
fix/newsletter-preview-webkit-styles

Conversation

@thomasguillot

@thomasguillot thomasguillot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Newsletter layout previews (the Layouts list DataView, the editor's layout sidebar, and the init-modal layout picker) rendered correctly in Chromium but broke in Safari/WebKit: the site logo blew out to its intrinsic size, social links lost their flex layout, the site-logo "Drop files to upload" overlay showed through, and custom layout fonts/colors fell back to defaults.

Root cause. NewsletterPreview got the core editor stylesheets into the BlockPreview iframe by hand-injecting <link>/<style> nodes into the iframe <head> on load. Gutenberg owns that iframe document and re-renders it, discarding anything injected outside its own channels. Chromium's timing left the injected nodes in place; WebKit wiped them, so the iframe was missing core block/editor CSS.

Fix. Route styles through Gutenberg's own channels — the same way the Post/Site editors do — so they persist across browsers:

  • Core stylesheets (wp-block-library, -theme, wp-edit-blocks, wp-components) via settings.__unstableResolvedAssets, referenced by URL and baked into the iframe srcDoc. Seeded only where that setting is empty (admin-shell surfaces) and never on the live editor, so the editor canvas is never reloaded.
  • Global styles + default fonts via a seeded settings.styles entry (safe { css }, no raw HTML concatenation).
  • Per-layout overrides (body/header fonts, background/text colors, custom CSS) via BlockPreview's additionalStyles prop, with !important on the generated rules so they win over both the seeded defaults and the editor's higher-specificity, variable-based font rules on the in-editor preview surfaces.

This removes the WebKit-fragile hand-injection: the redundant stylesheet clone, the duplicated per-instance/global <style> injection, and the dead #newspack-newsletters__layout-css element (whose only consumer in posts-inserter/posts-preview.js is also removed — that preview still gets fonts via useCustomFontsInIframe). Net result is a smaller component with no per-block CSS patches.

How to test the changes in this Pull Request:

  1. Build newspack-newsletters. Open Newsletters → Layouts list in Safari.
  2. Prebuilt layout thumbnails render correctly: logo sized to its container, social icons in a styled row, no "Drop files to upload" text.
  3. Create a saved layout with a distinct custom body/header font and custom background/text colors (or use a few seeded ones). Its thumbnail renders in that font and those colors in Safari — and so does its preview in the editor's layout sidebar / the init-modal layout picker (the surfaces where editor.css competes; !important ensures the layout's styles win).
  4. Confirm all of the above still render correctly in Chrome (no regression).
  5. Open the newsletter editor and confirm the main editor canvas behaves normally (the seed is guarded to never touch the live editor's resolved assets).

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

@thomasguillot thomasguillot force-pushed the fix/newsletter-preview-webkit-styles branch from a5241f6 to a817ea5 Compare June 10, 2026 23:16
@thomasguillot thomasguillot marked this pull request as ready for review June 10, 2026 23:17
@thomasguillot thomasguillot requested a review from a team as a code owner June 10, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant