rari 0.10.3 → 0.10.4
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.
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
}
|
|
5
5
|
`})]})}function h({children:h,initialPayload:g,onNavigate:_}){let[v,y]=s(g),[,b]=s(0),x=o({x:0,y:0}),S=o(new Map),C=o(null),[,w]=c(),T=o(0),E=o(new Map),D=o([]),O=o(null),k=o(0),[A,j]=s(null),M=()=>{if(typeof document>`u`)return;let e=document.querySelectorAll(`form`);S.current.clear(),e.forEach((e,t)=>{let n=new FormData(e);S.current.set(`form-${t}`,n)})},N=()=>{typeof document>`u`||document.querySelectorAll(`form`).forEach((e,t)=>{let n=S.current.get(`form-${t}`);n&&n.forEach((t,n)=>{let r=e.elements.namedItem(n);r&&(r.type===`checkbox`||r.type===`radio`?r.checked=t===`on`:r.value=t)})})},P=(e,t,n,r)=>{let i={timestamp:Date.now(),error:e,type:t,details:n,filePath:r};D.current.push(i),k.current+=1,D.current.length>10&&D.current.shift(),console.error(`[rari] HMR: Failure detected`,{type:t,details:n,filePath:r,consecutiveFailures:k.current,error:e.message,stack:e.stack,timestamp:new Date(i.timestamp).toISOString()}),k.current>=2&&j(i),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:hmr-failure`,{detail:i}))},F=()=>{setTimeout(()=>{window.location.reload()},1e3)},I=()=>{k.current>0&&(k.current=0)},L=e=>{if(!O.current)return!1;if(e===O.current)return!0;let t=e.match(f);if(t){let e=Number.parseInt(t[1],10);if(Date.now()-e>5e3)return!0}return!1};function R(e,n,i,a,o){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[,s,c,l]=e,u=s;if(typeof s==`string`&&s.startsWith(`$`)&&a){let e=s.substring(1);if(t.test(e)){let e=a.get(s);e&&(e===`$Sreact.suspense`||e===`react.suspense`?u=`Suspense`:console.warn(`[rari] AppRouter: Unknown symbol:`,e))}}if(u===`Suspense`||s===`Suspense`){let e=K(l,n,i,a,o);return r.createElement(r.Suspense,c?{...e,key:c}:e)}if(typeof u==`string`&&u.startsWith(`$L`)){let e=n.get(u);if(!e)return null;let t=globalThis[`~clientComponents`]?.[e.id]?.component;if(!t||typeof t!=`function`)return null;let s=c||`fallback-${Math.random()}`,d={...l,children:l.children?R(l.children,n,i,a,o):void 0};return r.createElement(t,{key:s,...d})}if(!u||typeof u!=`string`&&typeof u!=`function`)return console.error(`[rari] AppRouter: Invalid component type:`,{type:u,typeOf:typeof u,serverKey:c,props:l,rscData:e}),null;let d=K(l,n,i,a,o);return r.createElement(u,c?{...d,key:c}:d)}return e.map((e,t)=>{let s=R(e,n,i,a,o);return s?typeof s==`object`&&r.isValidElement(s)&&!s.key?r.cloneElement(s,{key:t}):s:null}).filter(Boolean)}return e}let z=o(new Set),B=o(new Map),V=o(new Map),H=o(new Map),U=o(new Map);function W(e){if(!U.current.has(e)){let t=new Promise(()=>{});U.current.set(e,t)}return U.current.get(e)}function G({contentRef:e}){let t=B.current,n=V.current,r=H.current;if(t.has(e))return U.current.delete(e),R(t.get(e),n,void 0,r,t);throw W(e)}function K(e,t,n,i,a){if(!e||typeof e!=`object`)return e;a&&(B.current=a),t&&(V.current=t),i&&(H.current=i);let o={};for(let s in e)if(Object.hasOwn(e,s))if(s===`children`){let c=e.children;if(typeof c==`string`&&c.startsWith(`$L`))if(a&&a.has(c)){let e=a.get(c);z.current.delete(c),o[s]=R(e,t,n,i,a)}else z.current.add(c),o[s]=r.createElement(G,{key:`lazy-${c}`,contentRef:c});else o[s]=c?R(c,t,n,i,a):void 0}else s===`dangerouslySetInnerHTML`?o[s]=e[s]:o[s]=R(e[s],t,n,i,a);return o}let q=(e,t)=>{try{let n=t===`array`?`[`:`{`,r=t===`array`?`]`:`}`,i=0,a=-1,o=!1,s=!1;for(let t=0;t<e.length;t++){let c=e[t];if(s){s=!1;continue}if(c===`\\`){s=!0;continue}if(c===`"`&&!s){o=!o;continue}if(!o){if(c===n)i++;else if(c===r&&(i--,i===0)){a=t+1;break}}}if(a===-1)return null;let c=e.substring(0,a),l=e.substring(a).trim();return l.length>0&&!p.test(l)&&console.warn(`[rari] Sanitized corrupted JSON (possible userscript injection):`,{extracted:c.substring(0,100),discarded:l.substring(0,50)}),c}catch(e){return console.error(`[rari] Failed to sanitize JSON:`,e),null}},J=async(e,i=!1)=>{try{let a=e.trim().split(`
|
|
6
6
|
`),o=new Map,s=new Map,c=new Map,l=null,u=[],d=null,f=null;for(let e=0;e<a.length;e++){let n=a[e].trim();if(!n)continue;let r=n.indexOf(`:`);if(r===-1)continue;let p=n.substring(0,r);if(!t.test(p)){console.warn(`[rari] AppRouter: Invalid row ID (non-numeric), skipping line:`,n.substring(0,50));continue}let m=n.substring(r+1);try{if(m.startsWith(`"$S`)){let e=m.slice(1,-1);s.set(`$${p}`,e);continue}if(m.startsWith(`I[`)){let t=q(m.substring(1),`array`);if(!t){console.warn(`[rari] AppRouter: Could not sanitize import line, skipping:`,n.substring(0,80));continue}let r=JSON.parse(t);if(Array.isArray(r)&&r.length>=3){let[t,n,a]=r;o.set(`$L${p}`,{id:t,chunks:Array.isArray(n)?n:[n],name:a||`default`}),i&&t.includes(`layout`)&&(d!==null&&f!==null&&u.push({layoutPath:d,startLine:f,endLine:e-1,props:{}}),d=t,f=e)}}else if(m.startsWith(`[`)){let e=JSON.parse(m);if(c.set(`$L${p}`,e),i&&Array.isArray(e)&&e.length>=4&&typeof e[1]==`string`&&e[1].startsWith(`$L`)){let t=e[1],n=o.get(t);if(n&&n.id.includes(`layout`)){let t=e[3]||{};if(d&&f!==null){let e=u.find(e=>e.layoutPath===d&&e.startLine===f);e&&(e.props=t)}}}!l&&Array.isArray(e)&&(e[0]===`$`?l=e:Array.isArray(e[0])&&e[0][0]===`$`&&(l=e.length===1?e[0]:e))}}catch(e){console.error(`[rari] AppRouter: Failed to parse RSC line:`,n,e)}}if(await n(o),i&&d!==null&&f!==null&&u.push({layoutPath:d,startLine:f,endLine:a.length-1,props:{}}),l&&Array.isArray(l)){if(l[0]===`$`)l=R(l,o,void 0,s,c);else if(Array.isArray(l[0])){let e=l.map(e=>Array.isArray(e)&&e[0]===`$`?R(e,o,void 0,s,c):e).filter(e=>e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||r.isValidElement(e));l=e.length===1?e[0]:e}}return{element:l,modules:o,symbols:s,wireFormat:e,layoutBoundaries:i?u:void 0}}catch(e){throw console.error(`[rari] AppRouter: Failed to parse RSC wire format:`,e),e}},Y=async(t,n)=>{let r=t||window.location.pathname,i=E.current.get(r);if(i)return i;let a=(async()=>{try{let t=(import.meta.env.RARI_SERVER_URL||window.location.origin).replace(e,``)+r+window.location.search,i=await fetch(t,{headers:{Accept:`text/x-component`,"Cache-Control":`no-cache`,Pragma:`no-cache`},cache:`no-store`,signal:n});if(!i.ok){let e=Error(`Failed to fetch RSC data: ${i.status} ${i.statusText}`);throw P(e,`fetch`,`HTTP ${i.status} when fetching ${t}`,window.location.pathname),e}let a=await i.text();if(L(a)&&v)return v;let o;try{o=await J(a,!1)}catch(e){let t=e instanceof Error?e:Error(String(e));throw P(t,`parse`,`Failed to parse RSC wire format: ${t.message}`,window.location.pathname),t}return y(o),O.current=a,I(),o}catch(e){throw e instanceof Error&&!e.message.includes(`Failed to fetch RSC data`)&&!e.message.includes(`Failed to parse`)&&P(e,`network`,`Network error: ${e.message}`,window.location.pathname),console.error(`[rari] AppRouter: Error fetching RSC payload:`,e),e}finally{E.current.delete(r)}})();return E.current.set(r,a),a};a(()=>{if(typeof window>`u`)return;let e=async e=>{let t=e.detail;T.current=t.navigationId,C.current=null,x.current={x:window.scrollX,y:window.scrollY},M(),w(async()=>{try{t.rscWireFormat?(y(await J(t.rscWireFormat,!1)),O.current=t.rscWireFormat,I()):t.isStreaming?C.current=[]:await Y(t.to,t.abortSignal),T.current===t.navigationId&&(b(e=>e+1),j(null),_&&_(t))}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;console.error(`[rari] AppRouter: Navigation failed:`,e),window.dispatchEvent(new CustomEvent(`rari:navigate-error`,{detail:{from:t.from,to:t.to,error:e,navigationId:t.navigationId}})),k.current>=3&&F()}finally{t.options?.historyKey||requestAnimationFrame(()=>{t.options?.scroll!==!1&&window.scrollTo(0,0)})}})},t=async()=>{x.current={x:window.scrollX,y:window.scrollY},M();try{await Y(),b(e=>e+1),j(null)}catch(e){console.error(`[rari] AppRouter: HMR update failed:`,e),k.current>=3&&F()}finally{requestAnimationFrame(()=>{window.scrollTo(x.current.x,x.current.y),N()})}},n=async()=>{try{await Y(),b(e=>e+1),j(null)}catch(e){console.error(`[rari] AppRouter: RSC invalidation failed:`,e),k.current>=3&&F()}},r=async()=>{try{await Y(),j(null)}catch(e){console.error(`[rari] AppRouter: Manifest update failed:`,e),k.current>=3&&F()}},i=async e=>{let t=e.detail.rscRow;if(!(!t||!t.trim())){C.current||=[],C.current.push(t);try{let e=C.current.join(`
|
|
7
|
-
`),t=await J(e,!1);C.current.length<=2&&e.includes(`~boundaryId`)?(y(t),b(e=>e+1)):w(()=>{y(t),b(e=>e+1)})}catch(e){console.error(`[rari] AppRouter: Failed to parse streaming RSC row:`,e)}}};return window.addEventListener(`rari:navigate`,e),window.addEventListener(`rari:app-router-rerender`,t),window.addEventListener(`rari:rsc-invalidate`,n),window.addEventListener(`rari:app-router-manifest-updated`,r),window.addEventListener(`rari:rsc-row`,i),()=>{window.removeEventListener(`rari:navigate`,e),window.removeEventListener(`rari:app-router-rerender`,t),window.removeEventListener(`rari:rsc-invalidate`,n),window.removeEventListener(`rari:app-router-manifest-updated`,r),window.removeEventListener(`rari:rsc-row`,i)}},[_]);let X=()=>{window.location.reload()},Z=()=>{j(null)},Q=e=>{if(!e||typeof e!=`object`)return null;if(e.type===`html`&&e.props?.children){let t=Array.isArray(e.props.children)?e.props.children:[e.props.children];for(let e of t)if(e&&typeof e==`object`&&e.type===`body`)return e.props?.children||null}return e},$=h;return v?.element&&($=Q(v.element)||v.element),Array.isArray($)&&$.length===1&&r.isValidElement($[0])
|
|
7
|
+
`),t=await J(e,!1);C.current.length<=2&&e.includes(`~boundaryId`)?(y(t),b(e=>e+1)):w(()=>{y(t),b(e=>e+1)})}catch(e){console.error(`[rari] AppRouter: Failed to parse streaming RSC row:`,e)}}};return window.addEventListener(`rari:navigate`,e),window.addEventListener(`rari:app-router-rerender`,t),window.addEventListener(`rari:rsc-invalidate`,n),window.addEventListener(`rari:app-router-manifest-updated`,r),window.addEventListener(`rari:rsc-row`,i),()=>{window.removeEventListener(`rari:navigate`,e),window.removeEventListener(`rari:app-router-rerender`,t),window.removeEventListener(`rari:rsc-invalidate`,n),window.removeEventListener(`rari:app-router-manifest-updated`,r),window.removeEventListener(`rari:rsc-row`,i)}},[_]);let X=()=>{window.location.reload()},Z=()=>{j(null)},Q=e=>{if(!e||typeof e!=`object`)return null;if(e.type===`html`&&e.props?.children){let t=Array.isArray(e.props.children)?e.props.children:[e.props.children];for(let e of t)if(e&&typeof e==`object`&&e.type===`body`)return e.props?.children||null}return e},$=h;return v?.element&&($=Q(v.element)||v.element),Array.isArray($)&&$.length===1&&r.isValidElement($[0])?$=$[0]:Array.isArray($)&&$.length>0&&$.every(e=>r.isValidElement(e)||e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)&&($=r.createElement(r.Fragment,null,...$)),$&&typeof $==`object`&&!r.isValidElement($)&&(console.error(`[rari] AppRouter: Invalid content to render:`,$),$=h),d(l,{children:[A&&d(`div`,{style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,padding:`24px`,background:`rgba(220, 38, 38, 0.95)`,color:`white`,borderRadius:`8px`,fontSize:`14px`,zIndex:1e4,maxWidth:`500px`,boxShadow:`0 4px 6px rgba(0, 0, 0, 0.3)`},children:[u(`div`,{style:{marginBottom:`16px`,fontWeight:`bold`,fontSize:`16px`},children:`⚠️ HMR Update Failed`}),d(`div`,{style:{marginBottom:`12px`,opacity:.9},children:[A.type===`fetch`&&`Failed to fetch updated content from server.`,A.type===`parse`&&`Failed to parse server response.`,A.type===`stale`&&`Server returned stale content.`,A.type===`network`&&`Network error occurred.`]}),u(`div`,{style:{marginBottom:`16px`,fontSize:`12px`,opacity:.8,fontFamily:`monospace`},children:A.details}),d(`div`,{style:{marginBottom:`12px`,fontSize:`12px`,opacity:.7},children:[`Consecutive failures:`,` `,k.current,` `,`/`,` `,3]}),d(`div`,{style:{display:`flex`,gap:`8px`},children:[u(`button`,{onClick:X,type:`button`,style:{padding:`8px 16px`,background:`white`,color:`#dc2626`,border:`none`,borderRadius:`4px`,cursor:`pointer`,fontWeight:`bold`,fontSize:`14px`},children:`Refresh Page`}),u(`button`,{onClick:Z,type:`button`,style:{padding:`8px 16px`,background:`rgba(255, 255, 255, 0.2)`,color:`white`,border:`1px solid rgba(255, 255, 255, 0.3)`,borderRadius:`4px`,cursor:`pointer`,fontSize:`14px`},children:`Dismiss`})]}),u(`div`,{style:{marginTop:`12px`,fontSize:`11px`,opacity:.6},children:`Check the console for detailed error logs.`})]}),u(i,{fallback:u(m,{}),children:$})]})}export{h as AppRouterProvider};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rari",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.4",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -102,18 +102,18 @@
|
|
|
102
102
|
"rolldown": "1.0.0-rc.2"
|
|
103
103
|
},
|
|
104
104
|
"optionalDependencies": {
|
|
105
|
-
"rari-darwin-arm64": "0.10.
|
|
106
|
-
"rari-darwin-x64": "0.10.
|
|
107
|
-
"rari-linux-arm64": "0.10.
|
|
108
|
-
"rari-linux-x64": "0.10.
|
|
109
|
-
"rari-win32-x64": "0.10.
|
|
105
|
+
"rari-darwin-arm64": "0.10.4",
|
|
106
|
+
"rari-darwin-x64": "0.10.4",
|
|
107
|
+
"rari-linux-arm64": "0.10.4",
|
|
108
|
+
"rari-linux-x64": "0.10.4",
|
|
109
|
+
"rari-win32-x64": "0.10.4"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^25.3.0",
|
|
113
113
|
"@types/react": "^19.2.14",
|
|
114
114
|
"@types/react-dom": "^19.2.3",
|
|
115
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
116
|
-
"oxlint": "^1.
|
|
115
|
+
"@typescript/native-preview": "^7.0.0-dev.20260223.1",
|
|
116
|
+
"oxlint": "^1.50.0",
|
|
117
117
|
"rolldown-vite": "^7.3.1",
|
|
118
118
|
"tsdown": "^0.20.3",
|
|
119
119
|
"@rari/deploy": "0.1.0",
|