Follow-ups on shadowrootadoptedstylesheets#1287
Follow-ups on shadowrootadoptedstylesheets#1287KurtCattiSchmidt wants to merge 2 commits intoMicrosoftEdge:mainfrom
Conversation
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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).
| 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: |
There was a problem hiding this comment.
| 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: |
Addressing the non-blocking feedback from #1284