@stillwind/integration 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { i as renderChunkStyles, r as createViteProject, t as createVitePlugins } from "../plugin-BFSq3lEh.js";
1
+ import { i as renderChunkStyles, r as createViteProject, t as createVitePlugins } from "../plugin-ByYcpBcE.js";
2
2
  import { registerDevelopmentCss } from "./development.js";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { fileURLToPath } from "node:url";
@@ -1,4 +1,4 @@
1
- import { r as createViteProject, t as createVitePlugins } from "../plugin-BFSq3lEh.js";
1
+ import { r as createViteProject, t as createVitePlugins } from "../plugin-ByYcpBcE.js";
2
2
  // src/fresh/manifest.ts
3
3
  /** Filters repeated static files for Fresh's move operation without changing the emitted manifest. */
4
4
  function registrationManifest(source) {
@@ -1,4 +1,4 @@
1
- import { r as createViteProject, t as createVitePlugins } from "../plugin-BFSq3lEh.js";
1
+ import { r as createViteProject, t as createVitePlugins } from "../plugin-ByYcpBcE.js";
2
2
  import { addPluginTemplate, defineNuxtModule } from "nuxt/kit";
3
3
  // src/nuxt/index.ts
4
4
  /**
@@ -31,6 +31,31 @@ function sourceModuleId(root, id) {
31
31
  }
32
32
  // src/vite/chunk-styles.ts
33
33
  /**
34
+ * Browser code that keeps loader links across Astro ClientRouter navigations.
35
+ *
36
+ * Astro removes each head element that the incoming document does not contain, and the chunk that
37
+ * added a link does not run again, so the link would stay missing. Astro keeps an old stylesheet
38
+ * link when the incoming head has a link with the same `href`, and each incoming link matches one
39
+ * old link. The listener therefore copies each loader link while the incoming head has fewer links
40
+ * with its `href` than the current head, which also keeps repeated split occurrences. One listener
41
+ * serves all chunks in a document.
42
+ */
43
+ const persistAcrossSwaps = `const key = Symbol.for("stillwind.persistLinks");
44
+ if (!globalThis[key]) {
45
+ globalThis[key] = true;
46
+ document.addEventListener("astro:before-swap", (event) => {
47
+ const head = event.newDocument.head;
48
+ const count = (parent, href) =>
49
+ [...parent.querySelectorAll('link[rel="stylesheet"]')].filter((l) => l.getAttribute("href") === href).length;
50
+ for (const link of document.head.querySelectorAll("link[data-stillwind-loader]")) {
51
+ const href = link.getAttribute("href");
52
+ if (count(head, href) < count(document.head, href)) {
53
+ head.append(link.cloneNode());
54
+ }
55
+ }
56
+ });
57
+ }`;
58
+ /**
34
59
  * Associates emitted CSS with a chunk and loads its stylesheets in the browser.
35
60
  *
36
61
  * Split parts retain manifest order and relative-base URLs resolve against the chunk. Hosts can
@@ -93,8 +118,10 @@ if (typeof document !== "undefined") {
93
118
  l.href = p.relative ? new URL(p.href, import.meta.url).href : p.href;
94
119
  l.dataset.stillwindPart = p.id;
95
120
  l.dataset.stillwindOrder = String(p.order);
121
+ l.dataset.stillwindLoader = "";
96
122
  document.head.insertBefore(l, links.find((e) => Number(e.dataset.stillwindOrder) > p.order) ?? null);
97
123
  }
124
+ ${persistAcrossSwaps}
98
125
  }
99
126
  `,
100
127
  map: null
@@ -117,8 +144,10 @@ if (typeof document !== "undefined") {
117
144
  const link = document.createElement("link");
118
145
  link.rel = "stylesheet";
119
146
  link.href = href;
147
+ link.dataset.stillwindLoader = "";
120
148
  document.head.append(link);
121
149
  }
150
+ ${persistAcrossSwaps}
122
151
  }
123
152
  `,
124
153
  map: null
@@ -681,6 +710,52 @@ function minifyTargets(target) {
681
710
  function finalizeModuleWithMap$1(code, includeStylesheet = true) {
682
711
  return finalizeModuleWithMap(code, includeStylesheet ? virtualCssId : void 0);
683
712
  }
713
+ // src/vite/server-source-resolve.ts
714
+ /** Text of the error that React Router throws when a client module resolves a server-only source. */
715
+ const serverOnlyImportMessage = "Server-only module referenced by client";
716
+ /** Number of resolutions before a React Router server-only import error is passed to the caller. */
717
+ const serverSourceResolveAttempts = 5;
718
+ /**
719
+ * Resolves an import whose target may be a server-only source, through the other Vite plugins.
720
+ *
721
+ * Rolldown can deliver the `custom` option of one `this.resolve()` call to a different call that
722
+ * runs at the same time (https://github.com/rolldown/rolldown/issues/11180). It stores the options
723
+ * of each pending call under the current size of a map. After an earlier call finishes, a new call
724
+ * can receive the key of a pending call and replace its options. React Router then does not see
725
+ * the flag from {@link ServerSourceResolveOptions} and throws for a valid Stillwind read, for example
726
+ * `../server.server.js?stillwind.css` in a route module. This retry is a workaround and is not
727
+ * needed after Rolldown gives each pending call its own key. Other plugin errors and other
728
+ * failures are passed to the caller without a retry.
729
+ *
730
+ * @param resolve - Resolver of the current Vite hook context. Each call must be independent, so
731
+ * the same arguments can be resolved again. Each call receives a new options object.
732
+ * @param specifier - Import text without the Stillwind resource query.
733
+ * @param importer - Resolver identity of the importing module.
734
+ * @returns The result of the first resolution that does not throw React Router's server-only
735
+ * import error.
736
+ * @throws The error of the last attempt if each attempt throws React Router's server-only import
737
+ * error, or the first error of another kind.
738
+ */
739
+ async function resolveServerSource(resolve, specifier, importer) {
740
+ for (let attempt = 1;; attempt++) try {
741
+ return await resolve(specifier, importer, {
742
+ skipSelf: true,
743
+ custom: { "react-router:dot-server": true }
744
+ });
745
+ } catch (error) {
746
+ if (attempt >= serverSourceResolveAttempts || !isServerOnlyImportError(error)) throw error;
747
+ }
748
+ }
749
+ /**
750
+ * Checks whether a resolver error, or one of its causes, is React Router's server-only import error.
751
+ *
752
+ * @param error - Value thrown by a resolver. Rolldown can wrap the plugin error in another error.
753
+ * @returns True when the message of the error or of a cause contains React Router's message.
754
+ */
755
+ function isServerOnlyImportError(error) {
756
+ for (let current = error; current instanceof Error; current = current.cause) if (current.message.includes(serverOnlyImportMessage)) return true;
757
+ return false;
758
+ }
684
759
  // src/vite/compile.ts
685
760
  /**
686
761
  * Compiles a producer and prepares its generated imports, source map, and cache metadata.
@@ -714,10 +789,7 @@ async function compileProducer(compiler, settings, config, registry, code, id, c
714
789
  return clean.startsWith("\0") || clean.startsWith("virtual:") ? `stillwind-virtual:${encodeURIComponent(clean)}` : pathToFileURL(clean).href;
715
790
  };
716
791
  const output = await compiler.compile(code, id, {
717
- resolve: (specifier, importer) => context.resolve(specifier, importer, {
718
- skipSelf: true,
719
- custom: { "react-router:dot-server": true }
720
- }),
792
+ resolve: (specifier, importer) => resolveServerSource((specifier, importer, options) => context.resolve(specifier, importer, options), specifier, importer),
721
793
  read: (id) => readFile(cleanModuleId(id), "utf8"),
722
794
  describe: (resolvedId) => {
723
795
  const virtual = resolvedId.startsWith("\0") || resolvedId.startsWith("virtual:");
@@ -2126,10 +2198,7 @@ function transformHooks(project, virtualModules, options = {}) {
2126
2198
  }
2127
2199
  const projections = /* @__PURE__ */ new Map();
2128
2200
  for (const specifier of await projectionImports(code, id)) {
2129
- const source = await this.resolve(specifier.slice(0, -14), id, {
2130
- skipSelf: true,
2131
- custom: { "react-router:dot-server": true }
2132
- });
2201
+ const source = await resolveServerSource(this.resolve.bind(this), specifier.slice(0, -14), id);
2133
2202
  if (!source || source.external) this.error(`Cannot resolve Stillwind projection ${specifier}`);
2134
2203
  await readableFile(source.id, settings.devServerRef);
2135
2204
  projections.set(specifier, source.id);
@@ -2613,4 +2682,4 @@ function compilerPlugin(project, transform, closed) {
2613
2682
  }
2614
2683
  export { renderChunkStyles as i, stillwind as n, createViteProject as r, createVitePlugins as t };
2615
2684
 
2616
- //# sourceMappingURL=plugin-BFSq3lEh.js.map
2685
+ //# sourceMappingURL=plugin-ByYcpBcE.js.map