@timber-js/app 0.2.0-alpha.138 → 0.2.0-alpha.139

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.
Files changed (108) hide show
  1. package/dist/_chunks/{actions-CHFblsdT.js → actions-DzFMnUAR.js} +7 -7
  2. package/dist/_chunks/{actions-CHFblsdT.js.map → actions-DzFMnUAR.js.map} +1 -1
  3. package/dist/_chunks/{build-output-helper-CfBfOU9m.js → build-output-helper-B20ZuTSA.js} +1 -1
  4. package/dist/_chunks/{build-output-helper-CfBfOU9m.js.map → build-output-helper-B20ZuTSA.js.map} +1 -1
  5. package/dist/_chunks/{cli-schema-sync-q-Ce6-iG.js → cli-schema-sync-D2IpXicg.js} +5 -5
  6. package/dist/_chunks/cli-schema-sync-D2IpXicg.js.map +1 -0
  7. package/dist/_chunks/{cli-schema-sync-CObqjGWF.js → cli-schema-sync-DH-M8Poy.js} +1 -1
  8. package/dist/_chunks/{codec-registry-G9hD5LOq.js → codec-registry-oOUxugz3.js} +1 -1
  9. package/dist/_chunks/{codec-registry-G9hD5LOq.js.map → codec-registry-oOUxugz3.js.map} +1 -1
  10. package/dist/_chunks/{define-DXWUJb-K.js → define-C3RvHQPK.js} +3 -3
  11. package/dist/_chunks/{define-DXWUJb-K.js.map → define-C3RvHQPK.js.map} +1 -1
  12. package/dist/_chunks/{define-Dp-qu3ql.js → define-DMVhsipD.js} +3 -3
  13. package/dist/_chunks/{define-Dp-qu3ql.js.map → define-DMVhsipD.js.map} +1 -1
  14. package/dist/_chunks/{fast-hash-DXZ7S2D5.js → fast-hash-D6hIVt1Y.js} +1 -1
  15. package/dist/_chunks/{fast-hash-DXZ7S2D5.js.map → fast-hash-D6hIVt1Y.js.map} +1 -1
  16. package/dist/_chunks/{format-CR6v1pWE.js → format-CfwjgPz9.js} +1 -1
  17. package/dist/_chunks/{format-CR6v1pWE.js.map → format-CfwjgPz9.js.map} +1 -1
  18. package/dist/_chunks/{handler-store-aQMpqPe7.js → handler-store-DjISKYEB.js} +1 -1
  19. package/dist/_chunks/{handler-store-aQMpqPe7.js.map → handler-store-DjISKYEB.js.map} +1 -1
  20. package/dist/_chunks/{href-validation-2G-HZaQ8.js → href-validation-EZktELp8.js} +1 -1
  21. package/dist/_chunks/{href-validation-2G-HZaQ8.js.map → href-validation-EZktELp8.js.map} +1 -1
  22. package/dist/_chunks/{logger-CMd9P1xQ.js → logger-Dt-jQaBO.js} +2 -2
  23. package/dist/_chunks/{logger-CMd9P1xQ.js.map → logger-Dt-jQaBO.js.map} +1 -1
  24. package/dist/_chunks/{metadata-routes-DESG8uk5.js → metadata-routes-BjepjefT.js} +1 -1
  25. package/dist/_chunks/{metadata-routes-DESG8uk5.js.map → metadata-routes-BjepjefT.js.map} +1 -1
  26. package/dist/_chunks/{navigation-root-BQqFQI-n.js → navigation-root-DLc4s4ZC.js} +3 -3
  27. package/dist/_chunks/{navigation-root-BQqFQI-n.js.map → navigation-root-DLc4s4ZC.js.map} +1 -1
  28. package/dist/_chunks/{registry-Dp_hJL4s.js → registry-DbJPKoBp.js} +1 -1
  29. package/dist/_chunks/{registry-Dp_hJL4s.js.map → registry-DbJPKoBp.js.map} +1 -1
  30. package/dist/_chunks/{resolve-schema-D3CbcdCW.js → resolve-schema-Dj8tQloi.js} +2 -2
  31. package/dist/_chunks/{resolve-schema-D3CbcdCW.js.map → resolve-schema-Dj8tQloi.js.map} +1 -1
  32. package/dist/_chunks/{router-ref-B50j42zB.js → router-ref-CtmF-aPv.js} +2 -2
  33. package/dist/_chunks/{router-ref-B50j42zB.js.map → router-ref-CtmF-aPv.js.map} +1 -1
  34. package/dist/_chunks/{schema-bridge-Cuy8BaYu.js → schema-bridge-DK_89h8O.js} +1 -1
  35. package/dist/_chunks/{schema-bridge-Cuy8BaYu.js.map → schema-bridge-DK_89h8O.js.map} +1 -1
  36. package/dist/_chunks/{segment-classify-BjfuctV2.js → segment-classify-CDDRVKs7.js} +1 -1
  37. package/dist/_chunks/{segment-classify-BjfuctV2.js.map → segment-classify-CDDRVKs7.js.map} +1 -1
  38. package/dist/_chunks/{segment-context-BnxoPSFQ.js → segment-context-ZDnXDkbz.js} +1 -1
  39. package/dist/_chunks/{segment-context-BnxoPSFQ.js.map → segment-context-ZDnXDkbz.js.map} +1 -1
  40. package/dist/_chunks/{ssr-data-DxXyoRrz.js → ssr-data-BOWsq18U.js} +1 -1
  41. package/dist/_chunks/{ssr-data-DxXyoRrz.js.map → ssr-data-BOWsq18U.js.map} +1 -1
  42. package/dist/_chunks/{tracing-DP5djRq5.js → tracing-M_zKubhk.js} +1 -1
  43. package/dist/_chunks/{tracing-DP5djRq5.js.map → tracing-M_zKubhk.js.map} +1 -1
  44. package/dist/_chunks/{use-query-states-D9SBlAfp.js → use-query-states-CbeQmext.js} +2 -2
  45. package/dist/_chunks/{use-query-states-D9SBlAfp.js.map → use-query-states-CbeQmext.js.map} +1 -1
  46. package/dist/_chunks/{use-segment-params-x2poKmk8.js → use-segment-params-D1CzlgBo.js} +2 -2
  47. package/dist/_chunks/{use-segment-params-x2poKmk8.js.map → use-segment-params-D1CzlgBo.js.map} +1 -1
  48. package/dist/_chunks/{validation-BoWM_qI1.js → validation-taUkvA4Q.js} +1 -1
  49. package/dist/_chunks/{validation-BoWM_qI1.js.map → validation-taUkvA4Q.js.map} +1 -1
  50. package/dist/_chunks/{walkers-BbEu2_Pp.js → walkers-7FBPM-hX.js} +3 -3
  51. package/dist/_chunks/{walkers-BbEu2_Pp.js.map → walkers-7FBPM-hX.js.map} +1 -1
  52. package/dist/_chunks/{warnings-CAzunaGo.js → warnings-CNPXaypM.js} +2 -2
  53. package/dist/_chunks/{warnings-CAzunaGo.js.map → warnings-CNPXaypM.js.map} +1 -1
  54. package/dist/adapters/cloudflare-dev.js.map +1 -1
  55. package/dist/adapters/cloudflare-kv-cache.js.map +1 -1
  56. package/dist/adapters/cloudflare.js +1 -1
  57. package/dist/adapters/cloudflare.js.map +1 -1
  58. package/dist/adapters/nitro.js +1 -1
  59. package/dist/adapters/nitro.js.map +1 -1
  60. package/dist/cache/index.js +4 -4
  61. package/dist/cache/index.js.map +1 -1
  62. package/dist/cli.js +1 -1
  63. package/dist/cli.js.map +1 -1
  64. package/dist/client/error-boundary.js +2 -2
  65. package/dist/client/error-boundary.js.map +1 -1
  66. package/dist/client/index.js +9 -9
  67. package/dist/client/index.js.map +1 -1
  68. package/dist/client/internal.js +88 -8
  69. package/dist/client/internal.js.map +1 -1
  70. package/dist/codec.js +1 -1
  71. package/dist/codec.js.map +1 -1
  72. package/dist/cookies/index.js +3 -3
  73. package/dist/cookies/index.js.map +1 -1
  74. package/dist/index.js +110 -13
  75. package/dist/index.js.map +1 -1
  76. package/dist/params/index.js +2 -2
  77. package/dist/params/index.js.map +1 -1
  78. package/dist/plugin-context.d.ts +7 -0
  79. package/dist/plugin-context.d.ts.map +1 -1
  80. package/dist/plugins/adapter-build.d.ts +19 -0
  81. package/dist/plugins/adapter-build.d.ts.map +1 -1
  82. package/dist/plugins/build-manifest.d.ts +5 -1
  83. package/dist/plugins/build-manifest.d.ts.map +1 -1
  84. package/dist/routing/index.js +3 -3
  85. package/dist/search-params/index.js +3 -3
  86. package/dist/search-params/index.js.map +1 -1
  87. package/dist/segment-params/index.js +1 -1
  88. package/dist/server/early-hints.d.ts +0 -6
  89. package/dist/server/early-hints.d.ts.map +1 -1
  90. package/dist/server/index.js +3 -3
  91. package/dist/server/index.js.map +1 -1
  92. package/dist/server/internal.js +8 -19
  93. package/dist/server/internal.js.map +1 -1
  94. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  95. package/dist/shims/font-google.js.map +1 -1
  96. package/dist/shims/font-local.js.map +1 -1
  97. package/dist/shims/image.d.ts +1 -1
  98. package/package.json +9 -8
  99. package/src/cli.ts +0 -0
  100. package/src/plugin-context.ts +7 -0
  101. package/src/plugins/adapter-build.ts +86 -0
  102. package/src/plugins/build-manifest.ts +99 -17
  103. package/src/server/early-hints.ts +0 -13
  104. package/src/server/rsc-entry/render-route.ts +12 -12
  105. package/LICENSE +0 -8
  106. package/dist/_chunks/cli-schema-sync-q-Ce6-iG.js.map +0 -1
  107. package/dist/_chunks/stale-reload-DIIIVGh_.js +0 -84
  108. package/dist/_chunks/stale-reload-DIIIVGh_.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { n as setViteServer } from "./_chunks/warnings-CAzunaGo.js";
