@rsc-kit/core 0.16.2 → 0.16.3

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/dist/vite.js CHANGED
@@ -12,7 +12,7 @@
12
12
  // carry the route composition and the worker's render contract, and supplies
13
13
  // the structural config (entries, output dirs, base). @vitejs/plugin-rsc is
14
14
  // included here so it always runs before any react() layer the app adds.
15
- import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
15
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, createReadStream, } from "node:fs";
16
16
  import { gzipSync } from "node:zlib";
17
17
  import { createHash } from "node:crypto";
18
18
  import { createRequire } from "node:module";
@@ -22,7 +22,7 @@ import rsc, { getPluginApi } from "@vitejs/plugin-rsc";
22
22
  import { loadEnv } from "vite";
23
23
  import { REPORT_FILE, buildReport } from "./buildReport.js";
24
24
  import { MANIFEST_PATH, manifestWarning, webManifest } from "./webManifest.js";
25
- import { ASSET_BASE, appAssets, headTags } from "./appAssets.js";
25
+ import { ASSET_BASE, allAppAssets, appAssets, headTags, typeOf, } from "./appAssets.js";
26
26
  import { httpHostCalls } from "./hostCalls.js";
27
27
  // Resolved once per rscKit() call. One build runs in one process, so these are
28
28
  // module state rather than threaded through every helper.
@@ -956,13 +956,7 @@ export function declaredManifest(appDir) {
956
956
  function copyAppAssets(clientDir) {
957
957
  if (!existsSync(clientDir))
958
958
  return;
959
- const all = [
960
- ...(foundAssets.favicon ? [foundAssets.favicon] : []),
961
- ...foundAssets.icons,
962
- ...(foundAssets.appleIcon ? [foundAssets.appleIcon] : []),
963
- ...(foundAssets.openGraph ? [foundAssets.openGraph] : []),
964
- ...(foundAssets.twitter ? [foundAssets.twitter] : []),
965
- ];
959
+ const all = allAppAssets(foundAssets);
966
960
  if (all.length === 0)
967
961
  return;
968
962
  for (const asset of all) {
@@ -3727,7 +3721,19 @@ export async function handleSsr(
3727
3721
  const html = await renderToReadableStream(root as any, {
3728
3722
  bootstrapScriptContent,
3729
3723
  nonce,
3730
- onError: onError ?? ((error: unknown) => { console.error('[rsc-kit:ssr]', error) }),
3724
+ // The query-string fallback is the designed path for a stored page, and
3725
+ // its digest is what lets the client tell it from a fault on hydration;
3726
+ // returned here so React writes it into the document.
3727
+ onError: onError ?? ((error: unknown) => {
3728
+ const digest = (error as { digest?: string } | null)?.digest
3729
+ if (digest === 'rsc-kit:search-params-fallback') {
3730
+ // One line, not a stack: the line is the dev server saying which
3731
+ // boundary the build will want.
3732
+ console.error('[rsc-kit] ' + String((error as Error).message))
3733
+ return digest
3734
+ }
3735
+ console.error('[rsc-kit:ssr]', error)
3736
+ }),
3731
3737
  })
3732
3738
 
3733
3739
  return DEV_ORIGIN ? rewriteViteDevUrlStream(html, DEV_ORIGIN) : html
@@ -4266,6 +4272,25 @@ export function rscKit(options = {}) {
4266
4272
  * nothing.
4267
4273
  */
4268
4274
  configureServer(server) {
4275
+ // The icons and share images live in app/, which nothing serves; the
4276
+ // build copies them beside the client output. There is no output while
4277
+ // developing, so the same hrefs the head tags carry are answered from
4278
+ // app/ here - and the web manifest with them - or the tab has no icon
4279
+ // and the console a 404 for a file that is right there.
4280
+ server.middlewares.use((req, res, next) => {
4281
+ const url = (req.url ?? "").split("?")[0];
4282
+ if (webManifestOptions && url === MANIFEST_PATH) {
4283
+ res.setHeader("Content-Type", "application/manifest+json");
4284
+ res.end(webManifest(webManifestOptions));
4285
+ return;
4286
+ }
4287
+ const asset = allAppAssets(foundAssets).find((a) => a.href === url);
4288
+ const file = asset ? join(sourceDir, "app", asset.file) : null;
4289
+ if (!asset || !file || !existsSync(file))
4290
+ return next();
4291
+ res.setHeader("Content-Type", typeOf(asset.file));
4292
+ createReadStream(file).pipe(res);
4293
+ });
4269
4294
  // rpc() has to reach the backend while the dev server is serving.
4270
4295
  //
4271
4296
  // A built deployment installs this itself: the server running