Problem/Motivation

With CSS aggregation on, Mercury Editor’s backend edit screen shows broken styles. The chrome (toolbar/sidebar) uses Claro; the large preview iframe uses the site default theme and loads entity.*.mercury_editor_preview.

This module inlines selected CSS and removes those files from the aggregate. That is correct for public pages. On the preview document it leaves the iframe without those rules (and without a matching inline <style> if skip/cache does not line up). Core keys the CSS-asset cache by library set, not by route — the admin-bypass library exists for that reason.

shouldBypassCriticalCss() already skips _admin_route, _hide_admin_toolbar, and Sec-Fetch-Dest: iframe. The preview route sets _hide_admin_toolbar but not _mercury_editor_route. That is not enough in practice: skip does not fire, or the stripped aggregate is reused. Canvas public pages are fine with this module; the gap is editorial overlays that still use the front-end theme.

Steps to reproduce

  1. Enable SDC Critical CSS and CSS aggregation (system.performance: css.preprocess: true).
  2. Open a Mercury Editor screen, e.g. /mercury-editor/{uuid}.
  3. The preview (most of the viewport) is unstyled / broken. Public pages of the same site are OK.

Observed on Drupal CMS-style sites using Mercury Editor (Artist, Horizons).

Proposed resolution

Widen the existing skip in shouldBypassCriticalCss(). Keep attaching sdc_critical_css/admin-bypass so the CSS-asset cache is not shared with public pages.

Use Drupal conventions, not a hard dependency on Mercury or Canvas:

  • _admin_route (already)
  • _hide_admin_toolbar (already)
  • Sec-Fetch-Dest: iframe (already)
  • _mercury_editor_route
  • route name matching mercury_editor.* / *.mercury_editor_preview / canvas.*
  • path prefix /mercury-editor or /canvas/

Leave hook_sdc_critical_css_skip_alter() for other editors. Same skip policy as Non-critical CSS (companion issue).

Remaining tasks

  • Extend shouldBypassCriticalCss().
  • Confirm admin-bypass is attached on every skipped request that still uses the default theme.
  • Tests for admin route, Mercury preview, Canvas editor path, iframe fetch dest.
  • Short README note: editorial overlays are skipped.

User interface changes

None.

API changes

None. hook_sdc_critical_css_skip_alter() stays.

Data model changes

None.

Comments

drale01 created an issue. See original summary.

  • drale01 committed 5a6d52ef on 1.0.x
    Issue #3631045 by drale01: Skip critical CSS stripping on editorial...
drale01’s picture

Status: Active » Fixed

Committed to 1.0.x: https://git.drupalcode.org/project/sdc_critical_css/-/commit/5a6d52e

Skip now covers Mercury Editor / Canvas editor routes and the lazy CSS aggregate rebuild (system.css_asset) when sdc_critical_css/admin-bypass is in include=. Tested with CSS aggregation on Artist (Mercury Editor). Public pages still inline as before.

Related: #3631048

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.