@rpcbase/server 0.514.0 → 0.516.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 +1 @@
1
- {"version":3,"file":"applyRouteLoaders.d.ts","sourceRoot":"","sources":["../src/applyRouteLoaders.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAC/B,OAAO,EACL,oBAAoB,EAMrB,MAAM,iBAAiB,CAAA;AA0GxB,MAAM,MAAM,yBAAyB,GAAG,oBAAoB,GAAG;IAC7D,gBAAgB,CAAC,EAAE,QAAQ,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,UAAU,EAAE,GAAG,EAAE,GAChB,OAAO,CAAC,yBAAyB,CAAC,CAwLpC"}
1
+ {"version":3,"file":"applyRouteLoaders.d.ts","sourceRoot":"","sources":["../src/applyRouteLoaders.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAC/B,OAAO,EACL,oBAAoB,EAMrB,MAAM,iBAAiB,CAAA;AAkHxB,MAAM,MAAM,yBAAyB,GAAG,oBAAoB,GAAG;IAC7D,gBAAgB,CAAC,EAAE,QAAQ,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,UAAU,EAAE,GAAG,EAAE,GAChB,OAAO,CAAC,yBAAyB,CAAC,CA8MpC"}
package/dist/index.js CHANGED
@@ -4331,6 +4331,7 @@ function getShortCircuitMatches(routes) {
4331
4331
  }
4332
4332
  const NOT_FOUND_STATUS = 404;
4333
4333
  const LOADER_TIMEOUT_MS = 4e3;
4334
+ const IMMUTABLE_LAZY_ROUTE_KEYS = /* @__PURE__ */ new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
4334
4335
  const getErrorStatus = (error) => {
4335
4336
  if (!error) return void 0;
4336
4337
  const candidate = error?.reason ?? error;
@@ -4373,6 +4374,22 @@ async function applyRouteLoaders(req, dataRoutes) {
4373
4374
  loaderHeaders: {},
4374
4375
  actionHeaders: {}
4375
4376
  };
4377
+ const resolveLazyRoute = async (route) => {
4378
+ if (!route || typeof route !== "object") return;
4379
+ const lazy = route.lazy;
4380
+ if (typeof lazy !== "function") return;
4381
+ const lazyModule = await lazy();
4382
+ if (!lazyModule || typeof lazyModule !== "object") {
4383
+ route.lazy = void 0;
4384
+ return;
4385
+ }
4386
+ for (const [key, value] of Object.entries(lazyModule)) {
4387
+ if (IMMUTABLE_LAZY_ROUTE_KEYS.has(key)) continue;
4388
+ if (route[key] !== void 0) continue;
4389
+ route[key] = value;
4390
+ }
4391
+ route.lazy = void 0;
4392
+ };
4376
4393
  const matches = matchRoutes(dataRoutes, location);
4377
4394
  if (!matches || matches.length === 0) {
4378
4395
  const error = {
@@ -4405,6 +4422,7 @@ async function applyRouteLoaders(req, dataRoutes) {
4405
4422
  };
4406
4423
  }
4407
4424
  const runLoaderWithTimeout = async (route, params) => {
4425
+ await resolveLazyRoute(route);
4408
4426
  if (!route.loader) return null;
4409
4427
  let timeoutId;
4410
4428
  const timeoutPromise = new Promise((_, reject) => {
@@ -4645,6 +4663,7 @@ const renderRtsHydrationScript = (data) => {
4645
4663
  return `<script>window.${STATIC_RPCBASE_RTS_HYDRATION_DATA_KEY}=${serialized};<\/script>`;
4646
4664
  };
4647
4665
  const RTS_SSR_PREPASS_TIMEOUT_MS = 4e3;
4666
+ const SSR_IDENTIFIER_PREFIX$1 = "rb-";
4648
4667
  const runRtsPrepass = async (element) => {
4649
4668
  return await new Promise((resolve) => {
4650
4669
  let isDone = false;
@@ -4672,6 +4691,7 @@ const runRtsPrepass = async (element) => {
4672
4691
  pipe,
4673
4692
  abort
4674
4693
  } = renderToPipeableStream(element, {
4694
+ identifierPrefix: SSR_IDENTIFIER_PREFIX$1,
4675
4695
  onAllReady() {
4676
4696
  if (isDone) return;
4677
4697
  pipe(sink);
@@ -4763,6 +4783,7 @@ async function renderSSR(req, dataRoutes) {
4763
4783
  };
4764
4784
  }
4765
4785
  const ABORT_DELAY_MS = 1e4;
4786
+ const SSR_IDENTIFIER_PREFIX = "rb-";
4766
4787
  const APP_HTML_PLACEHOLDER = "<!--app-html-->";
4767
4788
  const DEFAULT_SERVER_ERROR_MESSAGE = "We couldn't render this page on the server. Please refresh and try again.";
4768
4789
  const FALLBACK_ERROR_TEMPLATE_START = `<!doctype html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width,initial-scale=1" /><title>Server error</title><style>body{margin:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;background:#0b1021;color:#eef1f7;display:flex;align-items:center;justify-content:center;min-height:100vh;}main{max-width:420px;padding:32px;background:rgba(255,255,255,0.04);border:1px solid rgba(255,255,255,0.08);border-radius:14px;box-shadow:0 25px 50px rgba(0,0,0,0.35);}h1{font-size:24px;margin:0 0 8px;}p{margin:0 0 12px;line-height:1.5;}code{background:rgba(255,255,255,0.08);padding:2px 6px;border-radius:6px;font-size:12px;}</style></head><body><main>`;
@@ -4942,6 +4963,7 @@ const ssrMiddleware = ({
4942
4963
  pipe,
4943
4964
  abort
4944
4965
  } = renderToPipeableStream(element, {
4966
+ identifierPrefix: SSR_IDENTIFIER_PREFIX,
4945
4967
  onShellError(error) {
4946
4968
  if (error instanceof Error) {
4947
4969
  viteInstance?.ssrFixStacktrace(error);