Skip to content

Follow-ups on shadowrootadoptedstylesheets#1287

Open
KurtCattiSchmidt wants to merge 2 commits intoMicrosoftEdge:mainfrom
KurtCattiSchmidt:sar-followups
Open

Follow-ups on shadowrootadoptedstylesheets#1287
KurtCattiSchmidt wants to merge 2 commits intoMicrosoftEdge:mainfrom
KurtCattiSchmidt:sar-followups

Conversation

@KurtCattiSchmidt
Copy link
Copy Markdown
Contributor

Addressing the non-blocking feedback from #1284

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Follow-up edits to the Shadow DOM / shadowrootadoptedstylesheets explainers to incorporate non-blocking feedback from #1284, primarily refining wording and examples around module preloading/render blocking and updating terminology/syntax.

Changes:

  • Refines guidance for pre-fetching external CSS modules (adds blocking="render" to the example and expands the explanatory text).
  • Fixes terminology/grammar in the main Shadow DOM explainer (attribute vs property; grammar correction).
  • Updates an example to use import ... with { type: 'css' } syntax.

Reviewed changes

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

File Description
ShadowDOMAdoptedStyleSheets/explainer.md Expands/adjusts the modulepreload guidance and example; tweaks the recommendations list.
ShadowDOM/explainer.md Minor editorial fixes (attribute terminology, grammar) and updates an import example to with { type: 'css' }.

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

Comment on lines 205 to +207
For this reason, developer tools should surface a warning when `shadowrootadoptedstylesheets` triggers a fetch, recommending that developers either:
1. Define the styles inline using `<style type="module" specifier="...">` (a [Declarative CSS Module](../ShadowDOM/explainer.md#proposal-inline-declarative-css-module-scripts)) so the styles are available synchronously, or
2. Use `<link rel="modulepreload">` to pre-fetch the module, which supports error handling via the `onerror` event and can be combined with [`blocking="render"`](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#blocking-attributes) to avoid FOUC.
2. Use `<link rel="modulepreload">` to pre-fetch the module, which can be combined with [`blocking="render"`](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#blocking-attributes) to avoid FOUC.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This recommendation bullet removed the earlier claim about onerror error handling, but the example above still includes onerror="handleError()" and the preceding text mentions it. Please make the guidance consistent (either mention error handling here as well, or remove/de-emphasize onerror in the earlier paragraph/example if it’s not intended as a recommendation).

Copilot uses AI. Check for mistakes.
The shadow root is initially rendered without the styles from "foo.css". Once the fetch completes, the styles are applied. This will cause a FOUC (Flash of Unstyled Content) — the element is first painted without the external styles and then repainted once the fetch completes.

Developers should pre-fetch external CSS using [`<link rel="modulepreload">`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload) to ensure it's in the module map before the `<template>` is parsed, avoiding FOUC and providing error handling:
Developers should pre-fetch external CSS using [`<link rel="modulepreload">`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload) to initiate the fetch before the `<template>` is parsed. If the fetch completes before the `<template>` tag is parsed, the styles will be immediately populated. The optional `blocking="render"` attribute will block rendering until the fetch completes, avoiding FOUC if desired. The `onerror` may also provide error handling:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Developers should pre-fetch external CSS using [`<link rel="modulepreload">`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload) to initiate the fetch before the `<template>` is parsed. If the fetch completes before the `<template>` tag is parsed, the styles will be immediately populated. The optional `blocking="render"` attribute will block rendering until the fetch completes, avoiding FOUC if desired. The `onerror` may also provide error handling:
Developers should pre-fetch external CSS using [`<link rel="modulepreload">`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload) to initiate the fetch before the `<template>` is parsed. If the fetch completes before the `<template>` tag is parsed, the styles will be immediately populated. The optional `blocking="render"` attribute will block rendering until the fetch completes, avoiding FOUC if desired. The `onerror` attribute may also provide error handling:

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.

3 participants