2
- import { a as isDynamicMetadataExtension, o as isMetadataRouteServePath } from "./_chunks/metadata-routes-DESG8uk5.js";
3
- import { h as swallow } from "./_chunks/logger-CMd9P1xQ.js";
4
- import { c as loadTimberConfigFile, d as resolveBuildDir, f as resolveClientJavascript, l as mergeFileConfig, m as scanRoutes, o as DEFAULT_BUILD_DIR, p as createNoopTimer, s as createPluginContext, u as resolveAppDir } from "./_chunks/cli-schema-sync-q-Ce6-iG.js";
5
- import { a as generateRouteMap, i as collectInterceptionRewrites, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-BbEu2_Pp.js";
6
- import { t as fnv1aHash } from "./_chunks/fast-hash-DXZ7S2D5.js";
7
- import { t as formatSize } from "./_chunks/format-CR6v1pWE.js";
1
+ import { n as setViteServer } from "./_chunks/warnings-CNPXaypM.js";
2
+ import { a as isDynamicMetadataExtension, o as isMetadataRouteServePath } from "./_chunks/metadata-routes-BjepjefT.js";
3
+ import { h as swallow } from "./_chunks/logger-Dt-jQaBO.js";
4
+ import { c as loadTimberConfigFile, d as resolveBuildDir, f as resolveClientJavascript, l as mergeFileConfig, m as scanRoutes, o as DEFAULT_BUILD_DIR, p as createNoopTimer, s as createPluginContext, u as resolveAppDir } from "./_chunks/cli-schema-sync-D2IpXicg.js";
5
+ import { a as generateRouteMap, i as collectInterceptionRewrites, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-7FBPM-hX.js";
6
+ import { t as fnv1aHash } from "./_chunks/fast-hash-D6hIVt1Y.js";
7
+ import { t as formatSize } from "./_chunks/format-CfwjgPz9.js";
8
8
  import { basename, dirname, extname, join, normalize, relative, resolve } from "node:path";
9
9
  import { createRequire } from "node:module";
10
10
  import react, { reactCompilerPreset } from "@vitejs/plugin-react";
@@ -3981,7 +3981,6 @@ var RESOLVED_LOCAL = "\0@timber/fonts/local";
3981
3981
  */
3982
3982
  var VIRTUAL_FONT_CSS_PREFIX = "virtual:timber-font-css/";
3983
3983
  var VIRTUAL_FONT_CSS_SUFFIX = ".css";
3984
- "" + VIRTUAL_FONT_CSS_PREFIX;
3985
3984
  /**
3986
3985
  * In-memory map from the short hash used in virtual module ids back to
3987
3986
  * the absolute importer path. Populated by `virtualFontCssIdFor()` when
@@ -5864,9 +5863,6 @@ function buildManifestFromBundle(bundle, base, root) {
5864
5863
  const deps = collectTransitiveBundleDeps(chunk, chunksByFileName, base);
5865
5864
  if (deps.length > 0) modulepreload[inputPath] = deps;
5866
5865
  }
5867
- const allCss = [];
5868
- for (const item of Object.values(bundle)) if (item.type === "asset" && item.fileName.endsWith(".css")) allCss.push(base + item.fileName);
5869
- if (allCss.length > 0) css["_global"] = allCss;
5870
5866
  return {
5871
5867
  css,
5872
5868
  js,
@@ -5914,10 +5910,52 @@ function computeMetadataRouteHashes(node) {
5914
5910
  for (const slot of Object.values(node.slots)) Object.assign(hashes, computeMetadataRouteHashes(slot));
5915
5911
  return hashes;
5916
5912
  }
5913
+ var CLIENT_REF_KEY_RE = /registerClientReference\([^,]+,\s*"([0-9a-f]{12})"/g;
5914
+ /**
5915
+ * Collect all route file paths (layout, page) from the route tree.
5916
+ */
5917
+ function collectRouteFilePaths(node) {
5918
+ const paths = [];
5919
+ if (node.layout) paths.push(node.layout.filePath);
5920
+ if (node.page) paths.push(node.page.filePath);
5921
+ for (const child of node.children) paths.push(...collectRouteFilePaths(child));
5922
+ for (const slot of Object.values(node.slots)) paths.push(...collectRouteFilePaths(slot));
5923
+ return paths;
5924
+ }
5925
+ /**
5926
+ * Scan RSC bundle chunks to find which modules contain registerClientReference
5927
+ * calls, and extract the reference hash keys from each.
5928
+ */
5929
+ function buildClientRefIndex(bundle) {
5930
+ const index = /* @__PURE__ */ new Map();
5931
+ for (const item of Object.values(bundle)) {
5932
+ if (item.type !== "chunk" || !item.modules) continue;
5933
+ for (const [moduleId, mod] of Object.entries(item.modules)) {
5934
+ if (!mod.code) continue;
5935
+ const keys = [];
5936
+ for (const match of mod.code.matchAll(CLIENT_REF_KEY_RE)) keys.push(match[1]);
5937
+ if (keys.length > 0) index.set(moduleId, keys);
5938
+ }
5939
+ }
5940
+ return index;
5941
+ }
5942
+ /**
5943
+ * Walk a module's transitive imports to collect all client reference
5944
+ * keys reachable from it.
5945
+ */
5946
+ function walkModuleImports(moduleId, clientRefIndex, visited, result, getModuleInfo) {
5947
+ if (visited.has(moduleId)) return;
5948
+ visited.add(moduleId);
5949
+ const refKeys = clientRefIndex.get(moduleId);
5950
+ if (refKeys) for (const key of refKeys) result.add(key);
5951
+ const info = getModuleInfo(moduleId);
5952
+ if (!info) return;
5953
+ for (const importedId of info.importedIds) walkModuleImports(importedId, clientRefIndex, visited, result, getModuleInfo);
5954
+ }
5917
5955
  /**
5918
5956
  * Create the timber-build-manifest Vite plugin.
5919
5957
  *
5920
- * Hooks: configResolved, resolveId, load, generateBundle (client env only)
5958
+ * Hooks: configResolved, resolveId, load, generateBundle (client and RSC envs)
5921
5959
  */
5922
5960
  function timberBuildManifest(ctx) {
5923
5961
  let resolvedBase = "/";
@@ -5956,7 +5994,22 @@ function timberBuildManifest(ctx) {
5956
5994
  },
5957
5995
  generateBundle(_options, bundle) {
5958
5996
  if (isDev) return;
5959
- if (this.environment?.name === "client") {
5997
+ const envName = this.environment?.name;
5998
+ if (envName === "rsc" && ctx.routeTree) {
5999
+ const clientRefIndex = buildClientRefIndex(bundle);
6000
+ if (clientRefIndex.size > 0) {
6001
+ const routeFiles = collectRouteFilePaths(ctx.routeTree.root);
6002
+ const routeClientRefKeys = /* @__PURE__ */ new Map();
6003
+ const getInfo = (id) => this.getModuleInfo?.(id) ?? null;
6004
+ for (const filePath of routeFiles) {
6005
+ const refKeys = /* @__PURE__ */ new Set();
6006
+ walkModuleImports(filePath, clientRefIndex, /* @__PURE__ */ new Set(), refKeys, getInfo);
6007
+ if (refKeys.size > 0) routeClientRefKeys.set(filePath, refKeys);
6008
+ }
6009
+ if (routeClientRefKeys.size > 0) ctx.routeClientRefKeys = routeClientRefKeys;
6010
+ }
6011
+ }
6012
+ if (envName === "client") {
5960
6013
  ctx.buildManifest = buildManifestFromBundle(bundle, resolvedBase, ctx.root);
5961
6014
  if (ctx.routeTree) ctx.buildManifest.metadataRouteHashes = computeMetadataRouteHashes(ctx.routeTree.root);
5962
6015
  if (ctx.clientJavascript.disabled) {
@@ -6682,6 +6735,7 @@ function timberAdapterBuild(ctx) {
6682
6735
  const adapter = ctx.config.adapter;
6683
6736
  if (!adapter || typeof adapter.buildOutput !== "function") return;
6684
6737
  const buildDir = ctx.buildDir;
6738
+ if (ctx.buildManifest) await mergeRscAssetsManifest(buildDir, ctx.root, ctx.buildManifest, ctx.routeClientRefKeys);
6685
6739
  let manifestInit;
6686
6740
  if (ctx.buildManifest) {
6687
6741
  const manifest = ctx.clientJavascript.disabled ? {
@@ -6711,6 +6765,49 @@ function timberAdapterBuild(ctx) {
6711
6765
  * intercept them. This rewrites the files on disk after all builds
6712
6766
  * complete but before the adapter copies them to the output directory.
6713
6767
  */
6768
+ /**
6769
+ * Read the RSC plugin's assets manifest and merge per-route CSS and
6770
+ * per-route JS modulepreloads into the build manifest.
6771
+ *
6772
+ * CSS: `serverResources` maps server component paths to CSS URLs.
6773
+ * JS: `clientReferenceDeps` maps reference hashes to JS dep URLs.
6774
+ * Combined with `routeClientRefKeys` (from the RSC generateBundle
6775
+ * module graph walk) to produce per-route modulepreload entries.
6776
+ */
6777
+ async function mergeRscAssetsManifest(buildDir, root, buildManifest, routeClientRefKeys) {
6778
+ const manifestPath = join(buildDir, "rsc", "__vite_rsc_assets_manifest.js");
6779
+ let content;
6780
+ try {
6781
+ content = await readFile(manifestPath, "utf-8");
6782
+ } catch {
6783
+ return;
6784
+ }
6785
+ const jsonStr = content.replace(/^export default\s*/, "").replace(/;?\s*$/, "");
6786
+ let manifest;
6787
+ try {
6788
+ manifest = JSON.parse(jsonStr);
6789
+ } catch {
6790
+ return;
6791
+ }
6792
+ const serverResources = manifest.serverResources;
6793
+ if (serverResources) {
6794
+ for (const [relativePath, deps] of Object.entries(serverResources)) if (deps.css && deps.css.length > 0) {
6795
+ const absolutePath = join(root, relativePath);
6796
+ buildManifest.css[absolutePath] = deps.css;
6797
+ }
6798
+ }
6799
+ if (routeClientRefKeys && routeClientRefKeys.size > 0) {
6800
+ const clientReferenceDeps = manifest.clientReferenceDeps;
6801
+ if (clientReferenceDeps) for (const [filePath, refKeys] of routeClientRefKeys) {
6802
+ const jsUrls = /* @__PURE__ */ new Set();
6803
+ for (const key of refKeys) {
6804
+ const deps = clientReferenceDeps[key];
6805
+ if (deps?.js) for (const url of deps.js) jsUrls.add(url);
6806
+ }
6807
+ if (jsUrls.size > 0) buildManifest.modulepreload[filePath] = Array.from(jsUrls);
6808
+ }
6809
+ }
6810
+ }
6714
6811
  async function stripJsFromRscAssetsManifests(buildDir) {
6715
6812
  const manifestName = "__vite_rsc_assets_manifest.js";
6716
6813
  const paths = [join(buildDir, "rsc", manifestName), join(buildDir, "ssr", manifestName)];