/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/hotCases/css/link-insert-hook/index.js
33 строки
1 KB
Alexander Akait
feat: add linkInsert hook to CssLoadingRuntimeModule (#20947)
12 май 2026, 16:39
Не верифицирован
12 май 2026, 16:39
0053c9f
Код
Авторство
О чём код?
import "./index.css"; const findOurLink = () => [...window.document.getElementsByTagName("link")].find( (item) => item.rel === "stylesheet" && item.href && item.href.includes("bundle.css") ); it("should run linkInsert source on HMR and reuse the existing link's parent", (done) => { const initial = findOurLink(); expect(initial).toBeDefined(); expect(initial.sheet.cssRules[0].style.color.trim()).toBe("red"); // Move the initial link out of <head> and into <body>. The HMR // replacement must land in the same parent (document.body) via // hmr.parentNode.insertBefore, regardless of the default <head>. window.document.body.appendChild(initial); expect(initial.parentNode).toBe(window.document.body); NEXT( require("../../update")(done, true, () => { const taggedLink = [ ...window.document.getElementsByTagName("link") ].find((l) => l.getAttribute("data-link-insert") === "custom"); expect(taggedLink).toBeDefined(); // linkInsert source ran for HMR and placement followed hmr.parentNode. expect(taggedLink.parentNode).toBe(window.document.body); done(); }) ); });