@uniflowed/vite 0.0.0-alpha.37 → 0.0.0-alpha.39

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.
package/driver.js CHANGED
@@ -228,6 +228,24 @@ async function viteConfig(config, mode) {
228
228
  configFile: false,
229
229
  envDir: false,
230
230
  mode,
231
+ // Vite's dependency cache, kept in the project whatever is above it.
232
+ // Vite's own default is the nearest `package.json`'s `node_modules/.vite`,
233
+ // and a uf project needs no `package.json`. One inside another repository
234
+ // pre-bundled into that repository's `node_modules`, in one directory
235
+ // shared with every other such project there and emptied by each dev
236
+ // server that started — which is how two `uf dev` servers came to answer
237
+ // each other's pre-bundled files with `504 Outdated Optimize Dep`
238
+ // (ubugeeei-prod/uf#1141).
239
+ //
240
+ // This directory rather than `.vite` or `.uf/cache/vite`, because it is
241
+ // where Vite already puts the cache for a project with its own
242
+ // `package.json`, so nothing moves for one: the URLs stay
243
+ // `/node_modules/.vite/deps/…`, and the files stay under `node_modules`,
244
+ // which git ignores, Vite's watcher skips and Vite's sourcemap ignore list
245
+ // treats as somebody else's code. `cacheDir` is shared config, so every
246
+ // environment's optimizer follows it — `deps`, `deps_ssr`, `deps_rsc` —
247
+ // and a project's own `vite.cacheDir` is merged over it like any option.
248
+ cacheDir: path.join(root, "node_modules", ".vite"),
231
249
  // `app.router.basePath`: where Vite serves the modules in development, and
232
250
  // what it puts in front of every asset URL a build writes.
233
251
  base: basePathOf(config) === "" ? "/" : `${basePathOf(config)}/`,
package/index.js CHANGED
@@ -183,6 +183,16 @@ export default function uniflowed(options = {}) {
183
183
  // at. Anything but `"document"` is the client router, which is what every
184
184
  // project that has not heard of the key has.
185
185
  const navigation = app.rendering?.navigation === "document" ? "document" : "client";
186
+ // How long, in seconds, the client router shows a route it already fetched
187
+ // without asking the server again, written into the client entry beside
188
+ // `navigation` and honoured by every command for the same reason. Anything
189
+ // but a positive number is `0`, which keeps nothing.
190
+ const staleTime =
191
+ typeof app.rendering?.staleTime === "number" &&
192
+ Number.isFinite(app.rendering.staleTime) &&
193
+ app.rendering.staleTime > 0
194
+ ? app.rendering.staleTime
195
+ : 0;
186
196
  // Whether this application starts by attaching to markup or by rendering
187
197
  // into an empty root. `["csr"]` is the only list that means the second, and
188
198
  // `uf` refuses that value beside any other while the config is read — so the
@@ -213,6 +223,7 @@ export default function uniflowed(options = {}) {
213
223
  routeTarget,
214
224
  strictMode,
215
225
  navigation,
226
+ staleTime,
216
227
  mount,
217
228
  flightState,
218
229
  routing,
@@ -240,6 +251,7 @@ function flowPlugin({
240
251
  routeTarget,
241
252
  strictMode,
242
253
  navigation,
254
+ staleTime,
243
255
  mount,
244
256
  flightState,
245
257
  routing,
@@ -546,6 +558,7 @@ function flowPlugin({
546
558
  return flightClientSource(entryPath, {
547
559
  strictMode: strictMode && !isProduction,
548
560
  navigation,
561
+ staleTime,
549
562
  routing,
550
563
  });
551
564
  }
@@ -553,6 +566,7 @@ function flowPlugin({
553
566
  return clientModuleSource(entryPath, {
554
567
  strictMode: strictMode && !isProduction,
555
568
  navigation,
569
+ staleTime,
556
570
  mount,
557
571
  routing,
558
572
  });
@@ -623,9 +623,12 @@ export function flightClientSource(appEntry, options = {}) {
623
623
  const routing =
624
624
  (basePath === "" ? "" : `, basePath: ${JSON.stringify(basePath)}`) +
625
625
  (trailingSlash === "ignore" ? "" : `, trailingSlash: ${JSON.stringify(trailingSlash)}`);
626
+ // `app.rendering.staleTime`, in seconds, and nothing for the default `0`.
627
+ const staleTime =
628
+ options.staleTime > 0 ? `, staleTime: ${JSON.stringify(options.staleTime)}` : "";
626
629
  return `import { hydrateFlight } from "@uniflowed/router/rsc/client";
627
630
  import App from ${JSON.stringify(appEntry)};
628
- hydrateFlight({ App${strictMode}${navigation}${routing} });
631
+ hydrateFlight({ App${strictMode}${navigation}${staleTime}${routing} });
629
632
  `;
630
633
  }
631
634
 
@@ -1654,10 +1654,13 @@ export function clientModuleSource(appEntry, options = {}) {
1654
1654
  const navigation = options.navigation === "document" ? ', navigation: "document"' : "";
1655
1655
  const mount = options.mount === "render" ? "render" : "hydrate";
1656
1656
  const routing = routingArgumentSource(options.routing);
1657
+ // `app.rendering.staleTime`, in seconds, and nothing for the default `0`.
1658
+ const staleTime =
1659
+ options.staleTime > 0 ? `, staleTime: ${JSON.stringify(options.staleTime)}` : "";
1657
1660
  return `import { ${mount} } from "@uniflowed/router/client";
1658
1661
  import { routes, notFound, errors } from ${JSON.stringify(VIRTUAL.routes)};
1659
1662
  import App from ${JSON.stringify(appEntry)};
1660
- ${mount}({ App, routes, notFound, errors${strictMode}${navigation}${routing} });
1663
+ ${mount}({ App, routes, notFound, errors${strictMode}${navigation}${staleTime}${routing} });
1661
1664
  `;
1662
1665
  }
1663
1666
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniflowed/vite",
3
- "version": "0.0.0-alpha.37",
3
+ "version": "0.0.0-alpha.39",
4
4
  "description": "Vite, driven by uf.config.js: every Flow module through `uf transform`, MDX, the file-system router and static rendering as Vite plugins.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "dependencies": {
35
35
  "@mdx-js/rollup": "^3.1.1",
36
36
  "@shikijs/rehype": "^3.23.0",
37
- "@uniflowed/host": "0.0.0-alpha.37",
38
- "@uniflowed/router": "0.0.0-alpha.37",
39
- "@uniflowed/server": "0.0.0-alpha.37",
40
- "@uniflowed/validator": "0.0.0-alpha.37",
37
+ "@uniflowed/host": "0.0.0-alpha.39",
38
+ "@uniflowed/router": "0.0.0-alpha.39",
39
+ "@uniflowed/server": "0.0.0-alpha.39",
40
+ "@uniflowed/validator": "0.0.0-alpha.39",
41
41
  "estree-util-value-to-estree": "^3.5.0",
42
42
  "rehype-slug": "^6.0.0",
43
43
  "remark-frontmatter": "^5.0.0",