rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
35 lines (34 loc) • 1.13 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { getManifest } from "../lib/manifest.js";
const findCssForModule = (scriptId, manifest) => {
const css = new Set();
const visited = new Set();
const inner = (id) => {
if (visited.has(id)) {
return;
}
visited.add(id);
const entry = manifest[id];
if (!entry) {
return;
}
if (entry.css) {
for (const href of entry.css) {
css.add(href);
}
}
};
inner(scriptId);
return Array.from(css);
};
export const Stylesheets = async ({ requestInfo, }) => {
const manifest = await getManifest();
const allStylesheets = new Set();
for (const scriptId of requestInfo.rw.scriptsToBeLoaded) {
const css = findCssForModule(scriptId, manifest);
for (const entry of css) {
allStylesheets.add(entry);
}
}
return (_jsx(_Fragment, { children: Array.from(allStylesheets).map((href) => (_jsx("link", { rel: "stylesheet", href: href, precedence: "first" }, href))) }));
};