rari 0.10.13 → 0.10.15
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/cli.mjs +1 -1
- package/dist/client.d.mts +2 -2
- package/dist/client.mjs +3 -3
- package/dist/index.d.mts +4 -6
- package/dist/index.mjs +1 -1
- package/dist/metadata-route-5FF9DZGf.d.mts +72 -0
- package/dist/proxy/RariRequest.d.mts +1 -1
- package/dist/proxy/RariResponse.d.mts +1 -1
- package/dist/proxy/runtime-executor.d.mts +3 -1
- package/dist/proxy/runtime-executor.mjs +1 -1
- package/dist/{railway-UP19UVM3.mjs → railway-DnLx3pww.mjs} +1 -1
- package/dist/{render-CL95kAwR.mjs → render-CyCw8V_Z.mjs} +1 -1
- package/dist/router.d.mts +1 -1
- package/dist/router.mjs +1 -1
- package/dist/runtime/AppRouterProvider.mjs +1 -1
- package/dist/runtime/entry-client.mjs +2 -2
- package/dist/runtime/react-server-dom-rari-client.mjs +1 -1
- package/dist/runtime/react-server-dom-shim.d.mts +3 -3
- package/dist/runtime/react-server-dom-shim.mjs +1 -1
- package/dist/runtime/rsc-client-runtime.mjs +2 -2
- package/dist/{server-build-BbPx0SOe.mjs → server-build-V7WVXFpd.mjs} +10 -12
- package/dist/utils-dqnEOG_U-sHhPlm_u.mjs +1 -0
- package/dist/vite.d.mts +127 -7
- package/dist/vite.mjs +79 -1
- package/package.json +15 -15
- package/dist/index-DUhlny9p.d.mts +0 -195
- package/dist/utils-BTyXoHUx-BVw3bTZu.mjs +0 -1
- package/dist/vite-B-jD5pXc.mjs +0 -79
- /package/dist/{get-client-component-DuyG4UOi.mjs → get-client-component-CpMI09nb.mjs} +0 -0
- /package/dist/{navigate-BTY-aYi_.mjs → navigate-DPJioMXn.mjs} +0 -0
- /package/dist/{preload-components-RxFu9xLE.mjs → preload-components-5Y8ZOaFG.mjs} +0 -0
- /package/dist/{robots-generator-CA3pR8ZY.mjs → robots-generator-Bo5MHa-v.mjs} +0 -0
- /package/dist/{server-config-CDW6dUXy.d.mts → server-config-DIRkP4VR.d.mts} +0 -0
- /package/dist/{sitemap-generator-yW1rcKZr.mjs → sitemap-generator-D_gTjklw.mjs} +0 -0
- /package/dist/{types-DYoUsyof.d.mts → types-By2lPZfR.d.mts} +0 -0
- /package/dist/{types-BV0iON-q.d.mts → types-CBPVPFdE.d.mts} +0 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{getBinaryPath as e,getInstallationInstructions as t}from"./platform.mjs";import{existsSync as n,readFileSync as r,realpathSync as i}from"node:fs";import{resolve as a}from"node:path";import o from"node:process";import{spawn as s}from"node:child_process";import{fileURLToPath as c}from"node:url";import{styleText as l}from"node:util";function u(e){console.warn(`${l(`blue`,`info`)} ${e}`)}function d(e){console.warn(`${l(`green`,`✓`)} ${e}`)}function f(e){console.error(`${l(`red`,`✗`)} ${e}`)}function p(e){console.warn(`${l(`yellow`,`⚠`)} ${e}`)}const m=/^([^=]+)=(.*)$/;function h(){let e=a(o.cwd(),`.env`);if(n(e)){let t=r(e,`utf-8`);for(let e of t.split(`
|
|
3
|
-
`)){let t=e.trim();if(!t||t.startsWith(`#`))continue;let n=t.match(m);if(n){let[,e,t]=n,r=e.trim(),i=t.trim();(i.startsWith(`"`)&&i.endsWith(`"`)||i.startsWith(`'`)&&i.endsWith(`'`))&&(i=i.slice(1,-1)),o.env[r]||(o.env[r]=i)}}}}h();const[,,g,..._]=o.argv;function v(){let e=o.cwd(),t=a(`/`),i=0;for(;e!==t&&i<20;){if(i++,n(a(e,`pnpm-lock.yaml`)))return`pnpm`;if(n(a(e,`yarn.lock`)))return`yarn`;if(n(a(e,`bun.lockb`)))return`bun`;if(n(a(e,`package-lock.json`)))return`npm`;try{let t=a(e,`package.json`);if(n(t)){let e=JSON.parse(r(t,`utf-8`));if(e.packageManager?.startsWith(`pnpm`))return`pnpm`;if(e.packageManager?.startsWith(`yarn`))return`yarn`;if(e.packageManager?.startsWith(`bun`))return`bun`;if(e.packageManager?.startsWith(`npm`))return`npm`}}catch{}let t=a(e,`..`);if(t===e)break;e=t}return`npm`}function y(){let e=v(),t=o.platform===`win32`;switch(e){case`bun`:return t?`bun.cmd`:`bun`;case`pnpm`:return t?`pnpm.cmd`:`pnpm`;case`yarn`:return t?`yarn.cmd`:`yarn`;default:return t?`npx.cmd`:`npx`}}function b(e,t,n={}){let r=o.platform===`win32`;if(e===`npx`){let e=y();if(e.includes(`bun`))return s(r?`bunx.cmd`:`bunx`,t,{...n,shell:r});if(e.includes(`pnpm`))return s(e,[`exec`,...t],{...n,shell:r});if(e.includes(`yarn`))return s(e,[`dlx`,...t],{...n,shell:r})}return r&&e===`npx`?s(`npx.cmd`,t,{...n,shell:!0}):s(e,t,n)}function x(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function S(){return!!(o.env.RAILWAY_ENVIRONMENT||o.env.RAILWAY_PROJECT_ID||o.env.RAILWAY_SERVICE_ID)}function C(){return!!(o.env.RENDER||o.env.RENDER_SERVICE_ID||o.env.RENDER_SERVICE_NAME)}function w(){return S()||C()}function T(){return S()?`Railway`:C()?`Render`:`local`}function E(){return{port:o.env.PORT||o.env.RSC_PORT||`3000`,mode:o.env.NODE_ENV||`production`,host:w()?`0.0.0.0`:`127.0.0.1`}}async function D(){let{existsSync:e,rmSync:t}=await import(`node:fs`),{resolve:n}=await import(`node:path`),r=n(o.cwd(),`dist`);e(r)&&(u(`Cleaning dist folder...`),t(r,{recursive:!0,force:!0})),u(`Type checking...`);let i=b(`npx`,[`tsgo`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{i.on(`exit`,n=>{n===0?(d(`Type check passed`),e()):(f(`Type check failed with code ${n}`),t(Error(`Type check failed with code ${n}`)))}),i.on(`error`,t)}),u(`Building for production...`);let a=b(`npx`,[`vite`,`build`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{a.on(`exit`,n=>{n===0?(d(`Build complete`),e()):(f(`Build failed with code ${n}`),t(Error(`Build failed with code ${n}`)))}),a.on(`error`,t)}),await O()}async function O(){if(n(a(o.cwd(),`dist`,`server`,`image.json`))&&n(a(o.cwd(),`public`)))try{let t=s(e(),[`optimize-images`],{stdio:`inherit`,cwd:o.cwd(),shell:!1});await new Promise(e=>{t.on(`exit`,t=>{t===0||p(`Image pre-optimization exited with code ${t}`),e()}),t.on(`error`,t=>{p(`Image pre-optimization error: ${x(t)}`),e()})})}catch(e){p(`Could not pre-optimize images: ${x(e)}`)}}async function k(){let{existsSync:e}=await import(`node:fs`),{resolve:t}=await import(`node:path`);if(!e(t(o.cwd(),`dist`))){u(`First run detected - building project...`);let e=b(`npx`,[`vite`,`build`,`--mode`,`development`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((t,n)=>{e.on(`exit`,e=>{e===0?(d(`Initial build complete`),t()):(f(`Build failed with code ${e}`),n(Error(`Build failed with code ${e}`)))}),e.on(`error`,n)})}u(`Starting Vite dev server...`);let n=b(`npx`,[`vite`],{stdio:`inherit`,cwd:o.cwd()}),r=()=>{u(`Shutting down dev server...`),n.kill(`SIGTERM`)};return o.on(`SIGINT`,r),o.on(`SIGTERM`,r),n.on(`error`,e=>{f(`Failed to start Vite: ${e.message}`),o.exit(1)}),n.on(`exit`,e=>{e!==0&&e!==null&&(f(`Vite exited with code ${e}`),o.exit(e))}),new Promise(()=>{})}async function A(){let n;try{n=e()}catch{f(`Failed to obtain rari binary`),f(t()),o.exit(1)}let{port:r,mode:i,host:a}=E();if(w()){let e=T();u(`${e} environment detected`),u(`Starting rari server for ${e} deployment...`),u(`Mode: ${i}, Host: ${a}, Port: ${r}`),u(`using binary: ${n}`)}let c=s(n,[`--mode`,i,`--port`,r,`--host`,a],{stdio:`inherit`,cwd:o.cwd(),env:{...o.env,RUST_LOG:o.env.RUST_LOG||`error`}}),l=()=>{u(`shutting down...`),c.kill(`SIGTERM`)};return o.on(`SIGINT`,l),o.on(`SIGTERM`,l),c.on(`error`,e=>{f(`Failed to start rari server: ${e.message}`),e.message.includes(`ENOENT`)&&f(`Binary not found. Please ensure rari is properly installed.`),o.exit(1)}),c.on(`exit`,(e,t)=>{t?u(`server stopped by signal ${t}`):e===0?d(`server stopped successfully`):(f(`server exited with code ${e}`),o.exit(e||1))}),new Promise(()=>{})}async function j(){u(`Setting up Railway deployment...`),w()&&(f(`Already running in ${T()} environment. Use "rari start" instead.`),o.exit(1));let{createRailwayDeployment:e}=await import(`./railway-
|
|
3
|
+
`)){let t=e.trim();if(!t||t.startsWith(`#`))continue;let n=t.match(m);if(n){let[,e,t]=n,r=e.trim(),i=t.trim();(i.startsWith(`"`)&&i.endsWith(`"`)||i.startsWith(`'`)&&i.endsWith(`'`))&&(i=i.slice(1,-1)),o.env[r]||(o.env[r]=i)}}}}h();const[,,g,..._]=o.argv;function v(){let e=o.cwd(),t=a(`/`),i=0;for(;e!==t&&i<20;){if(i++,n(a(e,`pnpm-lock.yaml`)))return`pnpm`;if(n(a(e,`yarn.lock`)))return`yarn`;if(n(a(e,`bun.lockb`)))return`bun`;if(n(a(e,`package-lock.json`)))return`npm`;try{let t=a(e,`package.json`);if(n(t)){let e=JSON.parse(r(t,`utf-8`));if(e.packageManager?.startsWith(`pnpm`))return`pnpm`;if(e.packageManager?.startsWith(`yarn`))return`yarn`;if(e.packageManager?.startsWith(`bun`))return`bun`;if(e.packageManager?.startsWith(`npm`))return`npm`}}catch{}let t=a(e,`..`);if(t===e)break;e=t}return`npm`}function y(){let e=v(),t=o.platform===`win32`;switch(e){case`bun`:return t?`bun.cmd`:`bun`;case`pnpm`:return t?`pnpm.cmd`:`pnpm`;case`yarn`:return t?`yarn.cmd`:`yarn`;default:return t?`npx.cmd`:`npx`}}function b(e,t,n={}){let r=o.platform===`win32`;if(e===`npx`){let e=y();if(e.includes(`bun`))return s(r?`bunx.cmd`:`bunx`,t,{...n,shell:r});if(e.includes(`pnpm`))return s(e,[`exec`,...t],{...n,shell:r});if(e.includes(`yarn`))return s(e,[`dlx`,...t],{...n,shell:r})}return r&&e===`npx`?s(`npx.cmd`,t,{...n,shell:!0}):s(e,t,n)}function x(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function S(){return!!(o.env.RAILWAY_ENVIRONMENT||o.env.RAILWAY_PROJECT_ID||o.env.RAILWAY_SERVICE_ID)}function C(){return!!(o.env.RENDER||o.env.RENDER_SERVICE_ID||o.env.RENDER_SERVICE_NAME)}function w(){return S()||C()}function T(){return S()?`Railway`:C()?`Render`:`local`}function E(){return{port:o.env.PORT||o.env.RSC_PORT||`3000`,mode:o.env.NODE_ENV||`production`,host:w()?`0.0.0.0`:`127.0.0.1`}}async function D(){let{existsSync:e,rmSync:t}=await import(`node:fs`),{resolve:n}=await import(`node:path`),r=n(o.cwd(),`dist`);e(r)&&(u(`Cleaning dist folder...`),t(r,{recursive:!0,force:!0})),u(`Type checking...`);let i=b(`npx`,[`tsgo`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{i.on(`exit`,n=>{n===0?(d(`Type check passed`),e()):(f(`Type check failed with code ${n}`),t(Error(`Type check failed with code ${n}`)))}),i.on(`error`,t)}),u(`Building for production...`);let a=b(`npx`,[`vite`,`build`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{a.on(`exit`,n=>{n===0?(d(`Build complete`),e()):(f(`Build failed with code ${n}`),t(Error(`Build failed with code ${n}`)))}),a.on(`error`,t)}),await O()}async function O(){if(n(a(o.cwd(),`dist`,`server`,`image.json`))&&n(a(o.cwd(),`public`)))try{let t=s(e(),[`optimize-images`],{stdio:`inherit`,cwd:o.cwd(),shell:!1});await new Promise(e=>{t.on(`exit`,t=>{t===0||p(`Image pre-optimization exited with code ${t}`),e()}),t.on(`error`,t=>{p(`Image pre-optimization error: ${x(t)}`),e()})})}catch(e){p(`Could not pre-optimize images: ${x(e)}`)}}async function k(){let{existsSync:e}=await import(`node:fs`),{resolve:t}=await import(`node:path`);if(!e(t(o.cwd(),`dist`))){u(`First run detected - building project...`);let e=b(`npx`,[`vite`,`build`,`--mode`,`development`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((t,n)=>{e.on(`exit`,e=>{e===0?(d(`Initial build complete`),t()):(f(`Build failed with code ${e}`),n(Error(`Build failed with code ${e}`)))}),e.on(`error`,n)})}u(`Starting Vite dev server...`);let n=b(`npx`,[`vite`],{stdio:`inherit`,cwd:o.cwd()}),r=()=>{u(`Shutting down dev server...`),n.kill(`SIGTERM`)};return o.on(`SIGINT`,r),o.on(`SIGTERM`,r),n.on(`error`,e=>{f(`Failed to start Vite: ${e.message}`),o.exit(1)}),n.on(`exit`,e=>{e!==0&&e!==null&&(f(`Vite exited with code ${e}`),o.exit(e))}),new Promise(()=>{})}async function A(){let n;try{n=e()}catch{f(`Failed to obtain rari binary`),f(t()),o.exit(1)}let{port:r,mode:i,host:a}=E();if(w()){let e=T();u(`${e} environment detected`),u(`Starting rari server for ${e} deployment...`),u(`Mode: ${i}, Host: ${a}, Port: ${r}`),u(`using binary: ${n}`)}let c=s(n,[`--mode`,i,`--port`,r,`--host`,a],{stdio:`inherit`,cwd:o.cwd(),env:{...o.env,RUST_LOG:o.env.RUST_LOG||`error`}}),l=()=>{u(`shutting down...`),c.kill(`SIGTERM`)};return o.on(`SIGINT`,l),o.on(`SIGTERM`,l),c.on(`error`,e=>{f(`Failed to start rari server: ${e.message}`),e.message.includes(`ENOENT`)&&f(`Binary not found. Please ensure rari is properly installed.`),o.exit(1)}),c.on(`exit`,(e,t)=>{t?u(`server stopped by signal ${t}`):e===0?d(`server stopped successfully`):(f(`server exited with code ${e}`),o.exit(e||1))}),new Promise(()=>{})}async function j(){u(`Setting up Railway deployment...`),w()&&(f(`Already running in ${T()} environment. Use "rari start" instead.`),o.exit(1));let{createRailwayDeployment:e}=await import(`./railway-DnLx3pww.mjs`);await e()}async function M(){u(`Setting up Render deployment...`),w()&&(f(`Already running in ${T()} environment. Use "rari start" instead.`),o.exit(1));let{createRenderDeployment:e}=await import(`./render-CyCw8V_Z.mjs`);await e()}async function N(){switch(g){case void 0:case`help`:case`--help`:case`-h`:console.warn(`${l(`bold`,`rari CLI`)}
|
|
4
4
|
|
|
5
5
|
${l(`bold`,`Usage:`)}
|
|
6
6
|
${l(`cyan`,`rari dev`)} Start the development server with Vite
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as extractServerPropsWithCache, S as extractServerProps, T as hasServerSideDataFetching, _ as ServerSidePropsResult, a as ServerSpamBlockerConfig, b as clearPropsCacheForComponent, c as ErrorBoundary, d as NotFound, f as RuntimeClient, g as MetadataResult, h as createLoadingBoundary, i as ServerRateLimitConfig, l as HttpRuntimeClient, m as createHttpRuntimeClient, o as DefaultError, p as createErrorBoundary, r as ServerConfig, s as DefaultLoading, t as ServerCSPConfig, u as LoadingSpinner, v as StaticParamsResult, w as extractStaticParams, x as extractMetadata, y as clearPropsCache } from "./server-config-
|
|
2
|
-
import { a as ErrorProps, c as LayoutEntry, f as NotFoundEntry, h as RouteSegmentType, i as ErrorEntry, m as RouteSegment, n as AppRouteManifest, o as GenerateMetadata, r as AppRouteMatch, s as GenerateStaticParams, t as AppRouteEntry, u as LoadingEntry } from "./types-
|
|
1
|
+
import { C as extractServerPropsWithCache, S as extractServerProps, T as hasServerSideDataFetching, _ as ServerSidePropsResult, a as ServerSpamBlockerConfig, b as clearPropsCacheForComponent, c as ErrorBoundary, d as NotFound, f as RuntimeClient, g as MetadataResult, h as createLoadingBoundary, i as ServerRateLimitConfig, l as HttpRuntimeClient, m as createHttpRuntimeClient, o as DefaultError, p as createErrorBoundary, r as ServerConfig, s as DefaultLoading, t as ServerCSPConfig, u as LoadingSpinner, v as StaticParamsResult, w as extractStaticParams, x as extractMetadata, y as clearPropsCache } from "./server-config-DIRkP4VR.mjs";
|
|
2
|
+
import { a as ErrorProps, c as LayoutEntry, f as NotFoundEntry, h as RouteSegmentType, i as ErrorEntry, m as RouteSegment, n as AppRouteManifest, o as GenerateMetadata, r as AppRouteMatch, s as GenerateStaticParams, t as AppRouteEntry, u as LoadingEntry } from "./types-By2lPZfR.mjs";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Component, ErrorInfo, ReactNode } from "react";
|
|
5
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
package/dist/client.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,l as s,m as c,n as l,o as u,p as d,r as f,s as p,t as m,u as h}from"./runtime-client-Bg4V1Ksp.mjs";import{i as g,t as _}from"./navigate-BTY-aYi_.mjs";import{Component as v,useEffect as y,useLayoutEffect as b,useRef as x,useState as S}from"react";import{Fragment as C,jsx as w,jsxs as T}from"react/jsx-runtime";function E(e,t,n={}){let r=null,i=0,a=0,o=null,s=null,{leading:c=!1,trailing:l=!0,maxWait:u}=n;function d(t){let n=o,r=s;return o=null,s=null,a=t,e.apply(r,n)}function f(e){let n=e-i,r=e-a;return i===0||n>=t||n<0||u!==void 0&&r>=u}function p(){let e=Date.now();if(f(e))return h(e);let n=e-i,o=e-a,s=t-n,c=u===void 0?1/0:u-o,l=Math.min(s,c);r=setTimeout(p,l)}function m(e){return a=e,r=setTimeout(p,t),c?d(e):void 0}function h(e){if(r=null,l&&o)return d(e);o=null,s=null}function g(){r!==null&&clearTimeout(r),a=0,o=null,i=0,s=null,r=null}function _(){return r===null?void 0:h(Date.now())}function v(){return r!==null}function y(...e){let n=Date.now(),a=f(n);if(o=e,s=this,i=n,a){if(r===null)return m(i);if(u!==void 0)return r=setTimeout(p,t),d(i)}r===null&&(r=setTimeout(p,t))}return y.cancel=g,y.flush=_,y.pending=v,y}function D(e,t){if(e instanceof Error&&e.name===`AbortError`)return{type:`abort`,message:`Navigation was cancelled`,originalError:e,url:t,timestamp:Date.now(),retryable:!1};if(e instanceof Error&&e.message.includes(`timeout`))return{type:`timeout`,message:`Navigation request timed out`,originalError:e,url:t,timestamp:Date.now(),retryable:!0};if(e instanceof Error&&`status`in e){let n=e.status;return n===404?{type:`not-found`,message:`Page not found`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!1}:n>=500?{type:`server-error`,message:`Server error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!0}:{type:`fetch-error`,message:`HTTP error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:n>=500}}return e instanceof TypeError&&e.message.includes(`fetch`)?{type:`network-error`,message:`Network error - check your connection`,originalError:e,url:t,timestamp:Date.now(),retryable:!0}:e instanceof SyntaxError||e instanceof Error&&e.message.includes(`parse`)?{type:`parse-error`,message:`Failed to parse server response`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}:{type:`fetch-error`,message:e instanceof Error?e.message:`Unknown error occurred`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}}var O=class{options;retryCount;constructor(e={}){this.options={timeout:e.timeout??1e4,maxRetries:e.maxRetries??3,onError:e.onError??(()=>{}),onRetry:e.onRetry??(()=>{})},this.retryCount=new Map}handleError(e,t){let n=D(e,t);return this.options.onError(n),console.error(`[rari] Navigation:`,n.type,n.message,{url:n.url,statusCode:n.statusCode,retryable:n.retryable}),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:navigation-error`,{detail:n})),n}canRetry(e,t){return e.retryable?(this.retryCount.get(t)??0)<this.options.maxRetries:!1}incrementRetry(e){let t=(this.retryCount.get(e)??0)+1;return this.retryCount.set(e,t),this.options.onRetry(t,{type:`fetch-error`,message:`Retry attempt ${t}`,url:e,timestamp:Date.now(),retryable:!0}),t}resetRetry(e){this.retryCount.delete(e)}getRetryCount(e){return this.retryCount.get(e)??0}clearRetries(){this.retryCount.clear()}};const k=/(^\/+)|(\/+$)/g;function A(e){let t=e.replace(k,``);return t?t.split(`/`):[]}function j(e,t,n){let r=A(n),i={},a=0;for(let e=0;e<t.length;e++){let n=t[e];if(a>=r.length){if(n.type===`optional-catch-all`){n.param&&(i[n.param]=[]);continue}return null}switch(n.type){case`static`:if(r[a]!==n.value)return null;a++;break;case`dynamic`:n.param&&(i[n.param]=r[a]),a++;break;case`catch-all`:case`optional-catch-all`:n.param&&(i[n.param]=r.slice(a)),a=r.length;break}}return a===r.length?i:null}function M(e){if(!e||e===`/`)return`/`;let t=e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t.startsWith(`/`)||(t=`/${t}`),t}function N(e,t){try{return new URL(e,t||window.location.origin).origin!==(t||window.location.origin)}catch{return!1}}function P(e){try{let t=new URL(e,window.location.origin);return t.pathname+t.hash}catch{return e}}function F({error:e,onRetry:t,onReload:n,onDismiss:r,retryCount:i=0,maxRetries:a=3}){let o=e.retryable&&i<a;return w(`div`,{style:{position:`fixed`,top:0,left:0,right:0,bottom:0,background:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:1e4,padding:`20px`},onClick:e=>{e.target===e.currentTarget&&r&&r()},children:T(`div`,{style:{background:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`500px`,width:`100%`,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.15)`},onClick:e=>e.stopPropagation(),children:[T(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,marginBottom:`16px`},children:[w(`span`,{style:{fontSize:`32px`},children:(()=>{switch(e.type){case`timeout`:return`⏱️`;case`network-error`:return`📡`;case`not-found`:return`🔍`;case`server-error`:return`⚠️`;case`parse-error`:return`📄`;case`abort`:return`🚫`;default:return`❌`}})()}),w(`h2`,{style:{margin:0,fontSize:`20px`,fontWeight:`600`,color:`#1f2937`},children:`Navigation Error`})]}),w(`p`,{style:{margin:`0 0 16px 0`,fontSize:`15px`,lineHeight:`1.5`,color:`#4b5563`},children:(()=>{switch(e.type){case`timeout`:return`The page took too long to load. Please try again.`;case`network-error`:return`Unable to connect to the server. Please check your internet connection.`;case`not-found`:return`The page you're looking for doesn't exist.`;case`server-error`:return`The server encountered an error. Please try again in a moment.`;case`parse-error`:return`Unable to load the page content. Please try reloading.`;case`abort`:return`Navigation was cancelled.`;default:return e.message||`An unexpected error occurred.`}})()}),e.url&&T(`details`,{style:{marginBottom:`16px`,fontSize:`13px`,color:`#6b7280`},children:[w(`summary`,{style:{cursor:`pointer`,userSelect:`none`,marginBottom:`8px`},children:`Technical details`}),T(`div`,{style:{padding:`12px`,background:`#f9fafb`,borderRadius:`4px`,fontFamily:`monospace`,fontSize:`12px`,wordBreak:`break-all`},children:[T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`URL:`}),` `,e.url]}),e.statusCode&&T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Status:`}),` `,e.statusCode]}),T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Type:`}),` `,e.type]}),e.originalError&&T(`div`,{children:[w(`strong`,{children:`Error:`}),` `,e.originalError.message]})]})]}),o&&i>0&&T(`div`,{style:{marginBottom:`16px`,padding:`8px 12px`,background:`#fef3c7`,border:`1px solid #fbbf24`,borderRadius:`4px`,fontSize:`13px`,color:`#92400e`},children:[`Retry attempt`,` `,i,` `,`of`,` `,a]}),T(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[o&&t&&w(`button`,{onClick:t,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#3b82f6`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#2563eb`},onMouseLeave:e=>{e.currentTarget.style.background=`#3b82f6`},children:`Try Again`}),n&&w(`button`,{onClick:n,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#6b7280`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.background=`#6b7280`},children:`Reload Page`}),r&&w(`button`,{onClick:r,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`transparent`,color:`#6b7280`,border:`1px solid #d1d5db`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`all 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#f9fafb`,e.currentTarget.style.borderColor=`#9ca3af`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.borderColor=`#d1d5db`},children:`Dismiss`})]}),w(`p`,{style:{marginTop:`16px`,marginBottom:0,fontSize:`12px`,color:`#9ca3af`,textAlign:`center`},children:`Your current page is still available below this message`})]})})}const I=new class{cache=new Map;pendingRequests=new Map;async get(e){let t=this.cache.get(e);if(t)return t;let n=this.pendingRequests.get(e);if(n)return n;let r=this.fetchRouteInfo(e);this.pendingRequests.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pendingRequests.delete(e)}}async fetchRouteInfo(e){let t={path:e},n=await fetch(`/_rari/route-info`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=null;try{e=await n.json()}catch{}throw e?.error?Error(e.error):Error(`Failed to fetch route info: ${n.status} ${n.statusText}`)}let r=n.clone();try{return await n.json()}catch(t){try{let e=await r.text();return JSON.parse(e)}catch(n){throw console.error(`[RouteInfo] Failed to parse response:`,{error:t,parseError:n,path:e}),Error(`Failed to parse route info response`)}}}clear(){this.cache.clear(),this.pendingRequests.clear()}invalidate(e){this.cache.delete(e)}};if(typeof window<`u`){let e=window[`~rari`]||{};window[`~rari`]||(window[`~rari`]=e),e.routeInfoCache=I}var L=class{stateHistory;routeAccessOrder;maxHistorySize;scrollableSelector;constructor(e={}){this.stateHistory=new Map,this.routeAccessOrder=[],this.maxHistorySize=e.maxHistorySize||50,this.scrollableSelector=e.scrollableSelector||`[data-scrollable], .scrollable, [style*="overflow"]`}captureState(e){let t={scrollPositions:this.captureScrollPositions(),formData:this.captureFormData(),focusedElement:this.captureFocusedElement()};return this.storeState(e,t),t}captureScrollPositions(){let e=new Map;try{e.set(`window`,{x:window.scrollX,y:window.scrollY,element:`window`}),document.querySelectorAll(this.scrollableSelector).forEach((t,n)=>{if(t instanceof HTMLElement){let r=t.id||`scrollable-${n}`;(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&e.set(r,{x:t.scrollLeft,y:t.scrollTop,element:r})}})}catch{}return e}captureFormData(){let e=new Map;try{document.querySelectorAll(`form`).forEach((t,n)=>{let r=t.id||t.name||`form-${n}`,i=new FormData(t);i.entries().next().done||e.set(r,i)})}catch{}return e}captureFocusedElement(){try{let e=document.activeElement;if(e&&e!==document.body){if(e.id)return`#${e.id}`;if((e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.name)return`[name="${e.name}"]`}}catch{}return null}storeState(e,t){let n=this.routeAccessOrder.indexOf(e);for(n!==-1&&this.routeAccessOrder.splice(n,1),this.routeAccessOrder.push(e),this.stateHistory.set(e,t);this.routeAccessOrder.length>this.maxHistorySize;){let e=this.routeAccessOrder.shift();e&&this.stateHistory.delete(e)}}getHistorySize(){return this.stateHistory.size}hasState(e){return this.stateHistory.has(e)}getState(e){return this.stateHistory.get(e)}clearAll(){this.stateHistory.clear(),this.routeAccessOrder=[]}clearState(e){this.stateHistory.delete(e);let t=this.routeAccessOrder.indexOf(e);t!==-1&&this.routeAccessOrder.splice(t,1)}restoreState(e){let t=this.stateHistory.get(e);if(!t)return!1;let n=!0;return this.restoreScrollPositions(t.scrollPositions)||(n=!1),this.restoreFormData(t.formData)||(n=!1),t.focusedElement&&this.restoreFocus(t.focusedElement),n}restoreScrollPositions(e){let t=!0;try{e.forEach((e,n)=>{try{if(n===`window`)window.scrollTo(e.x,e.y);else{let r=document.getElementById(n)||document.querySelector(`[data-scrollable-id="${n}"]`);r instanceof HTMLElement?(r.scrollLeft=e.x,r.scrollTop=e.y):t=!1}}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore scroll positions:`,e),t=!1}return t}restoreFormData(e){let t=!0;try{e.forEach((e,n)=>{try{let r=document.getElementById(n)||document.querySelector(`form[name="${n}"]`)||document.querySelectorAll(`form`)[Number.parseInt(n.replace(`form-`,``),10)];r instanceof HTMLFormElement?e.forEach((e,n)=>{try{let t=r.elements.namedItem(n);t instanceof RadioNodeList?t.forEach(t=>{t instanceof HTMLInputElement&&(t.type===`radio`||t.type===`checkbox`?t.checked=t.value===e:t.value=e)}):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t instanceof HTMLInputElement&&(t.type===`checkbox`||t.type===`radio`)?t.checked=t.value===e:t.value=e)}catch{t=!1}}):t=!1}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore form data:`,e),t=!1}return t}restoreFocus(e){try{let t=document.querySelector(e);t instanceof HTMLElement&&requestAnimationFrame(()=>{try{t.focus()}catch{}})}catch{}}};function R(e){e.title&&(document.title=e.title);let t=(e,t)=>{let n=document.querySelector(e);if(n)t.content&&n.setAttribute(`content`,t.content);else{n=document.createElement(`meta`);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);document.head.appendChild(n)}};if(e.description&&t(`meta[name="description"]`,{name:`description`,content:e.description}),e.keywords&&e.keywords.length>0&&t(`meta[name="keywords"]`,{name:`keywords`,content:e.keywords.join(`, `)}),e.viewport&&t(`meta[name="viewport"]`,{name:`viewport`,content:e.viewport}),e.canonical){let t=document.querySelector(`link[rel="canonical"]`);t||(t=document.createElement(`link`),t.setAttribute(`rel`,`canonical`),document.head.appendChild(t)),t.setAttribute(`href`,e.canonical)}if(e.robots){let n=[];e.robots.index!==void 0&&n.push(e.robots.index?`index`:`noindex`),e.robots.follow!==void 0&&n.push(e.robots.follow?`follow`:`nofollow`),e.robots.nocache&&n.push(`nocache`),n.length>0&&t(`meta[name="robots"]`,{name:`robots`,content:n.join(`, `)})}if(e.openGraph){let n=e.openGraph;if(n.title&&t(`meta[property="og:title"]`,{property:`og:title`,content:n.title}),n.description&&t(`meta[property="og:description"]`,{property:`og:description`,content:n.description}),n.url&&t(`meta[property="og:url"]`,{property:`og:url`,content:n.url}),n.siteName&&t(`meta[property="og:site_name"]`,{property:`og:site_name`,content:n.siteName}),n.type&&t(`meta[property="og:type"]`,{property:`og:type`,content:n.type}),n.images&&n.images.length>0){document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`property`,`og:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}if(e.twitter){let n=e.twitter;if(n.card&&t(`meta[name="twitter:card"]`,{name:`twitter:card`,content:n.card}),n.site&&t(`meta[name="twitter:site"]`,{name:`twitter:site`,content:n.site}),n.creator&&t(`meta[name="twitter:creator"]`,{name:`twitter:creator`,content:n.creator}),n.title&&t(`meta[name="twitter:title"]`,{name:`twitter:title`,content:n.title}),n.description&&t(`meta[name="twitter:description"]`,{name:`twitter:description`,content:n.description}),n.images&&n.images.length>0){document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`name`,`twitter:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}}function z({children:e,initialRoute:t,staleWindowMs:n=3e4}){let[r,i]=S(()=>({currentRoute:M(t),navigationId:0,error:null})),a=x(null),o=x(!0),s=x(M(t)),c=x(new O({timeout:1e4,maxRetries:3,onError:e=>{console.error(`[rari] Router: Navigation error:`,e)},onRetry:()=>{}})),l=x(new Map),u=x([]),d=x(new L({maxHistorySize:50})),f=x(null),p=x(n),m=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,h=()=>{a.current&&=(a.current.abort(),null)},v=()=>{for(let[,e]of l.current.entries())e.abortController.abort();l.current.clear()},D=(e,t)=>{l.current.delete(e),o.current&&r.navigationId===t&&i(e=>({...e}))},k=async e=>I.get(e),A=x(null),z=async(e,t={})=>{if(!e||typeof e!=`string`){console.error(`[rari] Router: Invalid navigation target:`,e);return}let[n,u]=e.includes(`#`)?e.split(`#`):[e,``],f=M(n);if(f===s.current&&!t.replace){if(u){let e=document.getElementById(u);e&&(e.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,`${f}#${u}`))}return}let p=l.current.get(f);if(p)return p.promise;let g=await k(f);v(),h();let _=new AbortController;a.current=_;let y=r.navigationId+1,b=(async()=>{let e=s.current;try{t.historyKey||d.current.captureState(e);let n=t.historyKey||m(),r={route:f,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:n},a=u?`${f}#${u}`:f;t.replace?window.history.replaceState(r,``,a):window.history.pushState(r,``,a);let p=window.location.origin+f,h=await fetch(p,{headers:{Accept:`text/x-component`},signal:_.signal});if(!h.ok&&h.status!==404)throw Error(`Failed to fetch: ${h.status}`);let v=new URL(h.url).pathname,b=v===f?f:v;if(v!==f){let e=u?`${v}#${u}`:v;window.history.replaceState({route:v,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:t.historyKey||m()},``,e)}if(_.signal.aborted){D(b,y);return}try{let e=h.headers.get(`x-rari-metadata`);if(e){let t=decodeURIComponent(e);R(JSON.parse(t))}}catch{}let x=h.headers.get(`x-render-mode`)===`streaming`,S=g?.segments&&j(``,g.segments,b)||{};if(x&&h.body){let n=h.body.getReader(),r=new TextDecoder,i=``;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;if(_.signal.aborted){await n.cancel(),D(b,y);return}i+=r.decode(t,{stream:!0});let a=i.split(`
|
|
2
|
-
`);i=a.pop()||``;for(let e of a)e.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:e}}))}i.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:i}})),window.dispatchEvent(new CustomEvent(`rari:navigate`,{detail:{from:e,to:b,navigationId:y,options:t,routeInfo:{...
|
|
3
|
-
`,this.state.error.stack]})]}),w(`button`,{onClick:this.reset,type:`button`,style:{padding:`6px 12px`,background:`#c00`,color:`white`,border:`none`,borderRadius:`4px`,cursor:`pointer`,fontSize:`14px`},children:`Try Again`})]}):this.props.children}};export{z as ClientRouter,
|
|
1
|
+
import{i as e,t}from"./navigate-DPJioMXn.mjs";import{a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./runtime-client-Bg4V1Ksp.mjs";import{Component as v,useEffect as y,useLayoutEffect as b,useRef as x,useState as S}from"react";import{Fragment as C,jsx as w,jsxs as T}from"react/jsx-runtime";function E(e,t,n={}){let r=null,i=0,a=0,o=null,s=null,{leading:c=!1,trailing:l=!0,maxWait:u}=n;function d(t){let n=o,r=s;return o=null,s=null,a=t,e.apply(r,n)}function f(e){let n=e-i,r=e-a;return i===0||n>=t||n<0||u!==void 0&&r>=u}function p(){let e=Date.now();if(f(e))return h(e);let n=e-i,o=e-a,s=t-n,c=u===void 0?1/0:u-o,l=Math.min(s,c);r=setTimeout(p,l)}function m(e){return a=e,r=setTimeout(p,t),c?d(e):void 0}function h(e){if(r=null,l&&o)return d(e);o=null,s=null}function g(){r!==null&&clearTimeout(r),a=0,o=null,i=0,s=null,r=null}function _(){return r===null?void 0:h(Date.now())}function v(){return r!==null}function y(...e){let n=Date.now(),a=f(n);if(o=e,s=this,i=n,a){if(r===null)return m(i);if(u!==void 0)return r=setTimeout(p,t),d(i)}r===null&&(r=setTimeout(p,t))}return y.cancel=g,y.flush=_,y.pending=v,y}function D(e,t){if(e instanceof Error&&e.name===`AbortError`)return{type:`abort`,message:`Navigation was cancelled`,originalError:e,url:t,timestamp:Date.now(),retryable:!1};if(e instanceof Error&&e.message.includes(`timeout`))return{type:`timeout`,message:`Navigation request timed out`,originalError:e,url:t,timestamp:Date.now(),retryable:!0};if(e instanceof Error&&`status`in e){let n=e.status;return n===404?{type:`not-found`,message:`Page not found`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!1}:n>=500?{type:`server-error`,message:`Server error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!0}:{type:`fetch-error`,message:`HTTP error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:n>=500}}return e instanceof TypeError&&e.message.includes(`fetch`)?{type:`network-error`,message:`Network error - check your connection`,originalError:e,url:t,timestamp:Date.now(),retryable:!0}:e instanceof SyntaxError||e instanceof Error&&e.message.includes(`parse`)?{type:`parse-error`,message:`Failed to parse server response`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}:{type:`fetch-error`,message:e instanceof Error?e.message:`Unknown error occurred`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}}var O=class{options;retryCount;constructor(e={}){this.options={timeout:e.timeout??1e4,maxRetries:e.maxRetries??3,onError:e.onError??(()=>{}),onRetry:e.onRetry??(()=>{})},this.retryCount=new Map}handleError(e,t){let n=D(e,t);return this.options.onError(n),console.error(`[rari] Navigation:`,n.type,n.message,{url:n.url,statusCode:n.statusCode,retryable:n.retryable}),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:navigation-error`,{detail:n})),n}canRetry(e,t){return e.retryable?(this.retryCount.get(t)??0)<this.options.maxRetries:!1}incrementRetry(e){let t=(this.retryCount.get(e)??0)+1;return this.retryCount.set(e,t),this.options.onRetry(t,{type:`fetch-error`,message:`Retry attempt ${t}`,url:e,timestamp:Date.now(),retryable:!0}),t}resetRetry(e){this.retryCount.delete(e)}getRetryCount(e){return this.retryCount.get(e)??0}clearRetries(){this.retryCount.clear()}};const k=/(^\/+)|(\/+$)/g;function A(e){let t=e.replace(k,``);return t?t.split(`/`):[]}function j(e,t,n){let r=A(n),i={},a=0;for(let e=0;e<t.length;e++){let n=t[e];if(a>=r.length){if(n.type===`optional-catch-all`){n.param&&(i[n.param]=[]);continue}return null}switch(n.type){case`static`:if(r[a]!==n.value)return null;a++;break;case`dynamic`:n.param&&(i[n.param]=r[a]),a++;break;case`catch-all`:case`optional-catch-all`:n.param&&(i[n.param]=r.slice(a)),a=r.length;break}}return a===r.length?i:null}function M(e){if(!e||e===`/`)return`/`;let t=e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t.startsWith(`/`)||(t=`/${t}`),t}function N(e,t){try{return new URL(e,t||window.location.origin).origin!==(t||window.location.origin)}catch{return!1}}function P(e){try{let t=new URL(e,window.location.origin);return t.pathname+t.hash}catch{return e}}function F({error:e,onRetry:t,onReload:n,onDismiss:r,retryCount:i=0,maxRetries:a=3}){let o=e.retryable&&i<a;return w(`div`,{style:{position:`fixed`,top:0,left:0,right:0,bottom:0,background:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:1e4,padding:`20px`},onClick:e=>{e.target===e.currentTarget&&r&&r()},children:T(`div`,{style:{background:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`500px`,width:`100%`,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.15)`},onClick:e=>e.stopPropagation(),children:[T(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,marginBottom:`16px`},children:[w(`span`,{style:{fontSize:`32px`},children:(()=>{switch(e.type){case`timeout`:return`⏱️`;case`network-error`:return`📡`;case`not-found`:return`🔍`;case`server-error`:return`⚠️`;case`parse-error`:return`📄`;case`abort`:return`🚫`;default:return`❌`}})()}),w(`h2`,{style:{margin:0,fontSize:`20px`,fontWeight:`600`,color:`#1f2937`},children:`Navigation Error`})]}),w(`p`,{style:{margin:`0 0 16px 0`,fontSize:`15px`,lineHeight:`1.5`,color:`#4b5563`},children:(()=>{switch(e.type){case`timeout`:return`The page took too long to load. Please try again.`;case`network-error`:return`Unable to connect to the server. Please check your internet connection.`;case`not-found`:return`The page you're looking for doesn't exist.`;case`server-error`:return`The server encountered an error. Please try again in a moment.`;case`parse-error`:return`Unable to load the page content. Please try reloading.`;case`abort`:return`Navigation was cancelled.`;default:return e.message||`An unexpected error occurred.`}})()}),e.url&&T(`details`,{style:{marginBottom:`16px`,fontSize:`13px`,color:`#6b7280`},children:[w(`summary`,{style:{cursor:`pointer`,userSelect:`none`,marginBottom:`8px`},children:`Technical details`}),T(`div`,{style:{padding:`12px`,background:`#f9fafb`,borderRadius:`4px`,fontFamily:`monospace`,fontSize:`12px`,wordBreak:`break-all`},children:[T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`URL:`}),` `,e.url]}),e.statusCode&&T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Status:`}),` `,e.statusCode]}),T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Type:`}),` `,e.type]}),e.originalError&&T(`div`,{children:[w(`strong`,{children:`Error:`}),` `,e.originalError.message]})]})]}),o&&i>0&&T(`div`,{style:{marginBottom:`16px`,padding:`8px 12px`,background:`#fef3c7`,border:`1px solid #fbbf24`,borderRadius:`4px`,fontSize:`13px`,color:`#92400e`},children:[`Retry attempt`,` `,i,` `,`of`,` `,a]}),T(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[o&&t&&w(`button`,{onClick:t,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#3b82f6`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#2563eb`},onMouseLeave:e=>{e.currentTarget.style.background=`#3b82f6`},children:`Try Again`}),n&&w(`button`,{onClick:n,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#6b7280`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.background=`#6b7280`},children:`Reload Page`}),r&&w(`button`,{onClick:r,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`transparent`,color:`#6b7280`,border:`1px solid #d1d5db`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`all 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#f9fafb`,e.currentTarget.style.borderColor=`#9ca3af`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.borderColor=`#d1d5db`},children:`Dismiss`})]}),w(`p`,{style:{marginTop:`16px`,marginBottom:0,fontSize:`12px`,color:`#9ca3af`,textAlign:`center`},children:`Your current page is still available below this message`})]})})}const I=new class{cache=new Map;pendingRequests=new Map;async get(e){let t=this.cache.get(e);if(t)return t;let n=this.pendingRequests.get(e);if(n)return n;let r=this.fetchRouteInfo(e);this.pendingRequests.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pendingRequests.delete(e)}}async fetchRouteInfo(e){let t={path:e},n=await fetch(`/_rari/route-info`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=null;try{e=await n.json()}catch{}throw e?.error?Error(e.error):Error(`Failed to fetch route info: ${n.status} ${n.statusText}`)}let r=n.clone();try{return await n.json()}catch(t){try{let e=await r.text();return JSON.parse(e)}catch(n){throw console.error(`[RouteInfo] Failed to parse response:`,{error:t,parseError:n,path:e}),Error(`Failed to parse route info response`)}}}clear(){this.cache.clear(),this.pendingRequests.clear()}invalidate(e){this.cache.delete(e)}};if(typeof window<`u`){let e=window[`~rari`]||{};window[`~rari`]||(window[`~rari`]=e),e.routeInfoCache=I}var L=class{stateHistory;routeAccessOrder;maxHistorySize;scrollableSelector;constructor(e={}){this.stateHistory=new Map,this.routeAccessOrder=[],this.maxHistorySize=e.maxHistorySize||50,this.scrollableSelector=e.scrollableSelector||`[data-scrollable], .scrollable, [style*="overflow"]`}captureState(e){let t={scrollPositions:this.captureScrollPositions(),formData:this.captureFormData(),focusedElement:this.captureFocusedElement()};return this.storeState(e,t),t}captureScrollPositions(){let e=new Map;try{e.set(`window`,{x:window.scrollX,y:window.scrollY,element:`window`}),document.querySelectorAll(this.scrollableSelector).forEach((t,n)=>{if(t instanceof HTMLElement){let r=t.id||`scrollable-${n}`;(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&e.set(r,{x:t.scrollLeft,y:t.scrollTop,element:r})}})}catch{}return e}captureFormData(){let e=new Map;try{document.querySelectorAll(`form`).forEach((t,n)=>{let r=t.id||t.name||`form-${n}`,i=new FormData(t);i.entries().next().done||e.set(r,i)})}catch{}return e}captureFocusedElement(){try{let e=document.activeElement;if(e&&e!==document.body){if(e.id)return`#${e.id}`;if((e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.name)return`[name="${e.name}"]`}}catch{}return null}storeState(e,t){let n=this.routeAccessOrder.indexOf(e);for(n!==-1&&this.routeAccessOrder.splice(n,1),this.routeAccessOrder.push(e),this.stateHistory.set(e,t);this.routeAccessOrder.length>this.maxHistorySize;){let e=this.routeAccessOrder.shift();e&&this.stateHistory.delete(e)}}getHistorySize(){return this.stateHistory.size}hasState(e){return this.stateHistory.has(e)}getState(e){return this.stateHistory.get(e)}clearAll(){this.stateHistory.clear(),this.routeAccessOrder=[]}clearState(e){this.stateHistory.delete(e);let t=this.routeAccessOrder.indexOf(e);t!==-1&&this.routeAccessOrder.splice(t,1)}restoreState(e){let t=this.stateHistory.get(e);if(!t)return!1;let n=!0;return this.restoreScrollPositions(t.scrollPositions)||(n=!1),this.restoreFormData(t.formData)||(n=!1),t.focusedElement&&this.restoreFocus(t.focusedElement),n}restoreScrollPositions(e){let t=!0;try{e.forEach((e,n)=>{try{if(n===`window`)window.scrollTo(e.x,e.y);else{let r=document.getElementById(n)||document.querySelector(`[data-scrollable-id="${n}"]`);r instanceof HTMLElement?(r.scrollLeft=e.x,r.scrollTop=e.y):t=!1}}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore scroll positions:`,e),t=!1}return t}restoreFormData(e){let t=!0;try{e.forEach((e,n)=>{try{let r=document.getElementById(n)||document.querySelector(`form[name="${n}"]`)||document.querySelectorAll(`form`)[Number.parseInt(n.replace(`form-`,``),10)];r instanceof HTMLFormElement?e.forEach((e,n)=>{try{let t=r.elements.namedItem(n);t instanceof RadioNodeList?t.forEach(t=>{t instanceof HTMLInputElement&&(t.type===`radio`||t.type===`checkbox`?t.checked=t.value===e:t.value=e)}):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t instanceof HTMLInputElement&&(t.type===`checkbox`||t.type===`radio`)?t.checked=t.value===e:t.value=e)}catch{t=!1}}):t=!1}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore form data:`,e),t=!1}return t}restoreFocus(e){try{let t=document.querySelector(e);t instanceof HTMLElement&&requestAnimationFrame(()=>{try{t.focus()}catch{}})}catch{}}};function R(e){e.title&&(document.title=e.title);let t=(e,t)=>{let n=document.querySelector(e);if(n)t.content&&n.setAttribute(`content`,t.content);else{n=document.createElement(`meta`);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);document.head.appendChild(n)}};if(e.description&&t(`meta[name="description"]`,{name:`description`,content:e.description}),e.keywords&&e.keywords.length>0&&t(`meta[name="keywords"]`,{name:`keywords`,content:e.keywords.join(`, `)}),e.viewport&&t(`meta[name="viewport"]`,{name:`viewport`,content:e.viewport}),e.canonical){let t=document.querySelector(`link[rel="canonical"]`);t||(t=document.createElement(`link`),t.setAttribute(`rel`,`canonical`),document.head.appendChild(t)),t.setAttribute(`href`,e.canonical)}if(e.robots){let n=[];e.robots.index!==void 0&&n.push(e.robots.index?`index`:`noindex`),e.robots.follow!==void 0&&n.push(e.robots.follow?`follow`:`nofollow`),e.robots.nocache&&n.push(`nocache`),n.length>0&&t(`meta[name="robots"]`,{name:`robots`,content:n.join(`, `)})}if(e.openGraph){let n=e.openGraph;if(n.title&&t(`meta[property="og:title"]`,{property:`og:title`,content:n.title}),n.description&&t(`meta[property="og:description"]`,{property:`og:description`,content:n.description}),n.url&&t(`meta[property="og:url"]`,{property:`og:url`,content:n.url}),n.siteName&&t(`meta[property="og:site_name"]`,{property:`og:site_name`,content:n.siteName}),n.type&&t(`meta[property="og:type"]`,{property:`og:type`,content:n.type}),n.images&&n.images.length>0){document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`property`,`og:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}if(e.twitter){let n=e.twitter;if(n.card&&t(`meta[name="twitter:card"]`,{name:`twitter:card`,content:n.card}),n.site&&t(`meta[name="twitter:site"]`,{name:`twitter:site`,content:n.site}),n.creator&&t(`meta[name="twitter:creator"]`,{name:`twitter:creator`,content:n.creator}),n.title&&t(`meta[name="twitter:title"]`,{name:`twitter:title`,content:n.title}),n.description&&t(`meta[name="twitter:description"]`,{name:`twitter:description`,content:n.description}),n.images&&n.images.length>0){document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`name`,`twitter:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}}function z({children:n,initialRoute:r,staleWindowMs:i=3e4}){let[a,o]=S(()=>({currentRoute:M(r),navigationId:0,error:null})),s=x(null),c=x(!0),l=x(M(r)),u=x(new O({timeout:1e4,maxRetries:3,onError:e=>{console.error(`[rari] Router: Navigation error:`,e)},onRetry:()=>{}})),d=x(new Map),f=x([]),p=x(new L({maxHistorySize:50})),m=x(null),h=x(i),g=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,_=()=>{s.current&&=(s.current.abort(),null)},v=()=>{for(let[,e]of d.current.entries())e.abortController.abort();d.current.clear()},D=(e,t)=>{d.current.delete(e),c.current&&a.navigationId===t&&o(e=>({...e}))},k=async e=>I.get(e),A=x(null),z=async(e,t={})=>{if(!e||typeof e!=`string`){console.error(`[rari] Router: Invalid navigation target:`,e);return}let[n,r]=e.includes(`#`)?e.split(`#`):[e,``],i=M(n);if(i===l.current&&!t.replace){if(r){let e=document.getElementById(r);e&&(e.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,`${i}#${r}`))}return}let f=d.current.get(i);if(f)return f.promise;let m=await k(i);v(),_();let h=new AbortController;s.current=h;let y=a.navigationId+1,b=(async()=>{let e=l.current;try{t.historyKey||p.current.captureState(e);let n=t.historyKey||g(),a={route:i,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:n},s=r?`${i}#${r}`:i;t.replace?window.history.replaceState(a,``,s):window.history.pushState(a,``,s);let f=window.location.origin+i,_=await fetch(f,{headers:{Accept:`text/x-component`},signal:h.signal});if(!_.ok&&_.status!==404)throw Error(`Failed to fetch: ${_.status}`);let v=new URL(_.url).pathname,b=v===i?i:v;if(v!==i){let e=r?`${v}#${r}`:v;window.history.replaceState({route:v,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:t.historyKey||g()},``,e)}if(h.signal.aborted){D(b,y);return}try{let e=_.headers.get(`x-rari-metadata`);if(e){let t=decodeURIComponent(e);R(JSON.parse(t))}}catch{}let x=_.headers.get(`x-render-mode`)===`streaming`,S=m?.segments&&j(``,m.segments,b)||{};if(x&&_.body){let n=_.body.getReader(),r=new TextDecoder,i=``;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;if(h.signal.aborted){await n.cancel(),D(b,y);return}i+=r.decode(t,{stream:!0});let a=i.split(`
|
|
2
|
+
`);i=a.pop()||``;for(let e of a)e.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:e}}))}i.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:i}})),window.dispatchEvent(new CustomEvent(`rari:navigate`,{detail:{from:e,to:b,navigationId:y,options:t,routeInfo:{...m,extractedParams:S},abortSignal:h.signal,isStreaming:!0}}))}catch(e){throw console.error(`[rari] Router: Streaming error:`,e),e}}else{let n=await _.text();window.dispatchEvent(new CustomEvent(`rari:navigate`,{detail:{from:e,to:b,navigationId:y,options:t,routeInfo:{...m,extractedParams:S},abortSignal:h.signal,rscWireFormat:n}}))}if(h.signal.aborted){D(b,y);return}c.current&&(l.current=b,o(e=>({...e,currentRoute:b,error:null})),u.current.resetRetry(b),t.historyKey?requestAnimationFrame(()=>{p.current.restoreState(b)}):r&&requestAnimationFrame(()=>{let e=(t=0)=>{let n=document.getElementById(r);n?n.scrollIntoView({behavior:`smooth`,block:`start`}):t<10&&setTimeout(e,50,t+1)};e()})),d.current.delete(i),A.current?.()}catch(t){if(t instanceof Error&&t.name===`AbortError`){D(i,y);return}let n=u.current.handleError(t,i);c.current&&o(e=>({...e,error:n})),d.current.delete(i),window.dispatchEvent(new CustomEvent(`rari:navigate-error`,{detail:{from:e,to:i,error:n,navigationId:y}})),A.current?.()}})();return d.current.set(i,{targetPath:i,navigationId:y,promise:b,abortController:h}),b},B=async()=>{if(f.current.length===0)return;let e=f.current.at(-1);e&&(f.current=[],await z(e.path,e.options))},V=x(z);b(()=>(A.current=B,V.current=z,()=>{A.current=null,V.current=null}));let H=x(null);H.current||=E((e,t)=>{V.current?.(e,t)},50,{leading:!1,trailing:!0,maxWait:200});let U=e=>{if(e.button!==0||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)return;let t=e.target;for(;t&&t.tagName!==`A`;)t=t.parentElement;if(!t||t.tagName!==`A`)return;let n=t;if(n.target&&n.target!==`_self`||n.hasAttribute(`download`))return;let r=n.getAttribute(`href`);if(!r||N(r))return;if(r.startsWith(`#`)){e.preventDefault();let t=r.slice(1),n=document.getElementById(t);n&&(n.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,r));return}e.preventDefault();let i=P(r);H.current&&H.current(i,{replace:!1})},W=e=>{let t=window.location.pathname,n=e.state;V.current&&V.current(t,{replace:!0,scroll:!1,historyKey:n?.key})},G=()=>{if(a.error&&a.error.url){let e=a.error.url;u.current.incrementRetry(e),z(e,{replace:!1})}},K=()=>{window.location.reload()},q=()=>{o(e=>({...e,error:null}))};y(()=>{let e=window.history.state;if(!e||!e.key){let e={route:a.currentRoute,navigationId:a.navigationId,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:g()};window.history.replaceState(e,``,window.location.pathname+window.location.search+window.location.hash)}},[]);let J=e=>{if(e.persisted){let e=window.location.pathname;p.current.captureState(e)}},Y=e=>{if(e.persisted){let e=window.location.pathname,t=window.history.state;requestAnimationFrame(()=>{p.current.restoreState(e),t?.scrollPosition&&window.scrollTo(t.scrollPosition.x,t.scrollPosition.y)})}};return y(()=>(document.addEventListener(`click`,U),window.addEventListener(`popstate`,W),window.addEventListener(`pagehide`,J),window.addEventListener(`pageshow`,Y),()=>{document.removeEventListener(`click`,U),window.removeEventListener(`popstate`,W),window.removeEventListener(`pagehide`,J),window.removeEventListener(`pageshow`,Y)}),[]),y(()=>{h.current=i;let e=()=>{document.hidden?m.current=Date.now():m.current!==null&&Date.now()-m.current>h.current&&I.clear()};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[i]),y(()=>(c.current=!0,e((e,t)=>V.current?.(e,t)??Promise.resolve()),()=>{c.current=!1,t(),_(),v(),H.current?.cancel&&H.current.cancel()}),[]),T(C,{children:[n,a.error&&w(F,{error:a.error,onRetry:G,onReload:K,onDismiss:q,retryCount:u.current.getRetryCount(a.error.url||``),maxRetries:3})]})}var B=class extends v{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[rari] Layout: Error in layout "${this.props.layoutPath}":`,e,t),this.props.onError&&this.props.onError(e,t),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:layout-error`,{detail:{layoutPath:this.props.layoutPath,error:e,errorInfo:t,timestamp:Date.now()}}))}reset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback(this.state.error,this.reset):T(`div`,{style:{padding:`16px`,margin:`16px 0`,background:`#fee`,border:`1px solid #fcc`,borderRadius:`4px`},children:[w(`h3`,{style:{margin:`0 0 8px 0`,color:`#c00`},children:`Layout Error`}),T(`p`,{style:{margin:`0 0 8px 0`,fontSize:`14px`},children:[`An error occurred in layout:`,` `,w(`code`,{children:this.props.layoutPath})]}),T(`details`,{style:{fontSize:`12px`,marginBottom:`8px`},children:[w(`summary`,{style:{cursor:`pointer`},children:`Error details`}),T(`pre`,{style:{marginTop:`8px`,padding:`8px`,background:`#fff`,border:`1px solid #ddd`,borderRadius:`2px`,overflow:`auto`},children:[this.state.error.message,`
|
|
3
|
+
`,this.state.error.stack]})]}),w(`button`,{onClick:this.reset,type:`button`,style:{padding:`6px 12px`,background:`#c00`,color:`white`,border:`none`,borderRadius:`4px`,cursor:`pointer`,fontSize:`14px`},children:`Try Again`})]}):this.props.children}};export{z as ClientRouter,g as DefaultError,d as DefaultLoading,m as ErrorBoundary,c as HttpRuntimeClient,B as LayoutErrorBoundary,n as LoadingSpinner,O as NavigationErrorHandler,F as NavigationErrorOverlay,f as NotFound,L as StatePreserver,_ as clearPropsCache,i as clearPropsCacheForComponent,h as createErrorBoundary,r as createHttpRuntimeClient,l as createLoadingBoundary,a as extractMetadata,p as extractServerProps,u as extractServerPropsWithCache,s as extractStaticParams,o as hasServerSideDataFetching};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import { a as ProxyModule, c as RariURL, i as ProxyMatcher, l as RequestCookies, n as ProxyConfig, o as ProxyResult, r as ProxyFunction, s as RariFetchEvent, t as CookieOptions, u as ResponseCookies } from "./types-BV0iON-q.mjs";
|
|
1
|
+
import { d as Metadata, l as LayoutProps, p as PageProps } from "./types-By2lPZfR.mjs";
|
|
2
|
+
import { a as SitemapImage, i as SitemapEntry, n as RobotsRule, o as SitemapVideo, r as Sitemap, t as Robots } from "./metadata-route-5FF9DZGf.mjs";
|
|
3
|
+
import { c as RariURL, n as ProxyConfig, r as ProxyFunction, s as RariFetchEvent } from "./types-CBPVPFdE.mjs";
|
|
5
4
|
import { RariRequest } from "./proxy/RariRequest.mjs";
|
|
6
5
|
import { RariResponse } from "./proxy/RariResponse.mjs";
|
|
7
|
-
|
|
8
|
-
export { ApiResponse, ApiRouteHandlers, AppRouteEntry, AppRouteManifest, AppRouteMatch, CookieOptions, ErrorEntry, ErrorProps, GenerateMetadata, GenerateStaticParams, HttpRuntimeClient, LayoutEntry, LayoutProps, LoadingEntry, type Metadata, MetadataResult, NotFoundEntry, PageProps, ProxyConfig, ProxyFunction, ProxyMatcher, ProxyModule, ProxyPluginOptions, ProxyResult, RariFetchEvent, RariRequest, RariResponse, RariURL, Request, RequestCookies, Response, ResponseCookies, type Robots, type RobotsRule, RouteContext, RouteHandler, RouteSegment, RouteSegmentType, RuntimeClient, ServerCSPConfig, ServerConfig, ServerRateLimitConfig, ServerSidePropsResult, ServerSpamBlockerConfig, type Sitemap, type SitemapEntry, type SitemapImage, type SitemapVideo, StaticParamsResult, clearPropsCache, clearPropsCacheForComponent, createHttpRuntimeClient, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, rari, rariProxy, rariRouter };
|
|
6
|
+
export { type LayoutProps, type Metadata, type PageProps, type ProxyConfig, type ProxyFunction, type RariFetchEvent, RariRequest, RariResponse, type RariURL, type Robots, type RobotsRule, type Sitemap, type SitemapEntry, type SitemapImage, type SitemapVideo };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{RariRequest as e}from"./proxy/RariRequest.mjs";import{RariResponse as t}from"./proxy/RariResponse.mjs";export{e as RariRequest,t as RariResponse};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/fetch-cache.d.ts
|
|
2
|
+
declare global {
|
|
3
|
+
interface RequestInit {
|
|
4
|
+
rari?: {
|
|
5
|
+
revalidate?: number | false;
|
|
6
|
+
tags?: string[];
|
|
7
|
+
timeout?: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types/metadata-route.d.ts
|
|
13
|
+
interface RobotsRule {
|
|
14
|
+
userAgent?: string | string[];
|
|
15
|
+
allow?: string | string[];
|
|
16
|
+
disallow?: string | string[];
|
|
17
|
+
crawlDelay?: number;
|
|
18
|
+
}
|
|
19
|
+
interface Robots {
|
|
20
|
+
rules: RobotsRule | RobotsRule[];
|
|
21
|
+
sitemap?: string | string[];
|
|
22
|
+
host?: string;
|
|
23
|
+
}
|
|
24
|
+
interface SitemapImage {
|
|
25
|
+
loc: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
caption?: string;
|
|
28
|
+
geoLocation?: string;
|
|
29
|
+
license?: string;
|
|
30
|
+
}
|
|
31
|
+
interface SitemapVideo {
|
|
32
|
+
title: string;
|
|
33
|
+
thumbnail_loc: string;
|
|
34
|
+
description: string;
|
|
35
|
+
content_loc?: string;
|
|
36
|
+
player_loc?: string;
|
|
37
|
+
duration?: number;
|
|
38
|
+
expiration_date?: string;
|
|
39
|
+
rating?: number;
|
|
40
|
+
view_count?: number;
|
|
41
|
+
publication_date?: string;
|
|
42
|
+
family_friendly?: boolean;
|
|
43
|
+
restriction?: {
|
|
44
|
+
relationship: 'allow' | 'deny';
|
|
45
|
+
content: string;
|
|
46
|
+
};
|
|
47
|
+
platform?: {
|
|
48
|
+
relationship: 'allow' | 'deny';
|
|
49
|
+
content: string;
|
|
50
|
+
};
|
|
51
|
+
requires_subscription?: boolean;
|
|
52
|
+
uploader?: {
|
|
53
|
+
name: string;
|
|
54
|
+
info?: string;
|
|
55
|
+
};
|
|
56
|
+
live?: boolean;
|
|
57
|
+
tag?: string[];
|
|
58
|
+
}
|
|
59
|
+
interface SitemapEntry {
|
|
60
|
+
url: string;
|
|
61
|
+
lastModified?: string | Date;
|
|
62
|
+
changeFrequency?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
63
|
+
priority?: number;
|
|
64
|
+
alternates?: {
|
|
65
|
+
languages?: Record<string, string>;
|
|
66
|
+
};
|
|
67
|
+
images?: (string | SitemapImage)[];
|
|
68
|
+
videos?: SitemapVideo[];
|
|
69
|
+
}
|
|
70
|
+
type Sitemap = SitemapEntry[];
|
|
71
|
+
//#endregion
|
|
72
|
+
export { SitemapImage as a, SitemapEntry as i, RobotsRule as n, SitemapVideo as o, Sitemap as r, Robots as t };
|
|
@@ -20,7 +20,9 @@ interface SimpleProxyResult {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
declare global {
|
|
23
|
-
|
|
23
|
+
interface GlobalThis {
|
|
24
|
+
'~rariExecuteProxy'?: (request: SimpleRequest) => Promise<SimpleProxyResult>;
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
declare function initializeProxyExecutor(proxyModulePath: string, rariRequestPath: string): Promise<boolean>;
|
|
26
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
async function e(e,t){try{let n=await import(e);if(!n||!n.proxy)return console.error(`[rari] Proxy: proxy function not found in module`),!1;let{RariRequest:r}=await import(t);return globalThis
|
|
1
|
+
async function e(e,t){try{let n=await import(e);if(!n||!n.proxy)return console.error(`[rari] Proxy: proxy function not found in module`),!1;let{RariRequest:r}=await import(t);return globalThis[`~rariExecuteProxy`]=async function(e){try{let t=new r(e.url,{method:e.method,headers:new Headers(e.headers)}),i=[],a=await n.proxy(t,{waitUntil:e=>{i.push(e)}});if(i.length>0&&Promise.allSettled(i).catch(e=>{console.error(`[rari] Proxy: waitUntil promise failed:`,e)}),!a)return{continue:!0};let o=a.headers?.get?.(`x-rari-proxy-continue`),s=a.headers?.get?.(`x-rari-proxy-rewrite`);if(s)return{continue:!1,rewrite:s};let c=a.headers?.get?.(`location`);if(c&&a.status>=300&&a.status<400)return{continue:!1,redirect:{destination:c,permanent:a.status===301||a.status===308}};if(o===`true`){let e={},t={};return a.headers?.forEach&&a.headers.forEach((n,r)=>{if(r.startsWith(`x-rari-proxy-request-`)){let t=r.replace(`x-rari-proxy-request-`,``);e[t]=n}else r.startsWith(`x-rari-proxy-`)||(t[r]=n)}),{continue:!0,requestHeaders:Object.keys(e).length>0?e:void 0,responseHeaders:Object.keys(t).length>0?t:void 0}}if(a.status){let e={};a.headers?.forEach&&a.headers.forEach((t,n)=>{e[n]=t});let t;try{a.text&&typeof a.text==`function`?t=await a.text():a.body&&(t=String(a.body))}catch{}return{continue:!1,response:{status:a.status,headers:e,body:t}}}return{continue:!0}}catch(e){return console.error(`[rari] Proxy: Proxy execution error:`,e),{continue:!0}}},!0}catch(e){return console.error(`[rari] Proxy: Failed to initialize proxy executor:`,e),!1}}export{e as initializeProxyExecutor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"./utils-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"./utils-dqnEOG_U-sHhPlm_u.mjs";import{existsSync as a,readFileSync as o,writeFileSync as s}from"node:fs";import{join as c}from"node:path";import l from"node:process";import{styleText as u}from"node:util";async function d(){let d=l.cwd();e(`Creating Railway deployment configuration...`);let f=c(d,`package.json`);a(f)||(t(`No package.json found. Please run this command from your project root.`),l.exit(1));try{let t=JSON.parse(o(f,`utf-8`));t.scripts=t.scripts||{},t.scripts.start&&t.scripts.start!==`rari start`&&(n(`Existing start script found: "${t.scripts.start}"`),n(`Backing up to start:original and replacing with "rari start"`),t.scripts[`start:original`]=t.scripts.start),t.scripts.start=`rari start`,t.scripts[`start:local`]=`rari start`,t.scripts[`deploy:railway`]=`echo "Push to GitHub and connect to Railway to deploy"`,i(t),(!t.dependencies||!t.dependencies.rari)&&(e(`Adding rari dependency...`),t.dependencies=t.dependencies||{},t.dependencies.rari=`^0.1.0`),s(f,`${JSON.stringify(t,null,2)}\n`),r(`Updated package.json for Railway deployment`)}catch(e){t(`Failed to update package.json: ${e instanceof Error?e.message:`Unknown error`}`),l.exit(1)}let p=c(d,`railway.toml`);if(a(p)){n(`railway.toml already exists, backing up to railway.toml.backup`);let e=o(p,`utf-8`);s(c(d,`railway.toml.backup`),e)}s(p,`[build]
|
|
2
2
|
builder = "RAILPACK"
|
|
3
3
|
|
|
4
4
|
[deploy]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"./utils-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"./utils-dqnEOG_U-sHhPlm_u.mjs";import{existsSync as a,readFileSync as o,writeFileSync as s}from"node:fs";import{join as c}from"node:path";import l from"node:process";import{styleText as u}from"node:util";async function d(){let d=l.cwd();e(`Creating Render deployment configuration...`);let f=c(d,`package.json`);a(f)||(t(`No package.json found. Please run this command from your project root.`),l.exit(1));try{let t=JSON.parse(o(f,`utf-8`));t.scripts=t.scripts||{},t.scripts.start&&t.scripts.start!==`rari start`&&(n(`Existing start script found: "${t.scripts.start}"`),n(`Backing up to start:original and replacing with "rari start"`),t.scripts[`start:original`]=t.scripts.start),t.scripts.start=`rari start`,t.scripts[`start:local`]=`rari start`,t.scripts[`deploy:render`]=`echo "Push to GitHub and connect to Render to deploy"`,i(t),(!t.dependencies||!t.dependencies.rari)&&(e(`Adding rari dependency...`),t.dependencies=t.dependencies||{},t.dependencies.rari=`^0.1.0`),s(f,`${JSON.stringify(t,null,2)}\n`),r(`Updated package.json for Render deployment`)}catch(e){t(`Failed to update package.json: ${e instanceof Error?e.message:`Unknown error`}`),l.exit(1)}let p=c(d,`render.yaml`);if(a(p)){n(`render.yaml already exists, backing up to render.yaml.backup`);let e=o(p,`utf-8`);s(c(d,`render.yaml.backup`),e)}s(p,`services:
|
|
2
2
|
- type: web
|
|
3
3
|
name: rari-app
|
|
4
4
|
runtime: node
|
package/dist/router.d.mts
CHANGED
package/dist/router.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t}from"./navigate-
|
|
1
|
+
import{n as e,r as t}from"./navigate-DPJioMXn.mjs";import{createContext as n,use as r,useEffect as i,useMemo as a,useRef as o,useState as s}from"react";import{jsx as c}from"react/jsx-runtime";const l=n(null);function u({children:t,initialPathname:n}){let[r,u]=s(n),[d,f]=s(()=>typeof window<`u`?new URLSearchParams(window.location.search):new URLSearchParams),[p,m]=s({}),h=o(null);return i(()=>{let e=e=>{let t=e.detail;t?.to&&(u(t.to),f(new URLSearchParams(window.location.search)),t?.routeInfo?.extractedParams?m(t.routeInfo.extractedParams):m({}))};return window.addEventListener(`rari:navigate`,e),()=>{window.removeEventListener(`rari:navigate`,e)}},[]),i(()=>{let t=e();t&&(h.current=t);let n=e=>{h.current=e.detail.navigate},r=()=>{h.current=null};return window.addEventListener(`rari:register-navigate`,n),window.addEventListener(`rari:deregister-navigate`,r),()=>{window.removeEventListener(`rari:register-navigate`,n),window.removeEventListener(`rari:deregister-navigate`,r)}},[]),c(l,{value:a(()=>({pathname:r,params:p,searchParams:d,push:async(e,t)=>{h.current?await h.current(e,t):(console.warn(`[rari] Router not ready, falling back to window.location`),window.location.href=e)},replace:async(e,t)=>{h.current?await h.current(e,{...t,replace:!0}):(console.warn(`[rari] Router not ready, falling back to window.location`),window.location.replace(e))},back:()=>{window.history.back()},forward:()=>{window.history.forward()},refresh:()=>{window.dispatchEvent(new CustomEvent(`rari:app-router-rerender`))},prefetch:async e=>{try{let t=new URL(e,window.location.origin);await fetch(t.pathname+t.search,{headers:{Accept:`text/x-component`},priority:`low`})}catch(e){console.warn(`[rari] Prefetch failed:`,e)}}}),[r,p,d]),children:t})}function d(){let e=r(l);if(!e)throw Error(`useRouter must be used within a RouterProvider`);return e}function f(){return d().pathname}function p(){return d().params}function m(){return d().searchParams}export{u as RouterProvider,t as navigate,p as useParams,f as usePathname,d as useRouter,m as useSearchParams};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";import{S as e,b as t}from"../regex-constants-DMuIAFub.mjs";import{t as n}from"../preload-components-
|
|
1
|
+
"use client";import{S as e,b as t}from"../regex-constants-DMuIAFub.mjs";import{t as n}from"../preload-components-5Y8ZOaFG.mjs";import*as r from"react";import{Suspense as i,useEffect as a,useRef as o,useState as s,useTransition as c}from"react";import{Fragment as l,jsx as u,jsxs as d}from"react/jsx-runtime";const f=/"timestamp":(\d+)/,p=/^[;\s]*$/;function m(){return d(`div`,{style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:9999},children:[u(`div`,{style:{width:`40px`,height:`40px`,border:`4px solid rgba(0, 0, 0, 0.1)`,borderTopColor:`#3b82f6`,borderRadius:`50%`,animation:`spin 1s linear infinite`}}),u(`style`,{children:`
|
|
2
2
|
@keyframes spin {
|
|
3
3
|
to { transform: rotate(360deg); }
|
|
4
4
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import"../regex-constants-DMuIAFub.mjs";import{n as e,t}from"../get-client-component-
|
|
1
|
+
import"../regex-constants-DMuIAFub.mjs";import{n as e,t}from"../get-client-component-CpMI09nb.mjs";import*as n from"react";import{Suspense as r}from"react";import{ClientRouter as i}from"rari/client";import{RouterProvider as a}from"rari/router";import{createRoot as o}from"react-dom/client";import{AppRouterProvider as s}from"virtual:app-router-provider";import{createFromReadableStream as c}from"virtual:react-server-dom-rari-client.ts";import"virtual:rsc-integration.ts";function l(){return globalThis[`~rari`]}function u(){return globalThis}function d(){return window}function f(){return{moduleMap:new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return{id:`${String(t)}#${String(n)}`,chunks:[],name:String(n)}}})}}),moduleLoading:new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return async()=>{try{let e=String(t),r=String(n),i=`${e}#${r}`;if(u()[`~clientComponents`]?.[i]?.component)return u()[`~clientComponents`][i].component;if(u()[`~clientComponents`]?.[e]?.component){let t=u()[`~clientComponents`][e].component;return r===`default`?t:t?.[r]}let a=u()[`~clientComponents`]?.[i]||u()[`~clientComponents`]?.[e];if(a?.loader){a.loadPromise||=(a.loading=!0,a.loader().then(e=>(a.component=e.default||e,a.registered=!0,a.loading=!1,e)).catch(t=>{throw a.loading=!1,a.loadPromise=void 0,console.error(`[rari] Failed to lazy load ${e}#${r}:`,t),t}));let t=await a.loadPromise,n=t.default||t;return r===`default`?n:n?.[r]??n}return console.warn(`[rari] Module ${e}#${r} not found in client components registry`),null}catch(e){return console.error(`[rari] Failed to load ${String(t)}#${String(n)}:`,e),null}}}})}})}}l()===void 0&&(globalThis[`~rari`]={}),l().AppRouterProvider=s,l().ClientRouter=i,l().getClientComponent=t;async function p(t){try{await e(t)}catch(e){console.error(`[rari] Failed to preload component ${t}:`,e)}}
|
|
2
2
|
/*! @preserve CLIENT_COMPONENT_IMPORTS_PLACEHOLDER */
|
|
3
3
|
l().preloadClientComponent=p,u()[`~clientComponents`]===void 0&&(globalThis[`~clientComponents`]={}),u()[`~clientComponentPaths`]===void 0&&(globalThis[`~clientComponentPaths`]={});
|
|
4
4
|
/*! @preserve CLIENT_COMPONENT_REGISTRATIONS_PLACEHOLDER */
|
|
5
|
-
function m(){l().hydrateClientComponents||(l().hydrateClientComponents=function(e,t,r){let i=d()[`~rari`].boundaryModules||new Map;function a(e){if(!e)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(e.length>=4&&e[0]===`$`){let[,t,r,o]=e,s=o?{...o}:{};if(o?.children&&(s.children=a(o.children)),s[`~boundaryId`]&&delete s[`~boundaryId`],typeof t==`string`){if(t.startsWith(`$L`)){let e=i.get(t);if(e){let t=`${e.id}#${e.name||`default`}`,i=null,a=u()[`~clientComponents`][t]||u()[`~clientComponents`][e.id];return a&&(a.component?i=a.component:a.loader&&!a.loading&&(a.loading=!0,a.loadPromise=a.loader().then(e=>(a.component=e.default||e,a.registered=!0,a.loading=!1,a.component)).catch(t=>{throw a.loading=!1,a.loadPromise=void 0,console.error(`[rari] Failed to load component ${e.id}:`,t),t})),a.loadPromise&&!a.component&&n.use(a.loadPromise)),i?n.createElement(i,r?{...s,key:r}:s):s.children||null}return s.children||null}return n.createElement(t,r?{...s,key:r}:s)}return null}return e.map((e,t)=>{let r=a(e);return n.isValidElement(r)&&!r.key?n.cloneElement(r,{key:t}):r})}return e}try{let e=a(t);e&&(o(r).render(e),r.classList.add(`rari-boundary-hydrated`))}catch(e){console.error(`[rari] Failed to hydrate client components:`,e),console.error(`[rari] Error stack:`,e.stack)}})}function h(){let e=d()[`~rari`].pendingBoundaryHydrations;if(!(!e||e.size===0)){for(let[t,n]of e.entries())l().hydrateClientComponents&&l().hydrateClientComponents(t,n.content,n.element);e.clear()}}m();async function g(t){let n=[];for(let r of t){let t=e(r).catch(e=>{console.error(`[rari] Failed to preload component ${r}:`,e)});n.push(t)}n.length>0&&await Promise.all(n)}async function _(){let e=document.getElementById(`root`);if(!e){console.error(`[rari] Root element not found`);return}let r=document.getElementById(`__RARI_RSC_PAYLOAD__`),l=e.children.length>0,u=d()[`~rari`]?.bufferedRows&&d()[`~rari`].bufferedRows.length>0;if(m(),l&&!r&&!u){let e=document.querySelectorAll(`[data-client-component]`);if(e.length>0){let r=new Set;e.forEach(e=>{let t=e.getAttribute(`data-client-component`);t&&r.add(t)}),await g(r),e.forEach(e=>{let r=e.getAttribute(`data-client-component`),i=e.getAttribute(`data-props`);if(r)try{let a=t(r);if(!a)return;let s=i?JSON.parse(i):{};requestAnimationFrame(()=>{try{document.contains(e)&&(e.replaceChildren(),o(e).render(n.createElement(a,s)))}catch(e){console.error(`[rari] Failed to hydrate client component ${r}:`,e)}})}catch(e){console.error(`[rari] Failed to hydrate client component ${r}:`,e)}})}return}if(l&&u&&!r&&document.querySelectorAll(`[data-boundary-id]`).length>0){d()[`~rari`].pendingBoundaryHydrations&&d()[`~rari`].pendingBoundaryHydrations.size>0&&h();return}try{let t;if(!r&&!u&&!l)try{let e=window.location.pathname+window.location.search,n=(import.meta.env.DEV?import.meta.env.RARI_SERVER_URL||`http://localhost:${import.meta.env.VITE_RSC_PORT||`3000`}`:window.location.origin)+e,r=await fetch(n,{headers:{Accept:`text/x-component`},cache:`no-store`});if(!r.ok&&r.status!==404)throw Error(`Failed to fetch RSC data: ${r.status}`);let i=r.body;t=await c(i,f())}catch(e){if(e instanceof Promise)throw e;if(console.error(`[rari] Failed to fetch initial RSC data:`,e),e instanceof Error)console.error(`[rari] Error name:`,e.name),console.error(`[rari] Error message:`,e.message),e.stack&&console.error(`[rari] Error stack:`,e.stack);else if(typeof e==`string`)console.error(`[rari] Error details:`,e);else if(e&&typeof e==`object`)try{let t={};for(let n of Object.getOwnPropertyNames(e))t[n]=e[n];console.error(`[rari] Error details:`,JSON.stringify(t,null,2))}catch{console.error(`[rari] Error details:`,String(e))}else console.error(`[rari] Error details:`,String(e));t=null}else if(r&&r.textContent)try{let e=r.textContent,n=d()[`~rari`]?.bufferedRows&&d()[`~rari`].bufferedRows.length>0;t=d()[`~rari`]?.
|
|
5
|
+
function m(){l().hydrateClientComponents||(l().hydrateClientComponents=function(e,t,r){let i=d()[`~rari`].boundaryModules||new Map;function a(e){if(!e)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(e.length>=4&&e[0]===`$`){let[,t,r,o]=e,s=o?{...o}:{};if(o?.children&&(s.children=a(o.children)),s[`~boundaryId`]&&delete s[`~boundaryId`],typeof t==`string`){if(t.startsWith(`$L`)){let e=i.get(t);if(e){let t=`${e.id}#${e.name||`default`}`,i=null,a=u()[`~clientComponents`][t]||u()[`~clientComponents`][e.id];return a&&(a.component?i=a.component:a.loader&&!a.loading&&(a.loading=!0,a.loadPromise=a.loader().then(e=>(a.component=e.default||e,a.registered=!0,a.loading=!1,a.component)).catch(t=>{throw a.loading=!1,a.loadPromise=void 0,console.error(`[rari] Failed to load component ${e.id}:`,t),t})),a.loadPromise&&!a.component&&n.use(a.loadPromise)),i?n.createElement(i,r?{...s,key:r}:s):s.children||null}return s.children||null}return n.createElement(t,r?{...s,key:r}:s)}return null}return e.map((e,t)=>{let r=a(e);return n.isValidElement(r)&&!r.key?n.cloneElement(r,{key:t}):r})}return e}try{let e=a(t);e&&(o(r).render(e),r.classList.add(`rari-boundary-hydrated`))}catch(e){console.error(`[rari] Failed to hydrate client components:`,e),console.error(`[rari] Error stack:`,e.stack)}})}function h(){let e=d()[`~rari`].pendingBoundaryHydrations;if(!(!e||e.size===0)){for(let[t,n]of e.entries())l().hydrateClientComponents&&l().hydrateClientComponents(t,n.content,n.element);e.clear()}}m();async function g(t){let n=[];for(let r of t){let t=e(r).catch(e=>{console.error(`[rari] Failed to preload component ${r}:`,e)});n.push(t)}n.length>0&&await Promise.all(n)}async function _(){let e=document.getElementById(`root`);if(!e){console.error(`[rari] Root element not found`);return}let r=document.getElementById(`__RARI_RSC_PAYLOAD__`),l=e.children.length>0,u=d()[`~rari`]?.streaming?.bufferedRows&&d()[`~rari`].streaming.bufferedRows.length>0;if(m(),l&&!r&&!u){let e=document.querySelectorAll(`[data-client-component]`);if(e.length>0){let r=new Set;e.forEach(e=>{let t=e.getAttribute(`data-client-component`);t&&r.add(t)}),await g(r),e.forEach(e=>{let r=e.getAttribute(`data-client-component`),i=e.getAttribute(`data-props`);if(r)try{let a=t(r);if(!a)return;let s=i?JSON.parse(i):{};requestAnimationFrame(()=>{try{document.contains(e)&&(e.replaceChildren(),o(e).render(n.createElement(a,s)))}catch(e){console.error(`[rari] Failed to hydrate client component ${r}:`,e)}})}catch(e){console.error(`[rari] Failed to hydrate client component ${r}:`,e)}})}return}if(l&&u&&!r&&document.querySelectorAll(`[data-boundary-id]`).length>0){d()[`~rari`].pendingBoundaryHydrations&&d()[`~rari`].pendingBoundaryHydrations.size>0&&h();return}try{let t;if(!r&&!u&&!l)try{let e=window.location.pathname+window.location.search,n=(import.meta.env.DEV?import.meta.env.RARI_SERVER_URL||`http://localhost:${import.meta.env.VITE_RSC_PORT||`3000`}`:window.location.origin)+e,r=await fetch(n,{headers:{Accept:`text/x-component`},cache:`no-store`});if(!r.ok&&r.status!==404)throw Error(`Failed to fetch RSC data: ${r.status}`);let i=r.body;t=await c(i,f())}catch(e){if(e instanceof Promise)throw e;if(console.error(`[rari] Failed to fetch initial RSC data:`,e),e instanceof Error)console.error(`[rari] Error name:`,e.name),console.error(`[rari] Error message:`,e.message),e.stack&&console.error(`[rari] Error stack:`,e.stack);else if(typeof e==`string`)console.error(`[rari] Error details:`,e);else if(e&&typeof e==`object`)try{let t={};for(let n of Object.getOwnPropertyNames(e))t[n]=e[n];console.error(`[rari] Error details:`,JSON.stringify(t,null,2))}catch{console.error(`[rari] Error details:`,String(e))}else console.error(`[rari] Error details:`,String(e));t=null}else if(r&&r.textContent)try{let e=r.textContent,n=d()[`~rari`]?.streaming?.bufferedRows&&d()[`~rari`].streaming.bufferedRows.length>0;t=d()[`~rari`]?.streaming?.complete===void 0||n?await c(new ReadableStream({start(t){if(t.enqueue(new TextEncoder().encode(e)),d()[`~rari`]?.streaming?.bufferedRows){for(let e of d()[`~rari`].streaming.bufferedRows)t.enqueue(new TextEncoder().encode(`\n${e}`));d()[`~rari`].streaming.bufferedRows=[]}let n=e=>{let n=e;n.detail?.rscRow&&t.enqueue(new TextEncoder().encode(`\n${n.detail.rscRow}`))},r=()=>{t.close(),window.removeEventListener(`rari:rsc-row`,n),window.removeEventListener(`rari:stream-complete`,r)};window.addEventListener(`rari:rsc-row`,n),window.addEventListener(`rari:stream-complete`,r),d()[`~rari`]?.streaming?.complete&&r()}}),f()):await c(new ReadableStream({start(t){t.enqueue(new TextEncoder().encode(e)),t.close()}}),f())}catch(e){console.error(`[rari] Failed to parse embedded RSC payload:`,e),t=null}else if(u)try{t=await c(new ReadableStream({start(e){if(d()[`~rari`]?.streaming?.bufferedRows){for(let t of d()[`~rari`].streaming.bufferedRows)e.enqueue(new TextEncoder().encode(`${t}\n`));d()[`~rari`].streaming.bufferedRows=[]}let t=t=>{let n=t;n.detail?.rscRow&&e.enqueue(new TextEncoder().encode(`${n.detail.rscRow}\n`))},n=()=>{e.close(),window.removeEventListener(`rari:rsc-row`,t),window.removeEventListener(`rari:stream-complete`,n)};window.addEventListener(`rari:rsc-row`,t),window.addEventListener(`rari:stream-complete`,n),d()[`~rari`]?.streaming?.complete&&n()}}),f())}catch(e){console.error(`[rari] Failed to process streaming RSC payload:`,e),t=null}if(!t)throw Error(`No RSC data available for hydration`);let p;p=t;let m;m=n.createElement(s,{initialPayload:{element:t}},p),m=n.createElement(i,{initialRoute:window.location.pathname},m),m=n.createElement(a,{initialPathname:window.location.pathname},m),o(e).render(m)}catch(t){console.error(`[rari] Error rendering app:`,t),e.innerHTML=`
|
|
6
6
|
<div style="padding: 20px; background: #fee; border: 2px solid #f00; margin: 20px;">
|
|
7
7
|
<h2>Error Loading App</h2>
|
|
8
8
|
<p></p>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as e,t,w as n}from"../regex-constants-DMuIAFub.mjs";import{r}from"../get-client-component-
|
|
1
|
+
import{b as e,t,w as n}from"../regex-constants-DMuIAFub.mjs";import{r}from"../get-client-component-CpMI09nb.mjs";import{t as i}from"../preload-components-5Y8ZOaFG.mjs";import*as a from"react";async function o(e,t={}){let{moduleMap:n={}}=t,r=e.getReader(),a=[];for(;;){let{done:e,value:t}=await r.read();if(e)break;a.push(t)}let o=new Uint8Array(a.reduce((e,t)=>e+t.length,0)),s=0;for(let e of a)o.set(e,s),s+=e.length;let l=c(new TextDecoder().decode(o));return await i(l.modules),u(l.rootElement,l.modules,n,l.symbols,l.chunks)}async function s(e,t={}){let n=c(await(await e).text());return await i(n.modules),u(n.rootElement,n.modules,t.moduleMap||{},n.symbols,n.chunks)}function c(e){let t=new Map,n=new Map,r=new Map,i=0,a=0,o=0,s=0,c=``,u=null;for(;i<e.length;){let d=e[i],f=e.charCodeAt(i);switch(a){case 0:d===`:`?(a=1,i++):(f>=48&&f<=57?o=o<<4|f-48:f>=97&&f<=102?o=o<<4|f-87:f>=65&&f<=70&&(o=o<<4|f-55),i++);break;case 1:f===73||f===69||f===84||f===72||f===68||f===87||f===67?(s=f,a=2,i++):(s=0,a=2);break;case 2:d===`
|
|
2
2
|
`?(l(o,s,c,t,n,r),u===null&&s!==73&&c.trim()&&!(c.startsWith(`"$S`)&&c.endsWith(`"`))&&n.has(o.toString())&&(u=o.toString()),a=0,o=0,s=0,c=``):c+=d,i++;break}}return c.trim()&&(l(o,s,c,t,n,r),u===null&&s!==73&&!(c.startsWith(`"$S`)&&c.endsWith(`"`))&&n.has(o.toString())&&(u=o.toString())),{modules:t,chunks:n,symbols:r,rootElement:u===null?null:n.get(u)}}function l(e,t,n,r,i,a){let o=e.toString();try{switch(t){case 73:{let e=JSON.parse(n);Array.isArray(e)&&e.length>=3&&r.set(`$L${o}`,{id:e[0],chunks:e[1]||[],name:e[2]||`default`});break}case 69:{console.error(`[rari] RSC: Error chunk:`,n);let e=JSON.parse(n);i.set(o,{error:e});break}case 84:i.set(o,n);break;case 72:case 68:case 87:break;case 67:break;default:{if(!n.trim())break;if(n.startsWith(`"$S`)&&n.endsWith(`"`)){let e=n.slice(1,-1);a.set(o,e);break}let e=JSON.parse(n);i.set(o,e);break}}}catch(e){console.error(`[rari] RSC: Failed to parse row:`,{id:o,tag:t,data:n},e)}}function u(t,n,r,i,o){if(!t)return null;if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`){if(typeof t==`string`&&t.startsWith(`$`)&&t.length>1){if(t[1]===`L`){let e=t.slice(2),a=o?.get(e);if(!a){let e=new Promise(()=>{});throw e._rscLazyRef=t,e}return u(a,n,r,i,o)}let e=t.slice(1),a=o?.get(e);return a?u(a,n,r,i,o):null}return t}if(Array.isArray(t)){if(t.length>=4&&t[0]===`$`){let[,s,c,l]=t;if(typeof s==`string`&&s.startsWith(`$`)&&s.length>1&&e.test(s.slice(1))){let e=s.slice(1),t=i?.get(e);if(t&&t.startsWith(`$S`)&&t.slice(2)===`react.suspense`){let e=f(l,n,r,i,o);return a.createElement(a.Suspense,c?{...e,key:c}:e)}}if(typeof s==`string`&&s.startsWith(`$S`)){if(s.slice(2)===`react.suspense`){let e=f(l,n,r,i,o);return a.createElement(a.Suspense,c?{...e,key:c}:e)}return null}if(typeof s==`string`&&s.startsWith(`$L`)){let e=s.substring(2);if(e===`ClientRouter`&&(!l||!l.manifest))return l&&l.children?u(l.children,n,r,i,o):null;let t=d(e,n,r);if(t){let e=f(l,n,r,i,o);return a.createElement(t,c?{...e,key:c}:e)}return null}let p=f(l,n,r,i,o);return a.createElement(s,c?{...p,key:c}:p)}return t.map(e=>u(e,n,r,i,o))}return t}function d(e,i,a){if(e===`AppRouterProvider`){let e=globalThis[`~rari`]?.AppRouterProvider;if(e)return e}if(e===`ClientRouter`){let e=globalThis[`~rari`]?.ClientRouter;if(e)return e}if(i&&i.size>0){let a=`$L${e}`,o=i.get(a);if(o){let e=globalThis[`~clientComponents`]||{},i=[o.id,`${o.id}#${o.name||`default`}`,o.id.replace(n,``),o.id.replace(t,`/`)];for(let t of i){let n=e[t];if(n){if(n.component)return n.component;if(n.loader&&!n.loading)return r(n,o.id);if(n.loading)return null}}console.warn(`[rari] Component not found in registry:`,{moduleId:o.id,moduleName:o.name,triedKeys:i,availableKeys:Object.keys(e).slice(0,10)})}}if(a[e])return a[e];let o=globalThis[`~clientComponents`]||{};for(let[t,n]of Object.entries(o)){let i=t===e,a=t.endsWith(`/${e}`)||t.endsWith(`\\${e}`),o=t.endsWith(`#${e}`),s=n.name===e;if(i||a||o||s){if(n.component)return n.component;if(n.loader&&!n.loading)return r(n,t)}}return null}function f(e,t,n,r,i){if(!e||typeof e!=`object`)return e;let a={};for(let o in e)if(Object.hasOwn(e,o)){if(o.startsWith(`~`)||o===`ref`)continue;o===`children`?a[o]=e.children?u(e.children,t,n,r,i):void 0:a[o]=e[o]}return a}function p(e){return JSON.stringify(e)}function m(e){return JSON.parse(e)}export{s as createFromFetch,o as createFromReadableStream,m as decodeReply,p as encodeReply};
|
|
@@ -15,7 +15,7 @@ declare function registerClientReference(clientReference: any, id: string, expor
|
|
|
15
15
|
declare function registerClientComponent(componentFunction: any, id: string, exportName: string): void;
|
|
16
16
|
declare function registerServerReference(serverReference: any, id: string, exportName: string): any;
|
|
17
17
|
declare function createClientModuleProxy(id: string): any;
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
18
|
+
declare const CLIENT_REFERENCE_REGISTRY: Map<string, ClientReferenceData>;
|
|
19
|
+
declare const SERVER_REFERENCE_REGISTRY: Map<string, ServerReferenceData>;
|
|
20
20
|
//#endregion
|
|
21
|
-
export {
|
|
21
|
+
export { CLIENT_REFERENCE_REGISTRY, SERVER_REFERENCE_REGISTRY, createClientModuleProxy, registerClientComponent, registerClientReference, registerServerReference };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new Map,t=new Map;let n=null;globalThis[`~rari`]?.bridge!==void 0&&(n=globalThis[`~rari`].bridge);function r(t,r,i){let a=`${r}#${i}`;e.set(a,{id:r,exportName:i,chunks:[r],name:i,async:!1}),Object.defineProperty(t,`$$typeof`,{value:Symbol.for(`react.client.reference`),enumerable:!1}),Object.defineProperty(t,`$$id`,{value:a,enumerable:!1}),Object.defineProperty(t,`$$async`,{value:!1,enumerable:!1});try{n&&typeof n.registerClientReference==`function`&&n.registerClientReference(a,r,i)}catch(e){console.error(e)}return t}function i(t,n,r){let i=`${n}#${r}`;e.set(i,{id:n,exportName:r,chunks:[n],name:r,async:!1})}function a(e,r,i){let a=`${r}#${i}`;t.set(a,{id:r,exportName:i,bound:!1}),Object.defineProperty(e,`$$typeof`,{value:Symbol.for(`react.server.reference`),enumerable:!1}),Object.defineProperty(e,`$$id`,{value:a,enumerable:!1}),Object.defineProperty(e,`$$bound`,{value:!1,enumerable:!1});try{n&&typeof n.registerServerReference==`function`&&n.registerServerReference(a,r,i)}catch(e){console.error(e)}return e}function o(e){return new Proxy({},{get(t,n){function i(){throw Error(`Attempted to call ${String(n)}() from the server but ${String(n)} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`)}return r(i,e,String(n))}})}const s=e,c=t;export{s as
|
|
1
|
+
const e=new Map,t=new Map;let n=null;globalThis[`~rari`]?.bridge!==void 0&&(n=globalThis[`~rari`].bridge);function r(t,r,i){let a=`${r}#${i}`;e.set(a,{id:r,exportName:i,chunks:[r],name:i,async:!1}),Object.defineProperty(t,`$$typeof`,{value:Symbol.for(`react.client.reference`),enumerable:!1}),Object.defineProperty(t,`$$id`,{value:a,enumerable:!1}),Object.defineProperty(t,`$$async`,{value:!1,enumerable:!1});try{n&&typeof n.registerClientReference==`function`&&n.registerClientReference(a,r,i)}catch(e){console.error(e)}return t}function i(t,n,r){let i=`${n}#${r}`;e.set(i,{id:n,exportName:r,chunks:[n],name:r,async:!1})}function a(e,r,i){let a=`${r}#${i}`;t.set(a,{id:r,exportName:i,bound:!1}),Object.defineProperty(e,`$$typeof`,{value:Symbol.for(`react.server.reference`),enumerable:!1}),Object.defineProperty(e,`$$id`,{value:a,enumerable:!1}),Object.defineProperty(e,`$$bound`,{value:!1,enumerable:!1});try{n&&typeof n.registerServerReference==`function`&&n.registerServerReference(a,r,i)}catch(e){console.error(e)}return e}function o(e){return new Proxy({},{get(t,n){function i(){throw Error(`Attempted to call ${String(n)}() from the server but ${String(n)} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`)}return r(i,e,String(n))}})}const s=e,c=t;export{s as CLIENT_REFERENCE_REGISTRY,c as SERVER_REFERENCE_REGISTRY,o as createClientModuleProxy,i as registerClientComponent,r as registerClientReference,a as registerServerReference};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{_ as e,d as t,g as n,h as r,m as i,n as a,p as o,y as s}from"../regex-constants-DMuIAFub.mjs";import{t as c}from"../get-client-component-
|
|
2
|
-
`),i=r.slice(0,-1);S=r.at(-1)||``;for(let e of i)if(e.trim())try{let t=e.indexOf(`:`);if(t===-1)continue;let n=e.substring(0,t),r=e.substring(t+1);if(r.startsWith(`I[`))try{let e=JSON.parse(r.substring(1));if(Array.isArray(e)&&e.length>=3){let[t,r,i]=e;l.set(`$L${n}`,{id:t,chunks:Array.isArray(r)?r:[r],name:i||`default`})}}catch(e){console.error(`Failed to parse import row:`,r,e)}else if(r.startsWith(`E{`))try{let e=JSON.parse(r.substring(1));console.error(`RSC stream error:`,e)}catch(e){console.error(`Failed to parse error row:`,r,e)}else if(r.startsWith(`Symbol.for(`))continue;else if(r.startsWith(`[`)){let e=JSON.parse(r);if(Array.isArray(e)&&e.length>=4){let[t,r,i]=e,a=i?.[`~boundaryId`];if(t===`$`&&(r===`react.suspense`||r===`suspense`)&&i&&a&&u.set(`$L${n}`,a),t===`$`&&i&&Object.hasOwn(i,`children`)&&typeof r==`string`&&r.startsWith(`$L`)){let e=u.get(r)||null;if(e){let t=g(i.children);b.set(e,t),C&&C.updateBoundary(e,t);continue}}}if(!v){let t=!0;if(Array.isArray(e)&&e.length>=4&&e[0]===`$`){let n=e[1],r=e[3],i=r?.[`~boundaryId`];typeof n==`string`&&(n===`react.suspense`||n===`suspense`)&&r&&i&&(t=!1)}t&&(v=g(e),C&&typeof C.updateRoot==`function`&&C.updateRoot())}}}catch(t){console.error(`Failed to parse stream line:`,e,t)}}}catch(e){console.error(`Error processing stream:`,e)}},T=()=>{let[,e]=_(0);h(()=>(C={updateBoundary:(t,n)=>{b.set(t,n),e(e=>e+1)},updateRoot:()=>{e(e=>e+1)}},()=>{C=null}),[]);let t=e=>{if(!e)return null;if(m(e)){let n=e.props,r=n?.[`~boundaryId`];if(n&&r){let e=b.get(r);if(e)return e}if(n&&n.children){let r=t(n.children);if(r!==n.children)return f(e,{...n,children:r})}return e}return Array.isArray(e)?e.map(e=>t(e)):e};return t(v)};return w(),{"~isRscResponse":!0,"~rscPromise":Promise.resolve(p(T)),readRoot(){return Promise.resolve(p(T))}}}buildRequestHeaders(){return{Accept:`text/x-component`,"Cache-Control":`no-cache, no-transform`}}async fetchWithTimeout(e,t){let n=new AbortController,r=setTimeout(()=>n.abort(),this.config.timeout);try{let i=await fetch(e,{...t,signal:n.signal});return clearTimeout(r),i}catch(e){throw clearTimeout(r),e}}async processRscResponse(e){if(await E(),C)try{let t=C(Promise.resolve(e));return{"~isRscResponse":!0,"~rscPromise":t,readRoot(){return t}}}catch{throw Error(`React Server DOM client not available`)}else throw Error(`React Server DOM client not available`)}async processRscResponseManually(e){let t=await e.text();return this.parseRscResponse(t)}parseRscResponse(e){let t=e.trim().split(s),n=new Map,r=new Map,i=[];for(let e of t){let t=e.indexOf(`:`);if(t===-1)continue;let a=e.substring(0,t),o=e.substring(t+1);if(o)try{if(o.startsWith(`I[`)){let e=o.substring(1),t=JSON.parse(e);if(Array.isArray(t)&&t.length>=3){let[e,r,i]=t;n.set(`$L${a}`,{id:e,chunks:Array.isArray(r)?r:[r],name:i||`default`})}}else if(o.startsWith(`E{`)){let e=o.substring(1),t=JSON.parse(e);i.push(t),console.error(`RSC: Server error`,t)}else if(o.startsWith(`[`)){let e=JSON.parse(o);r.set(a,e)}else if(o.startsWith(`Symbol.for(`))continue;else console.error(`Unknown RSC row format:`,e)}catch(t){console.error(`Failed to parse RSC row:`,e,t)}}if(i.length>0)throw Error(`RSC Server Error: ${i.map(e=>e.message||e).join(`, `)}`);let a=null,o=r.keys().toSorted((e,t)=>Number.parseInt(e)-Number.parseInt(t));for(let e of o){let t=r.get(e);if(Array.isArray(t)&&t.length>=2&&t[0]===`$`){let[,e,,n]=t,r=n?.[`~boundaryId`];if(e===`react.suspense`&&n&&r)continue;a=t;break}}return a?this.reconstructElementFromRscData(a,n):(console.error(`No valid root element found in RSC payload`,{elements:r,modules:n}),null)}reconstructElementFromRscData(e,t){if(e==null)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))if(e.length>=4&&e[0]===`$`){let[,n,r,i]=e,a=n;if(typeof n==`string`&&n.includes(`#`))a=x(n)||(({children:e,...t})=>p(`div`,{...t,"data-client-component":n,style:{border:`2px dashed #f00`,padding:`8px`,margin:`4px`,backgroundColor:`#fff0f0`}},p(`small`,{style:{color:`#c00`}},`Missing Client Component: ${n}`),e));else if(typeof n==`string`&&n.startsWith(`$L`)&&t.has(n)){let e=t.get(n);e&&(a=x(`${e.id}#${e.name}`)||(({children:t,...r})=>p(`div`,{...r,"data-client-component":n,style:{border:`2px dashed #f00`,padding:`8px`,margin:`4px`,backgroundColor:`#fff0f0`}},p(`small`,{style:{color:`#c00`}},`Missing Client Component: ${e.name} (${e.id})`),t)))}let o=i?this.processPropsRecursively(i,t):{};return p(a,{key:r,...o})}else return e.map(e=>this.reconstructElementFromRscData(e,t));return typeof e==`object`?null:e}processPropsRecursively(e,t){if(!e||typeof e!=`object`)return e;let n={};for(let[r,i]of Object.entries(e))if(r===`children`)if(Array.isArray(i))if(i.length>=2&&i[0]===`$`)n[r]=this.reconstructElementFromRscData(i,t);else{let e=i.map(e=>this.reconstructElementFromRscData(e,t)).filter(e=>e!=null);e.length===0?n[r]=null:e.length===1?n[r]=e[0]:n[r]=e}else n[r]=this.reconstructElementFromRscData(i,t);else r===`dangerouslySetInnerHTML`?n[r]=i:n[r]=this.reconstructElementFromRscData(i,t);return n}};function O({error:e,details:t}){return p(`div`,{className:`rsc-error`,style:{padding:`16px`,backgroundColor:`#fee`,border:`1px solid #fcc`,borderRadius:`4px`,margin:`8px 0`,fontFamily:`monospace`}},p(`h3`,{style:{margin:`0 0 8px 0`,color:`#c00`}},`RSC Error`),p(`p`,{style:{margin:`0 0 8px 0`}},e),t&&p(`details`,{style:{marginTop:`8px`}},p(`summary`,{style:{cursor:`pointer`}},`Error Details`),p(`pre`,{style:{fontSize:`12px`,overflow:`auto`,backgroundColor:`#f5f5f5`,padding:`8px`}},JSON.stringify(t,null,2))))}function k({componentId:e,props:t,fallback:n}){let[r,i]=_({data:null,loading:!0,error:null}),a=JSON.stringify(t),o=g(a);h(()=>{let n=!0;return o.current!==a&&(i({data:null,loading:!0,error:null}),o.current=a),D.fetchServerComponent(e,t).then(e=>{n&&i({data:e,loading:!1,error:null})}).catch(e=>{n&&i({data:null,loading:!1,error:e})}),()=>{n=!1}},[e,a]);let{data:s,loading:c,error:l}=r;return c?n||null:l?p(O,{error:`Error loading component`,details:{message:l.message,componentId:e}}):s?s[`~isRscResponse`]?p(d,{fallback:n||null},s.readRoot()):s:p(O,{error:`No data received for component: ${e}`,details:{componentId:e,dataType:typeof s,hasData:!!s}})}function A(e){let t=0;if(typeof window<`u`){let n=window;n[`~rscRefreshCounters`]=n[`~rscRefreshCounters`]||{},n[`~rscRefreshCounters`][e]===void 0&&(n[`~rscRefreshCounters`][e]=0),t=n[`~rscRefreshCounters`][e]}let n=n=>{let[r,i]=_(t);return h(()=>{let t=t=>{let n=t.detail;if(n&&n.filePath&&M(n.filePath)&&(D.clearCache(),typeof window<`u`)){let t=window;t[`~rscRefreshCounters`]||={},t[`~rscRefreshCounters`][e]=(t[`~rscRefreshCounters`][e]||0)+1,i(t[`~rscRefreshCounters`][e])}};return typeof window<`u`&&window.addEventListener(`rari:rsc-invalidate`,t),()=>{typeof window<`u`&&window.removeEventListener(`rari:rsc-invalidate`,t)}},[]),p(d,{fallback:null},p(k,{key:`${e}-${r}`,componentId:e,props:n,fallback:null}))};return n.displayName=`ServerComponent(${e})`,function(e){return p(n,e)}}function j(e,t){return D.fetchServerComponent(e,t)}function M(e){if(!e)return!1;try{return typeof globalThis<`u`&&globalThis[`~rari`].serverComponents?globalThis[`~rari`].serverComponents.has(e):!1}catch(e){return console.error(`Error checking if file is server component:`,e),!1}}if(import.meta.hot){let e=!1,t=[],n=new Map;function r(r,i){n.set(r,i),import.meta.hot.on(r,async n=>{if(!e){t.push({event:r,data:n});return}try{await i(n)}catch(e){console.error(`[rari] HMR: Error in handler for '${r}':`,e)}})}r(`rari:register-server-component`,e=>{e?.filePath&&typeof globalThis<`u`&&(globalThis[`~rari`].serverComponents=globalThis[`~rari`].serverComponents||new Set,globalThis[`~rari`].serverComponents.add(e.filePath))}),r(`rari:server-components-registry`,e=>{e?.serverComponents&&Array.isArray(e.serverComponents)&&typeof globalThis<`u`&&(globalThis[`~rari`].serverComponents=globalThis[`~rari`].serverComponents||new Set,e.serverComponents.forEach(e=>{globalThis[`~rari`].serverComponents?.add(e)}))}),r(`vite:beforeFullReload`,async e=>{e?.path&&M(e.path)&&await u({filePath:e.path,forceReload:!0})}),r(`rari:server-component-updated`,async e=>{let t=e?.id||e?.componentId,n=e?.t||e?.timestamp;if(t){if(typeof window<`u`){let r=new CustomEvent(`rari:rsc-invalidate`,{detail:{componentId:t,filePath:e.filePath||e.file,type:`server-component`,timestamp:n}});window.dispatchEvent(r)}}else e?.path&&M(e.path)&&await u({filePath:e.path,forceReload:!1})}),r(`rari:app-router-updated`,async e=>{try{if(!e||!e.routePath&&(!e.affectedRoutes||e.affectedRoutes.length===0))return;await i(e)}catch(e){console.error(`[rari] HMR: App router update failed:`,e)}}),r(`rari:server-action-updated`,async e=>{if(e?.filePath&&(D.clearCache(),typeof window<`u`)){let t=new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.filePath,type:`server-action`}});window.dispatchEvent(t)}});async function i(e){let t=e.fileType,n=e.filePath,r=e.routePath,i=e.affectedRoutes,o=e.manifestUpdated,u=e.metadata;e.metadataChanged&&u&&a(u);try{let e=`${y()}/_rari/hmr`,t=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`register`,file_path:n})});if(!t.ok){let e=await t.text(),n=`Component reload failed with status ${t.status}: ${e}`;throw console.error(`[rari] HMR:`,n),Error(n)}let r=await t.json();if(typeof r!=`object`||!r){let e=`Invalid reload response: null or non-object`;throw console.error(`[rari] HMR:`,e,r),Error(e)}if(r.success!==!0&&r.reloaded!==!0){let e=`Component reload unsuccessful: ${r.error||`unknown error`}`;throw console.error(`[rari] HMR:`,e,r),Error(e)}}catch(e){console.error(`[rari] HMR: Failed to reload component:`,e);return}let d=[r];switch(t){case`page`:d=[r];break;case`layout`:case`loading`:case`error`:case`not-found`:d=i;break;default:break}await s({routes:d,fileType:t,filePath:n,componentId:r}),o&&await l(),await c({routePath:r,affectedRoutes:i})}function a(e){if(!(typeof document>`u`)&&(e.title&&(document.title=e.title),e.description)){let t=document.querySelector(`meta[name="description"]`);t||(t=document.createElement(`meta`),t.setAttribute(`name`,`description`),document.head.appendChild(t)),t.setAttribute(`content`,e.description)}}function o(e){if(!e||e.length===0){D.clearCache();return}let t=[];for(let n of D.componentCache.keys())for(let r of e){if(n.includes(`route:${r}:`)||n.startsWith(`${r}:`)){t.push(n);break}if(r!==`/`&&n.includes(`route:${r}/`)){t.push(n);break}}for(let e of t)D.componentCache.delete(e)}async function s(e){let t=e.routes||[],n=e.fileType,r=e.filePath,i=e.componentId;if(i||r)try{let e=`${y()}/_rari/hmr`,t=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`invalidate`,componentId:i||r,filePath:r})}),n=await t.text();t.ok||console.error(`[rari] HMR: Server cache invalidation failed:`,t.status,n)}catch(e){console.error(`[rari] HMR: Failed to call server invalidation endpoint:`,e)}if(o(t),typeof window<`u`){let e=new CustomEvent(`rari:rsc-invalidate`,{detail:{routes:t,fileType:n}});window.dispatchEvent(e)}}async function c(e){let t=e.routePath,n=e.affectedRoutes||[t];if(!(typeof window>`u`))try{let e=window.location.pathname,r=new CustomEvent(`rari:app-router-rerender`,{detail:{routePath:t,affectedRoutes:n,currentPath:e,preserveParams:!0}});window.dispatchEvent(r)}catch(e){throw console.error(`[rari] HMR: Failed to trigger re-render:`,e),e}}async function l(){typeof window<`u`&&window[`~rari`]?.routeInfoCache&&window[`~rari`].routeInfoCache.clear()}async function u(e){let t=e?.filePath||e;if(D.clearCache(),typeof window<`u`){let e=new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:t}});window.dispatchEvent(e)}}t.length>0?(async()=>{try{for(;t.length>0;){let e=[...t];t.length=0;for(let{event:t,data:r}of e){let e=n.get(t);if(e)try{await e(r)}catch(e){console.error(`[rari] HMR: Error replaying buffered event '${t}':`,e)}}}}catch(e){console.error(`[rari] HMR: Error during event replay:`,e)}finally{e=!0}})():e=!0}var N=class{overlay;currentError;escapeKeyHandler;constructor(){this.overlay=null,this.currentError=null,this.escapeKeyHandler=null}show(e){this.currentError=e,this.overlay?this.updateOverlay(e):this.createOverlay(e)}hide(){this.overlay&&(this.overlay.remove(),this.overlay=null,this.currentError=null),this.escapeKeyHandler&&=(document.removeEventListener(`keydown`,this.escapeKeyHandler),null)}isVisible(){return this.overlay!==null}createOverlay(e){this.overlay=document.createElement(`div`),this.overlay.id=`rari-hmr-error-overlay`,this.updateOverlay(e),document.body.appendChild(this.overlay),this.escapeKeyHandler=e=>{e.key===`Escape`&&this.hide()},document.addEventListener(`keydown`,this.escapeKeyHandler)}updateOverlay(e){if(!this.overlay)return;this.overlay.replaceChildren();let t=document.createElement(`div`);t.style.cssText=`position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.85); z-index: 999999; display: flex; align-items: center; justify-content: center; padding: 2rem; backdrop-filter: blur(4px);`;let n=document.createElement(`div`);n.style.cssText=`background: #1e1e1e; color: #e0e0e0; border-radius: 0.5rem; padding: 2rem; max-width: 50rem; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4); border: 1px solid #ef4444;`;let r=document.createElement(`div`);r.style.cssText=`display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem;`;let i=document.createElement(`div`);i.style.cssText=`display: flex; align-items: center; gap: 0.75rem;`;let a=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);a.style.cssText=`width: 2rem; height: 2rem; color: #ef4444;`,a.setAttribute(`fill`,`none`),a.setAttribute(`stroke`,`currentColor`),a.setAttribute(`viewBox`,`0 0 24 24`);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);o.setAttribute(`stroke-linecap`,`round`),o.setAttribute(`stroke-linejoin`,`round`),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`d`,`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z`),a.appendChild(o);let s=document.createElement(`h1`);s.style.cssText=`margin: 0; font-size: 1.5rem; font-weight: 700; color: #ef4444;`,s.textContent=`Build Error`,i.appendChild(a),i.appendChild(s);let c=document.createElement(`button`);if(c.style.cssText=`background: transparent; border: none; color: #9ca3af; cursor: pointer; padding: 0.5rem; border-radius: 0.25rem; transition: all 0.2s; font-size: 1.5rem; line-height: 1; width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center;`,c.textContent=`×`,c.setAttribute(`aria-label`,`Close overlay`),c.onclick=()=>this.hide(),c.onmouseover=()=>{c.style.background=`rgba(255,255,255,0.1)`,c.style.color=`#e0e0e0`},c.onmouseout=()=>{c.style.background=`transparent`,c.style.color=`#9ca3af`},c.onfocus=()=>{c.style.background=`rgba(255,255,255,0.1)`,c.style.color=`#e0e0e0`},c.onblur=()=>{c.style.background=`transparent`,c.style.color=`#9ca3af`},r.appendChild(i),r.appendChild(c),n.appendChild(r),e.filePath){let t=document.createElement(`div`);t.style.cssText=`margin-bottom: 1rem; padding: 0.75rem; background: rgba(0, 0, 0, 0.2); border-radius: 0.375rem; font-family: monospace; font-size: 0.875rem;`;let r=document.createElement(`strong`);r.textContent=`File: `,t.appendChild(r),t.appendChild(document.createTextNode(e.filePath)),n.appendChild(t)}let l=document.createElement(`div`);l.style.cssText=`margin-bottom: 1.5rem;`;let u=document.createElement(`h2`);u.style.cssText=`margin: 0 0 0.75rem 0; font-size: 1rem; font-weight: 600; color: #fca5a5;`,u.textContent=`Error Message:`;let d=document.createElement(`pre`);if(d.style.cssText=`margin: 0; padding: 1rem; background: rgba(239, 68, 68, 0.1); border-left: 4px solid #ef4444; border-radius: 0.375rem; overflow-x: auto; font-family: monospace; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: #fca5a5;`,d.textContent=e.message??`An error occurred`,l.appendChild(u),l.appendChild(d),n.appendChild(l),e.stack){let t=document.createElement(`details`);t.style.cssText=`margin-top: 1rem; cursor: pointer;`;let r=document.createElement(`summary`);r.style.cssText=`font-weight: 600; margin-bottom: 0.5rem; user-select: none;`,r.textContent=`Stack Trace`;let i=document.createElement(`pre`);i.style.cssText=`margin: 0; padding: 0.75rem; background: rgba(0, 0, 0, 0.2); border-radius: 0.375rem; overflow-x: auto; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;`,i.textContent=e.stack,t.appendChild(r),t.appendChild(i),n.appendChild(t)}let f=document.createElement(`div`);f.style.cssText=`margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid #374151; display: flex; gap: 0.75rem; align-items: center;`;let p=document.createElement(`button`);p.style.cssText=`padding: 0.625rem 1.25rem; background: #ef4444; color: white; border: none; border-radius: 0.375rem; cursor: pointer; font-weight: 600; font-size: 0.875rem; transition: all 0.2s;`,p.textContent=`Reload Page`,p.onclick=()=>window.location.reload(),p.onmouseover=()=>{p.style.background=`#dc2626`},p.onmouseout=()=>{p.style.background=`#ef4444`},p.onfocus=()=>{p.style.background=`#dc2626`},p.onblur=()=>{p.style.background=`#ef4444`};let m=document.createElement(`button`);m.style.cssText=`padding: 0.625rem 1.25rem; background: #374151; color: #e0e0e0; border: none; border-radius: 0.375rem; cursor: pointer; font-weight: 600; font-size: 0.875rem; transition: all 0.2s;`,m.textContent=`Dismiss`,m.onclick=()=>this.hide(),m.onmouseover=()=>{m.style.background=`#4b5563`},m.onmouseout=()=>{m.style.background=`#374151`},m.onfocus=()=>{m.style.background=`#4b5563`},m.onblur=()=>{m.style.background=`#374151`};let h=document.createElement(`span`);h.style.cssText=`margin-left: auto; font-size: 0.75rem; color: #9ca3af;`;let g=new Date(e.timestamp);h.textContent=Number.isNaN(g.valueOf())?``:g.toLocaleTimeString(),f.appendChild(p),f.appendChild(m),f.appendChild(h),n.appendChild(f),t.appendChild(n),this.overlay.appendChild(t)}};let P=null;function F(){return P||=new N,P}if(import.meta.hot){let e=F();import.meta.hot.on(`rari:hmr-error`,t=>{let n=t.msg||t.message,r=t.file||t.filePath,i=t.t||t.timestamp,a=t.count||t.errorCount,o=t.max||t.maxErrors;console.error(`[rari] HMR: Build error:`,n),r&&console.error(`[rari] HMR: File:`,r),t.stack&&console.error(`[rari] HMR: Stack:`,t.stack),e.show({message:n,stack:t.stack,filePath:r,timestamp:i}),a&&o&&(a>=o?console.error(`[rari] HMR: Maximum error count (${o}) reached. Consider restarting the dev server if issues persist.`):a>=o-2&&console.warn(`[rari] HMR: Error count: ${a}/${o}. Approaching maximum error threshold.`))}),import.meta.hot.on(`rari:hmr-error-cleared`,()=>{e.hide()}),import.meta.hot.on(`vite:error`,t=>{e.show({message:t.err?.message||`Unknown Vite error`,stack:t.err?.stack,filePath:t.err?.file,timestamp:Date.now()})})}export{O as RscErrorComponent,S as createClientModuleMap,A as createServerComponentWrapper,j as fetchServerComponent,x as getClientComponent,b as registerClientComponent,D as rscClient};
|
|
1
|
+
import{_ as e,d as t,g as n,h as r,m as i,n as a,p as o,y as s}from"../regex-constants-DMuIAFub.mjs";import{t as c}from"../get-client-component-CpMI09nb.mjs";import"../preload-components-5Y8ZOaFG.mjs";import{createFromFetch as l,createFromReadableStream as u}from"./react-server-dom-rari-client.mjs";import{Suspense as d,cloneElement as f,createElement as p,isValidElement as m,useEffect as h,useRef as g,useState as _}from"react";import*as v from"react-dom/client";function y(){return import.meta.env?.RARI_SERVER_URL?import.meta.env.RARI_SERVER_URL:typeof window<`u`?window.location.origin:`http://localhost:3000`}if(globalThis[`~rari`]===void 0&&(globalThis[`~rari`]={}),globalThis[`~rari`].isDevelopment=process.env.NODE_ENV!==`production`,globalThis[`~clientComponents`]===void 0&&(globalThis[`~clientComponents`]={}),globalThis[`~clientComponentNames`]===void 0&&(globalThis[`~clientComponentNames`]={}),globalThis[`~clientComponentPaths`]===void 0&&(globalThis[`~clientComponentPaths`]={}),typeof window<`u`){window[`~rari`]||(window[`~rari`]=globalThis[`~rari`]),window[`~rari`].streaming||(window[`~rari`].streaming={bufferedRows:[],bufferedEvents:[]}),window[`~rari`].streaming.bufferedEvents||(window[`~rari`].streaming.bufferedEvents=[]),window[`~rari`].boundaryModules||(window[`~rari`].boundaryModules=new Map),window[`~rari`].pendingBoundaryHydrations||(window[`~rari`].pendingBoundaryHydrations=new Map),globalThis[`~rari`].processBoundaryUpdate=function(t,s,c){let l=document.querySelector(`[data-boundary-id="${t}"]`);if(l)try{let u=s.indexOf(`:`);if(u===-1){console.warn(`[rari] Invalid RSC row format (no colon):`,s);return}let d=s.substring(0,u),f=s.substring(u+1);if(f.startsWith(`I[`)){try{let e=JSON.parse(f.substring(1));if(Array.isArray(e)&&e.length>=3){let[t,n,r]=e,i=`$L${d}`;window[`~rari`].boundaryModules?.set(i,{id:t,chunks:Array.isArray(n)?n:[n],name:r||`default`})}}catch(e){console.error(`[rari] Failed to parse import row:`,f,e)}return}let p;try{p=JSON.parse(f)}catch(e){console.error(`[rari] Failed to parse RSC content:`,f,e);return}function m(e){if(!e)return!1;if(typeof e==`string`)return e.startsWith(`$L`);if(Array.isArray(e)){if(e.length>=4&&e[0]===`$`){let[,t]=e;if(typeof t==`string`&&t.startsWith(`$L`))return!0;let n=e[3];if(n&&n.children)return m(n.children)}return e.some(e=>m(e))}return!1}if(m(p)){if(window[`~rari`].pendingBoundaryHydrations?.set(t,{content:p,element:l,rowId:c}),globalThis[`~rari`].hydrateClientComponents){let e=globalThis[`~rari`].hydrateClientComponents;e(t,p,l)}return}function h(t){let s=t=>t.replace(o,`&`).replace(n,`<`).replace(r,`>`).replace(e,`"`).replace(i,`'`),c=new Set(`div.span.p.ul.ol.li.a.img.section.article.header.footer.nav.main.aside.strong.em.b.i.button.input.label.form.select.option.textarea.h1.h2.h3.h4.h5.h6.table.thead.tbody.tr.td.th.code.pre.blockquote.hr.br.small.mark.del.ins.sub.sup.abbr.time.figure.figcaption.details.summary.dialog.menu.menuitem.canvas.svg.path.circle.rect.line.polygon.polyline.ellipse.text.g.defs.use.symbol.clippath.mask.pattern.lineargradient.radialgradient.stop.image.video.audio.source.track.picture.dl.dt.dd.fieldset.legend`.split(`.`));if(!t)return``;if(typeof t==`string`||typeof t==`number`)return s(String(t));if(Array.isArray(t)){if(t.length>=4&&t[0]===`$`){let[,e,,n]=t,r=typeof e==`string`&&c.has(e.toLowerCase())?e.toLowerCase():`div`,i=null,o=``,l=``;if(n){for(let[e,t]of Object.entries(n))if(e===`dangerouslySetInnerHTML`&&t&&typeof t==`object`&&`__html`in t)i=t.__html;else if(e!==`children`&&e!==`~boundaryId`){let n=e===`className`?`class`:e;if(e===`style`&&typeof t==`object`&&t){let e=Object.entries(t).map(([e,t])=>`${e.replace(a,`$1-$2`).toLowerCase()}:${String(t)}`).join(`;`);l+=` style="${s(e)}"`}else typeof t==`string`||typeof t==`number`?l+=` ${n}="${s(String(t))}"`:typeof t==`boolean`&&t&&(l+=` ${n}`)}i===null&&n.children&&(o=h(n.children))}return`<${r}${l}>${i===null?o:i}</${r}>`}return t.map(h).join(``)}return``}let g=h(p);g&&requestAnimationFrame(()=>{let e=document.contains(l);e&&(l.innerHTML=g,l.classList.add(`rari-boundary-resolved`)),window.dispatchEvent(new CustomEvent(`rari:boundary-resolved`,{detail:{boundaryId:t,rscRow:s,rowId:c,element:l,wasAttached:e}}))})}catch(e){console.error(`[rari] Error processing boundary update:`,e)}};let t=window,s=globalThis;t[`~rari`].streaming?.bufferedEvents&&t[`~rari`].streaming.bufferedEvents.length>0&&(t[`~rari`].streaming.bufferedEvents.forEach(e=>{let{boundaryId:t,rscRow:n,rowId:r}=e;s[`~rari`].processBoundaryUpdate?.(t,n,r)}),t[`~rari`].streaming.bufferedEvents=[]),window.addEventListener(`rari:boundary-update`,e=>{let{boundaryId:t,rscRow:n,rowId:r}=e.detail;s[`~rari`].processBoundaryUpdate&&s[`~rari`].processBoundaryUpdate(t,n,r)})}function b(e,n,r){let i=r===`default`?e.name||n.split(`/`).pop()?.replace(t,``)||`DefaultComponent`:r,a=i,o={id:a,path:n,type:`client`,component:e,registered:!0};globalThis[`~clientComponents`][a]=o,globalThis[`~clientComponents`][n]=o,globalThis[`~clientComponentPaths`][n]=a,globalThis[`~clientComponentNames`][i]=a,e&&(e[`~isClientComponent`]=!0,e[`~clientComponentId`]=a),typeof window<`u`&&fetch(`/_rari/register-client`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({component_id:a,file_path:n,export_name:r})}).catch(e=>{console.error(`[rari] Failed to register client component with server:`,e)})}function x(e){return c(e)}function S(){let e={};for(let[t,n]of Object.entries(globalThis[`~clientComponents`]))e[t]={id:t,chunks:[n.path],name:t,async:!1,default:n.component};return e}let C=l,w=u,T=null;async function E(){return T||(T=(async()=>{try{return C=l,w=u,typeof w!=`function`&&(w=null),typeof C!=`function`&&(C=null),v}catch(e){return console.error(`Failed to load react-dom/client RSC functions:`,e),C=null,w=null,null}})(),T)}const D=new class{componentCache;moduleCache;inflightRequests;config;constructor(){this.componentCache=new Map,this.moduleCache=new Map,this.inflightRequests=new Map,this.config={maxRetries:5,retryDelay:500,timeout:1e4}}configure(e){this.config={...this.config,...e}}clearCache(){this.componentCache.clear(),this.moduleCache.clear()}async fetchServerComponent(e,t={}){let n=typeof window<`u`&&window[`~rari`]?.hmr?.refreshCounters?.[e]||0,r=`${e}:${JSON.stringify(t)}:hmr:${n}`;if(this.componentCache.has(r))return this.componentCache.get(r);if(this.inflightRequests.has(r))return this.inflightRequests.get(r);let i=this.fetchServerComponentStream(e,t);this.inflightRequests.set(r,i);try{let e=await i;return this.componentCache.set(r,e),e}finally{this.inflightRequests.delete(r)}}async fetchServerComponentStream(e,t={}){await E();let n=(()=>{let e=[`/_rari/stream`];try{if(typeof window<`u`&&(window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`)){let t=y();t&&e.push(`${t}/_rari/stream`)}}catch{}return e})(),r=null,i=null,a=async()=>{for(let r of n)try{let n=await this.fetchWithTimeout(r,{method:`POST`,headers:{"Content-Type":`application/json`,...this.buildRequestHeaders()},body:JSON.stringify({component_id:e,props:t})});if(n.ok)return n;i=Error(`HTTP ${n.status}: ${await n.text()}`)}catch(e){i=e}return null};if(r=await a(),r||=(await new Promise(e=>setTimeout(e,this.config.retryDelay)),await a()),!r)throw i||Error(`Failed to reach stream endpoint`);if(!r.ok){let e=await r.text();throw Error(`Server responded with ${r.status}: ${e}`)}let o=r.body;if(!o)throw Error(`No ReadableStream from stream response`);let s=o.getReader(),c=new TextDecoder,l=new Map,u=new Map,g=e=>{if(!p)return console.error(`React not available for RSC conversion`),null;if(!e)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(e.length>=3&&e[0]===`$`){let[,t,n,r]=e;if(t===`react.suspense`||t===`suspense`)return p(d,{fallback:g(r?.fallback)||null},r?.children?g(r.children):null);let i=r?{...r}:{};if(r?.children){let e=g(r.children);Array.isArray(e)?i.children=e.map((e,t)=>m(e)?f(e,{key:e.key??t}):e):i.children=e}if(typeof t==`string`){if(t.startsWith(`$L`)){let e=l.get(t);if(e){let t=x(`${e.id}#${e.name||`default`}`);if(t)return p(t,n?{...i,key:n}:i)}return i&&i.children?i.children:null}if(t.includes(`.tsx#`)||t.includes(`.jsx#`)){let e=x(t);return e?p(e,n?{...i,key:n}:i):(console.error(`Failed to resolve client component:`,t),null)}else return i&&Object.hasOwn(i,`~boundaryId`)&&(i={...i},delete i[`~boundaryId`]),p(t,n?{...i,key:n}:i)}else console.error(`Unknown RSC element type:`,t)}return e.map(e=>g(e))}return typeof e==`object`?(console.error(`Unexpected object in RSC conversion:`,e),null):e},v=null,b=new Map,S=``,C=null,w=async()=>{try{for(;;){let{value:e,done:t}=await s.read();if(t)break;let n=c.decode(e,{stream:!0});S+=n;let r=S.split(`
|
|
2
|
+
`),i=r.slice(0,-1);S=r.at(-1)||``;for(let e of i)if(e.trim())try{let t=e.indexOf(`:`);if(t===-1)continue;let n=e.substring(0,t),r=e.substring(t+1);if(r.startsWith(`I[`))try{let e=JSON.parse(r.substring(1));if(Array.isArray(e)&&e.length>=3){let[t,r,i]=e;l.set(`$L${n}`,{id:t,chunks:Array.isArray(r)?r:[r],name:i||`default`})}}catch(e){console.error(`Failed to parse import row:`,r,e)}else if(r.startsWith(`E{`))try{let e=JSON.parse(r.substring(1));console.error(`RSC stream error:`,e)}catch(e){console.error(`Failed to parse error row:`,r,e)}else if(r.startsWith(`Symbol.for(`))continue;else if(r.startsWith(`[`)){let e=JSON.parse(r);if(Array.isArray(e)&&e.length>=4){let[t,r,i]=e,a=i?.[`~boundaryId`];if(t===`$`&&(r===`react.suspense`||r===`suspense`)&&i&&a&&u.set(`$L${n}`,a),t===`$`&&i&&Object.hasOwn(i,`children`)&&typeof r==`string`&&r.startsWith(`$L`)){let e=u.get(r)||null;if(e){let t=g(i.children);b.set(e,t),C&&C.updateBoundary(e,t);continue}}}if(!v){let t=!0;if(Array.isArray(e)&&e.length>=4&&e[0]===`$`){let n=e[1],r=e[3],i=r?.[`~boundaryId`];typeof n==`string`&&(n===`react.suspense`||n===`suspense`)&&r&&i&&(t=!1)}t&&(v=g(e),C&&typeof C.updateRoot==`function`&&C.updateRoot())}}}catch(t){console.error(`Failed to parse stream line:`,e,t)}}}catch(e){console.error(`Error processing stream:`,e)}},T=()=>{let[,e]=_(0);h(()=>(C={updateBoundary:(t,n)=>{b.set(t,n),e(e=>e+1)},updateRoot:()=>{e(e=>e+1)}},()=>{C=null}),[]);let t=e=>{if(!e)return null;if(m(e)){let n=e.props,r=n?.[`~boundaryId`];if(n&&r){let e=b.get(r);if(e)return e}if(n&&n.children){let r=t(n.children);if(r!==n.children)return f(e,{...n,children:r})}return e}return Array.isArray(e)?e.map(e=>t(e)):e};return t(v)};return w(),{"~isRscResponse":!0,"~rscPromise":Promise.resolve(p(T)),readRoot(){return Promise.resolve(p(T))}}}buildRequestHeaders(){return{Accept:`text/x-component`,"Cache-Control":`no-cache, no-transform`}}async fetchWithTimeout(e,t){let n=new AbortController,r=setTimeout(()=>n.abort(),this.config.timeout);try{let i=await fetch(e,{...t,signal:n.signal});return clearTimeout(r),i}catch(e){throw clearTimeout(r),e}}async processRscResponse(e){if(await E(),C)try{let t=C(Promise.resolve(e));return{"~isRscResponse":!0,"~rscPromise":t,readRoot(){return t}}}catch{throw Error(`React Server DOM client not available`)}else throw Error(`React Server DOM client not available`)}async processRscResponseManually(e){let t=await e.text();return this.parseRscResponse(t)}parseRscResponse(e){let t=e.trim().split(s),n=new Map,r=new Map,i=[];for(let e of t){let t=e.indexOf(`:`);if(t===-1)continue;let a=e.substring(0,t),o=e.substring(t+1);if(o)try{if(o.startsWith(`I[`)){let e=o.substring(1),t=JSON.parse(e);if(Array.isArray(t)&&t.length>=3){let[e,r,i]=t;n.set(`$L${a}`,{id:e,chunks:Array.isArray(r)?r:[r],name:i||`default`})}}else if(o.startsWith(`E{`)){let e=o.substring(1),t=JSON.parse(e);i.push(t),console.error(`RSC: Server error`,t)}else if(o.startsWith(`[`)){let e=JSON.parse(o);r.set(a,e)}else if(o.startsWith(`Symbol.for(`))continue;else console.error(`Unknown RSC row format:`,e)}catch(t){console.error(`Failed to parse RSC row:`,e,t)}}if(i.length>0)throw Error(`RSC Server Error: ${i.map(e=>e.message||e).join(`, `)}`);let a=null,o=r.keys().toSorted((e,t)=>Number.parseInt(e)-Number.parseInt(t));for(let e of o){let t=r.get(e);if(Array.isArray(t)&&t.length>=2&&t[0]===`$`){let[,e,,n]=t,r=n?.[`~boundaryId`];if(e===`react.suspense`&&n&&r)continue;a=t;break}}return a?this.reconstructElementFromRscData(a,n):(console.error(`No valid root element found in RSC payload`,{elements:r,modules:n}),null)}reconstructElementFromRscData(e,t){if(e==null)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))if(e.length>=4&&e[0]===`$`){let[,n,r,i]=e,a=n;if(typeof n==`string`&&n.includes(`#`))a=x(n)||(({children:e,...t})=>p(`div`,{...t,"data-client-component":n,style:{border:`2px dashed #f00`,padding:`8px`,margin:`4px`,backgroundColor:`#fff0f0`}},p(`small`,{style:{color:`#c00`}},`Missing Client Component: ${n}`),e));else if(typeof n==`string`&&n.startsWith(`$L`)&&t.has(n)){let e=t.get(n);e&&(a=x(`${e.id}#${e.name}`)||(({children:t,...r})=>p(`div`,{...r,"data-client-component":n,style:{border:`2px dashed #f00`,padding:`8px`,margin:`4px`,backgroundColor:`#fff0f0`}},p(`small`,{style:{color:`#c00`}},`Missing Client Component: ${e.name} (${e.id})`),t)))}let o=i?this.processPropsRecursively(i,t):{};return p(a,{key:r,...o})}else return e.map(e=>this.reconstructElementFromRscData(e,t));return typeof e==`object`?null:e}processPropsRecursively(e,t){if(!e||typeof e!=`object`)return e;let n={};for(let[r,i]of Object.entries(e))if(r===`children`)if(Array.isArray(i))if(i.length>=2&&i[0]===`$`)n[r]=this.reconstructElementFromRscData(i,t);else{let e=i.map(e=>this.reconstructElementFromRscData(e,t)).filter(e=>e!=null);e.length===0?n[r]=null:e.length===1?n[r]=e[0]:n[r]=e}else n[r]=this.reconstructElementFromRscData(i,t);else r===`dangerouslySetInnerHTML`?n[r]=i:n[r]=this.reconstructElementFromRscData(i,t);return n}};function O({error:e,details:t}){return p(`div`,{className:`rsc-error`,style:{padding:`16px`,backgroundColor:`#fee`,border:`1px solid #fcc`,borderRadius:`4px`,margin:`8px 0`,fontFamily:`monospace`}},p(`h3`,{style:{margin:`0 0 8px 0`,color:`#c00`}},`RSC Error`),p(`p`,{style:{margin:`0 0 8px 0`}},e),t&&p(`details`,{style:{marginTop:`8px`}},p(`summary`,{style:{cursor:`pointer`}},`Error Details`),p(`pre`,{style:{fontSize:`12px`,overflow:`auto`,backgroundColor:`#f5f5f5`,padding:`8px`}},JSON.stringify(t,null,2))))}function k({componentId:e,props:t,fallback:n}){let[r,i]=_({data:null,loading:!0,error:null}),a=JSON.stringify(t),o=g(a);h(()=>{let n=!0;return o.current!==a&&(i({data:null,loading:!0,error:null}),o.current=a),D.fetchServerComponent(e,t).then(e=>{n&&i({data:e,loading:!1,error:null})}).catch(e=>{n&&i({data:null,loading:!1,error:e})}),()=>{n=!1}},[e,a]);let{data:s,loading:c,error:l}=r;return c?n||null:l?p(O,{error:`Error loading component`,details:{message:l.message,componentId:e}}):s?s[`~isRscResponse`]?p(d,{fallback:n||null},s.readRoot()):s:p(O,{error:`No data received for component: ${e}`,details:{componentId:e,dataType:typeof s,hasData:!!s}})}function A(e){let t=0;if(typeof window<`u`){let n=window;n[`~rari`].hmr||(n[`~rari`].hmr={refreshCounters:{}}),n[`~rari`].hmr.refreshCounters[e]===void 0&&(n[`~rari`].hmr.refreshCounters[e]=0),t=n[`~rari`].hmr.refreshCounters[e]}let n=n=>{let[r,i]=_(t);return h(()=>{let t=t=>{let n=t.detail;if(n&&n.filePath&&M(n.filePath)&&(D.clearCache(),typeof window<`u`)){let t=window;t[`~rari`].hmr||(t[`~rari`].hmr={refreshCounters:{}}),t[`~rari`].hmr.refreshCounters[e]=(t[`~rari`].hmr.refreshCounters[e]||0)+1,i(t[`~rari`].hmr.refreshCounters[e])}};return typeof window<`u`&&window.addEventListener(`rari:rsc-invalidate`,t),()=>{typeof window<`u`&&window.removeEventListener(`rari:rsc-invalidate`,t)}},[]),p(d,{fallback:null},p(k,{key:`${e}-${r}`,componentId:e,props:n,fallback:null}))};return n.displayName=`ServerComponent(${e})`,function(e){return p(n,e)}}function j(e,t){return D.fetchServerComponent(e,t)}function M(e){if(!e)return!1;try{return typeof globalThis<`u`&&globalThis[`~rari`].serverComponents?globalThis[`~rari`].serverComponents.has(e):!1}catch(e){return console.error(`Error checking if file is server component:`,e),!1}}if(import.meta.hot){let e=!1,t=[],n=new Map;function r(r,i){n.set(r,i),import.meta.hot.on(r,async n=>{if(!e){t.push({event:r,data:n});return}try{await i(n)}catch(e){console.error(`[rari] HMR: Error in handler for '${r}':`,e)}})}r(`rari:register-server-component`,e=>{e?.filePath&&typeof globalThis<`u`&&(globalThis[`~rari`].serverComponents=globalThis[`~rari`].serverComponents||new Set,globalThis[`~rari`].serverComponents.add(e.filePath))}),r(`rari:server-components-registry`,e=>{e?.serverComponents&&Array.isArray(e.serverComponents)&&typeof globalThis<`u`&&(globalThis[`~rari`].serverComponents=globalThis[`~rari`].serverComponents||new Set,e.serverComponents.forEach(e=>{globalThis[`~rari`].serverComponents?.add(e)}))}),r(`vite:beforeFullReload`,async e=>{e?.path&&M(e.path)&&await u({filePath:e.path,forceReload:!0})}),r(`rari:server-component-updated`,async e=>{let t=e?.id||e?.componentId,n=e?.t||e?.timestamp;if(t){if(typeof window<`u`){let r=new CustomEvent(`rari:rsc-invalidate`,{detail:{componentId:t,filePath:e.filePath||e.file,type:`server-component`,timestamp:n}});window.dispatchEvent(r)}}else e?.path&&M(e.path)&&await u({filePath:e.path,forceReload:!1})}),r(`rari:app-router-updated`,async e=>{try{if(!e||!e.routePath&&(!e.affectedRoutes||e.affectedRoutes.length===0))return;await i(e)}catch(e){console.error(`[rari] HMR: App router update failed:`,e)}}),r(`rari:server-action-updated`,async e=>{if(e?.filePath&&(D.clearCache(),typeof window<`u`)){let t=new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:e.filePath,type:`server-action`}});window.dispatchEvent(t)}});async function i(e){let t=e.fileType,n=e.filePath,r=e.routePath,i=e.affectedRoutes,o=e.manifestUpdated,u=e.metadata;e.metadataChanged&&u&&a(u);try{let e=`${y()}/_rari/hmr`,t=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`register`,file_path:n})});if(!t.ok){let e=await t.text(),n=`Component reload failed with status ${t.status}: ${e}`;throw console.error(`[rari] HMR:`,n),Error(n)}let r=await t.json();if(typeof r!=`object`||!r){let e=`Invalid reload response: null or non-object`;throw console.error(`[rari] HMR:`,e,r),Error(e)}if(r.success!==!0&&r.reloaded!==!0){let e=`Component reload unsuccessful: ${r.error||`unknown error`}`;throw console.error(`[rari] HMR:`,e,r),Error(e)}}catch(e){console.error(`[rari] HMR: Failed to reload component:`,e);return}let d=[r];switch(t){case`page`:d=[r];break;case`layout`:case`loading`:case`error`:case`not-found`:d=i;break;default:break}await s({routes:d,fileType:t,filePath:n,componentId:r}),o&&await l(),await c({routePath:r,affectedRoutes:i})}function a(e){if(!(typeof document>`u`)&&(e.title&&(document.title=e.title),e.description)){let t=document.querySelector(`meta[name="description"]`);t||(t=document.createElement(`meta`),t.setAttribute(`name`,`description`),document.head.appendChild(t)),t.setAttribute(`content`,e.description)}}function o(e){if(!e||e.length===0){D.clearCache();return}let t=[];for(let n of D.componentCache.keys())for(let r of e){if(n.includes(`route:${r}:`)||n.startsWith(`${r}:`)){t.push(n);break}if(r!==`/`&&n.includes(`route:${r}/`)){t.push(n);break}}for(let e of t)D.componentCache.delete(e)}async function s(e){let t=e.routes||[],n=e.fileType,r=e.filePath,i=e.componentId;if(i||r)try{let e=`${y()}/_rari/hmr`,t=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`invalidate`,componentId:i||r,filePath:r})}),n=await t.text();t.ok||console.error(`[rari] HMR: Server cache invalidation failed:`,t.status,n)}catch(e){console.error(`[rari] HMR: Failed to call server invalidation endpoint:`,e)}if(o(t),typeof window<`u`){let e=new CustomEvent(`rari:rsc-invalidate`,{detail:{routes:t,fileType:n}});window.dispatchEvent(e)}}async function c(e){let t=e.routePath,n=e.affectedRoutes||[t];if(!(typeof window>`u`))try{let e=window.location.pathname,r=new CustomEvent(`rari:app-router-rerender`,{detail:{routePath:t,affectedRoutes:n,currentPath:e,preserveParams:!0}});window.dispatchEvent(r)}catch(e){throw console.error(`[rari] HMR: Failed to trigger re-render:`,e),e}}async function l(){typeof window<`u`&&window[`~rari`]?.routeInfoCache&&window[`~rari`].routeInfoCache.clear()}async function u(e){let t=e?.filePath||e;if(D.clearCache(),typeof window<`u`){let e=new CustomEvent(`rari:rsc-invalidate`,{detail:{filePath:t}});window.dispatchEvent(e)}}t.length>0?(async()=>{try{for(;t.length>0;){let e=[...t];t.length=0;for(let{event:t,data:r}of e){let e=n.get(t);if(e)try{await e(r)}catch(e){console.error(`[rari] HMR: Error replaying buffered event '${t}':`,e)}}}}catch(e){console.error(`[rari] HMR: Error during event replay:`,e)}finally{e=!0}})():e=!0}var N=class{overlay;currentError;escapeKeyHandler;constructor(){this.overlay=null,this.currentError=null,this.escapeKeyHandler=null}show(e){this.currentError=e,this.overlay?this.updateOverlay(e):this.createOverlay(e)}hide(){this.overlay&&(this.overlay.remove(),this.overlay=null,this.currentError=null),this.escapeKeyHandler&&=(document.removeEventListener(`keydown`,this.escapeKeyHandler),null)}isVisible(){return this.overlay!==null}createOverlay(e){this.overlay=document.createElement(`div`),this.overlay.id=`rari-hmr-error-overlay`,this.updateOverlay(e),document.body.appendChild(this.overlay),this.escapeKeyHandler=e=>{e.key===`Escape`&&this.hide()},document.addEventListener(`keydown`,this.escapeKeyHandler)}updateOverlay(e){if(!this.overlay)return;this.overlay.replaceChildren();let t=document.createElement(`div`);t.style.cssText=`position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.85); z-index: 999999; display: flex; align-items: center; justify-content: center; padding: 2rem; backdrop-filter: blur(4px);`;let n=document.createElement(`div`);n.style.cssText=`background: #1e1e1e; color: #e0e0e0; border-radius: 0.5rem; padding: 2rem; max-width: 50rem; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4); border: 1px solid #ef4444;`;let r=document.createElement(`div`);r.style.cssText=`display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem;`;let i=document.createElement(`div`);i.style.cssText=`display: flex; align-items: center; gap: 0.75rem;`;let a=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);a.style.cssText=`width: 2rem; height: 2rem; color: #ef4444;`,a.setAttribute(`fill`,`none`),a.setAttribute(`stroke`,`currentColor`),a.setAttribute(`viewBox`,`0 0 24 24`);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);o.setAttribute(`stroke-linecap`,`round`),o.setAttribute(`stroke-linejoin`,`round`),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`d`,`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z`),a.appendChild(o);let s=document.createElement(`h1`);s.style.cssText=`margin: 0; font-size: 1.5rem; font-weight: 700; color: #ef4444;`,s.textContent=`Build Error`,i.appendChild(a),i.appendChild(s);let c=document.createElement(`button`);if(c.style.cssText=`background: transparent; border: none; color: #9ca3af; cursor: pointer; padding: 0.5rem; border-radius: 0.25rem; transition: all 0.2s; font-size: 1.5rem; line-height: 1; width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center;`,c.textContent=`×`,c.setAttribute(`aria-label`,`Close overlay`),c.onclick=()=>this.hide(),c.onmouseover=()=>{c.style.background=`rgba(255,255,255,0.1)`,c.style.color=`#e0e0e0`},c.onmouseout=()=>{c.style.background=`transparent`,c.style.color=`#9ca3af`},c.onfocus=()=>{c.style.background=`rgba(255,255,255,0.1)`,c.style.color=`#e0e0e0`},c.onblur=()=>{c.style.background=`transparent`,c.style.color=`#9ca3af`},r.appendChild(i),r.appendChild(c),n.appendChild(r),e.filePath){let t=document.createElement(`div`);t.style.cssText=`margin-bottom: 1rem; padding: 0.75rem; background: rgba(0, 0, 0, 0.2); border-radius: 0.375rem; font-family: monospace; font-size: 0.875rem;`;let r=document.createElement(`strong`);r.textContent=`File: `,t.appendChild(r),t.appendChild(document.createTextNode(e.filePath)),n.appendChild(t)}let l=document.createElement(`div`);l.style.cssText=`margin-bottom: 1.5rem;`;let u=document.createElement(`h2`);u.style.cssText=`margin: 0 0 0.75rem 0; font-size: 1rem; font-weight: 600; color: #fca5a5;`,u.textContent=`Error Message:`;let d=document.createElement(`pre`);if(d.style.cssText=`margin: 0; padding: 1rem; background: rgba(239, 68, 68, 0.1); border-left: 4px solid #ef4444; border-radius: 0.375rem; overflow-x: auto; font-family: monospace; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: #fca5a5;`,d.textContent=e.message??`An error occurred`,l.appendChild(u),l.appendChild(d),n.appendChild(l),e.stack){let t=document.createElement(`details`);t.style.cssText=`margin-top: 1rem; cursor: pointer;`;let r=document.createElement(`summary`);r.style.cssText=`font-weight: 600; margin-bottom: 0.5rem; user-select: none;`,r.textContent=`Stack Trace`;let i=document.createElement(`pre`);i.style.cssText=`margin: 0; padding: 0.75rem; background: rgba(0, 0, 0, 0.2); border-radius: 0.375rem; overflow-x: auto; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;`,i.textContent=e.stack,t.appendChild(r),t.appendChild(i),n.appendChild(t)}let f=document.createElement(`div`);f.style.cssText=`margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid #374151; display: flex; gap: 0.75rem; align-items: center;`;let p=document.createElement(`button`);p.style.cssText=`padding: 0.625rem 1.25rem; background: #ef4444; color: white; border: none; border-radius: 0.375rem; cursor: pointer; font-weight: 600; font-size: 0.875rem; transition: all 0.2s;`,p.textContent=`Reload Page`,p.onclick=()=>window.location.reload(),p.onmouseover=()=>{p.style.background=`#dc2626`},p.onmouseout=()=>{p.style.background=`#ef4444`},p.onfocus=()=>{p.style.background=`#dc2626`},p.onblur=()=>{p.style.background=`#ef4444`};let m=document.createElement(`button`);m.style.cssText=`padding: 0.625rem 1.25rem; background: #374151; color: #e0e0e0; border: none; border-radius: 0.375rem; cursor: pointer; font-weight: 600; font-size: 0.875rem; transition: all 0.2s;`,m.textContent=`Dismiss`,m.onclick=()=>this.hide(),m.onmouseover=()=>{m.style.background=`#4b5563`},m.onmouseout=()=>{m.style.background=`#374151`},m.onfocus=()=>{m.style.background=`#4b5563`},m.onblur=()=>{m.style.background=`#374151`};let h=document.createElement(`span`);h.style.cssText=`margin-left: auto; font-size: 0.75rem; color: #9ca3af;`;let g=new Date(e.timestamp);h.textContent=Number.isNaN(g.valueOf())?``:g.toLocaleTimeString(),f.appendChild(p),f.appendChild(m),f.appendChild(h),n.appendChild(f),t.appendChild(n),this.overlay.appendChild(t)}};let P=null;function F(){return P||=new N,P}if(import.meta.hot){let e=F();import.meta.hot.on(`rari:hmr-error`,t=>{let n=t.msg||t.message,r=t.file||t.filePath,i=t.t||t.timestamp,a=t.count||t.errorCount,o=t.max||t.maxErrors;console.error(`[rari] HMR: Build error:`,n),r&&console.error(`[rari] HMR: File:`,r),t.stack&&console.error(`[rari] HMR: Stack:`,t.stack),e.show({message:n,stack:t.stack,filePath:r,timestamp:i}),a&&o&&(a>=o?console.error(`[rari] HMR: Maximum error count (${o}) reached. Consider restarting the dev server if issues persist.`):a>=o-2&&console.warn(`[rari] HMR: Error count: ${a}/${o}. Approaching maximum error threshold.`))}),import.meta.hot.on(`rari:hmr-error-cleared`,()=>{e.hide()}),import.meta.hot.on(`vite:error`,t=>{e.show({message:t.err?.message||`Unknown Vite error`,stack:t.err?.stack,filePath:t.err?.file,timestamp:Date.now()})})}export{O as RscErrorComponent,S as createClientModuleMap,A as createServerComponentWrapper,j as fetchServerComponent,x as getClientComponent,b as registerClientComponent,D as rscClient};
|