@weftui/dom 0.30.0 → 0.31.1

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/README.md CHANGED
@@ -9,10 +9,10 @@ Two entry points: `@weftui/dom/client` for the browser, `@weftui/dom/server` for
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- npm install @weftui/core @weftui/dom effect@beta
12
+ npm install @weftui/core @weftui/dom effect@rc
13
13
  ```
14
14
 
15
- Weft tracks Effect 4's beta line. This release is built and tested against `effect@4.0.0-beta.98`; the peer range accepts newer 4.0 betas, which may contain upstream breaking changes.
15
+ Weft tracks Effect 4's prerelease line (beta, then rc). This release is built and tested against `effect@4.0.0-rc.112`; the peer range accepts newer 4.0 prereleases, which may contain upstream breaking changes.
16
16
 
17
17
  `effect` is a peer dependency; `@weftui/core` is required to author the tree.
18
18
 
@@ -1,4 +1,4 @@
1
- import { i as UnsupportedNodeTypeError, n as RenderError, r as StreamSubscriptionError, t as HydrationMismatchError } from "../data-C88W1AwU.js";
1
+ import { i as UnsupportedNodeTypeError, n as RenderError, r as StreamSubscriptionError, t as HydrationMismatchError } from "../data-DeNpcBZh.js";
2
2
  import { Cause, Effect, Layer, ManagedRuntime, Stream } from "effect";
3
3
  import { AssertNoServerOnly, Node, Renderable, ServerOnlyLeak } from "@weftui/core";
4
4
  declare namespace weft_app_d_exports {
@@ -62,6 +62,16 @@ interface RootHandle {
62
62
  * {@link element}. Idempotent. Teardown side effects fire once.
63
63
  */
64
64
  unmount(): Effect.Effect<void>;
65
+ /**
66
+ * Resolves when everything dirty at call time has committed to the DOM or
67
+ * been discarded, with the commit generation. Immediate when idle; resolves
68
+ * (never hangs) across `WeftApp.dispose`. App-scoped: with multiple roots it
69
+ * may also wait on sibling roots' pending commits (documented superset;
70
+ * per-root filtering is follow-up work).
71
+ */
72
+ readonly awaitCommit: Effect.Effect<number>;
73
+ /** Current commit generation: monotonic, app-scoped, +1 per flush pass that committed anything. */
74
+ readonly commitGeneration: Effect.Effect<number>;
65
75
  }
66
76
  /**
67
77
  * A Weft application: one lazy `ManagedRuntime` (the app layer), one root
@@ -1 +1 @@
1
- import{t as e}from"../rolldown-runtime-DK3Fl9T5.js";import{_ as t,a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,u as _,y as v}from"../shared-Dz0KM9ku.js";import{n as y}from"../boundary-replay-BY4GyLot.js";import{Cause as b,Context as x,Deferred as S,Effect as C,Exit as w,Fiber as ee,HashMap as T,HashSet as E,Layer as te,ManagedRuntime as ne,Option as D,PubSub as O,Ref as k,Schema as re,Scope as A,Stream as j,SubscriptionRef as M,pipe as N}from"effect";import{AppRpcClientTag as ie,FAILURE_BOUNDARY as ae,FRAGMENT as oe,LIST as se,SERVER_BOUNDARY as ce,SUSPENSE_BOUNDARY as le,Source as ue,Subscribable as P,getElementDescriptor as F,isStream as I,toStream as L}from"@weftui/core";function R(){return C.gen(function*(){let e=yield*s;return++e.streamIdCounter.current})}const de=R;let fe=0;const z=()=>++fe;function B(e,t){return C.gen(function*(){for(let[n,r]of Object.entries(t))if(n!==`children`){if(l(n)){yield*ye(e,n,r);continue}if(n===`ref`&&typeof r==`object`&&M.isSubscriptionRef(r)){yield*M.set(r,D.some(e));continue}if(n===`ref`&&Array.isArray(r)){yield*C.forEach(r.filter(e=>M.isSubscriptionRef(e)),t=>M.set(t,D.some(e)),{discard:!0});continue}if(n===`style`){yield*_e(e,r);continue}pe(e,n)?yield*me(e,n,r):yield*he(e,n,r)}})}function pe(e,t){if(t.startsWith(`data-`)||t.startsWith(`aria-`))return!1;let n=Object.getPrototypeOf(e);for(;n!==null;){if(Object.hasOwn(n,t))return!0;n=Object.getPrototypeOf(n)}return t in e}function me(e,t,n){return C.gen(function*(){I(n)||C.isEffect(n)?yield*U(L(n),n=>{n==null?delete e[t]:e[t]=n},`property:${t}`):n!=null&&(e[t]=n)})}function he(e,t,n){return C.gen(function*(){if(I(n)||C.isEffect(n))yield*U(L(n),n=>{if(n==null)e.removeAttribute(t);else{let r=ge(n);r!==void 0&&(typeof n==`boolean`?n?e.setAttribute(t,``):e.removeAttribute(t):e.setAttribute(t,r))}},`attribute:${t}`);else{let r=ge(n);r!==void 0&&(typeof n==`boolean`?n?e.setAttribute(t,``):e.removeAttribute(t):e.setAttribute(t,r))}})}function ge(e){if(e!=null)return String(e)}function _e(e,t){return C.gen(function*(){if(I(t)||C.isEffect(t)){yield*U(L(t),t=>{if(typeof t==`string`)e.setAttribute(`style`,t);else if(typeof t==`object`&&t){e.style.cssText=``;for(let[n,r]of Object.entries(t))r!=null&&e.style.setProperty(V(n),String(r))}},`style`);return}if(typeof t==`string`){e.setAttribute(`style`,t);return}typeof t==`object`&&t&&(yield*ve(e,t))})}function ve(e,t){return C.gen(function*(){for(let[n,r]of Object.entries(t))I(r)||C.isEffect(r)?yield*U(L(r),t=>{t!=null&&e.style.setProperty(V(n),String(t))},`style.${n}`):r!=null&&e.style.setProperty(V(n),String(r))})}function V(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function H(e,t,n,r){return C.gen(function*(){let i=yield*C.serviceOption(d);if(D.isNone(i)){let i=yield*C.forkIn(e,t);return yield*N(ee.await(i),C.flatMap(e=>w.isFailure(e)&&!b.hasInterruptsOnly(e.cause)?r(e.cause,n):C.void),C.forkIn(t)),i}let a=yield*C.forkIn(e,t);return yield*N(ee.await(a),C.flatMap(e=>w.isFailure(e)?i.value.reportError(e.cause):C.void),C.forkIn(t)),a})}function U(e,t,n){return C.gen(function*(){let r=yield*s;yield*H(j.runForEach(e,e=>C.sync(()=>void t(e))),r.scope,n,r.reportUnhandled)})}function ye(e,t,n){return C.gen(function*(){let r=yield*s,i=t.slice(2).toLowerCase(),a=null,o=()=>{a&&=(e.removeEventListener(i,a),null)},c=n=>{o(),!(n==null||n===!1)&&typeof n==`function`&&(a=e=>{let i=n(e);C.isEffect(i)&&r.runtime.runFork(N(i,C.provideService(A.Scope,r.rootScope),C.exit,C.flatMap(e=>w.isFailure(e)&&!b.hasInterruptsOnly(e.cause)?r.reportUnhandled(e.cause,`event:${t}`):C.void)))},e.addEventListener(i,a))};yield*A.addFinalizer(r.scope,C.sync(o)),I(n)||C.isEffect(n)?yield*U(L(n),e=>c(e),`event:${t}`):c(n)})}function be(e,t,n,r,i,a){return C.gen(function*(){let o=yield*s,c=yield*S.await(t).pipe(C.flip,C.catch(()=>C.interrupt)),l=e.match(c);if(yield*A.close(n,w.void),l===null)return D.isSome(r)?yield*r.value.reportError(c):yield*o.reportUnhandled(c,`boundary:outermost`);K(i,a);let u=yield*W(l),d=a.parentNode;if(d!==null&&u!==null)if(Array.isArray(u))for(let e of u)d.insertBefore(e,a);else d.insertBefore(u,a)})}function xe(e){return C.gen(function*(){let t=yield*s,n=yield*C.serviceOption(d),r=z(),i=document.createComment(h(r)),a=document.createComment(f(r)),o=yield*A.fork(t.scope,`sequential`),c={...t,scope:o},l=yield*S.make(),u=yield*N(Te(e.children),C.provideService(d,{reportError:e=>S.fail(l,e).pipe(C.asVoid)}),C.provideService(s,c),C.provideService(A.Scope,o),C.catchCause(t=>{let n=e.match(t);return n===null?C.failCause(t):N(A.close(o,w.void),C.flatMap(()=>W(n)),C.map(e=>e===null?[]:Array.isArray(e)?e:[e]))}));return yield*C.forkIn(be(e,l,o,n,i,a),t.scope),[i,...u,a]})}function Se(e){return C.gen(function*(){let t=yield*s,n=yield*k.make(1),r=yield*S.make(),i=N(k.updateAndGet(n,e=>e-1),C.flatMap(e=>e<=0?C.asVoid(S.succeed(r,void 0)):C.void)),a={register:k.update(n,e=>e+1),settle:i},c=e.children,l=yield*W((c===void 0?[]:Array.isArray(c)?c:[c]).map(e=>F(e)===void 0&&(C.isEffect(e)||I(e))?{type:()=>e,props:{}}:e)).pipe(C.provideService(v,a)),u=l===null?[]:Array.isArray(l)?l:[l];yield*i;let d=yield*S.poll(r);if(D.isSome(d))return u;let f=yield*de(),p=document.createComment(m(f)),h=document.createComment(o(f)),g=yield*W(e.fallback??null),_=[];g!==null&&(Array.isArray(g)?_.push(...g):_.push(g));let y=document.createDocumentFragment();for(let e of u)y.appendChild(e);let b=C.gen(function*(){yield*S.await(r),K(p,h);let e=h.parentNode;e!==null&&(e.insertBefore(y,h),p.remove(),h.remove())});return yield*C.forkIn(b,t.scope),[p,..._,h]})}function Ce(e){return C.gen(function*(){let n=yield*s,r=yield*C.serviceOption(ie);if(D.isNone(r))return yield*C.fail(new t({cause:void 0,message:`Boundary.rpc "${e.tag}" was mounted client-first without an AppRpcClient in context. Mount the app under @weftui/router (RouterLive), which provides the rpc client, so the boundary can resolve its data.`}));let i=r.value,a=z(),o=document.createComment(h(a)),c=document.createComment(f(a)),l=yield*W(e.fallback??null),u=[];l!==null&&(Array.isArray(l)?u.push(...l):u.push(l));let d=C.gen(function*(){let t=yield*i.call(e.tag,e.payload()),n=yield*Qe(e.tag,e.payload,t,r),a=yield*W(e.render(n));K(o,c);let s=c.parentNode;if(s!==null&&a!==null)if(Array.isArray(a))for(let e of a)s.insertBefore(e,c);else s.insertBefore(a,c)}).pipe(C.catchCause(t=>C.logError(`[weft] Boundary.rpc "${e.tag}" mount failed to resolve; fallback left in place.`,t)));return yield*C.forkIn(d,n.scope),[o,...u,c]})}function W(e){return C.gen(function*(){if(typeof e==`string`||typeof e==`number`||typeof e==`bigint`)return document.createTextNode(String(e));if(typeof e==`boolean`||e==null)return null;if(I(e)||C.isEffect(e)){let t=F(e);if(t!==void 0)return yield*W(t);if(C.isEffect(e)){let t=yield*C.context(),n=C.runSyncExitWith(t)(e);if(w.isSuccess(n))return yield*W(n.value)}return yield*G(L(e))}if(typeof e==`object`&&Symbol.iterator in e&&!(`type`in e))return yield*Te(we(e));if(typeof e==`object`&&`type`in e&&!(Symbol.iterator in e)){let{type:t,props:n}=e;return t===oe?yield*Ee(n):t===le?yield*Se(n):t===ce?yield*Ce(n):t===ae?yield*xe(n):t===se?yield*Ie(n):typeof t==`string`?yield*De(t,n):typeof t==`function`?yield*Oe(t,n):yield*C.fail(new r({type:t,message:`Invalid Renderable type: expected string, FRAGMENT, or function, got ${typeof t}`}))}return null})}function we(e){let t=[];function n(e){if(I(e)||C.isEffect(e)){t.push(e);return}if(typeof e==`object`&&e&&Symbol.iterator in e&&!(`type`in e))for(let t of e)n(t);else t.push(e)}return n(e),t}function Te(e){return C.gen(function*(){let t=[];for(let n of e)if(F(n)===void 0&&(I(n)||C.isEffect(n))){let e=yield*G(L(n));t.push(...e)}else{let e=yield*W(n);e!==null&&(Array.isArray(e)?t.push(...e):t.push(e))}return t})}function Ee(e){return C.gen(function*(){let t=`children`in e?e.children:void 0;return t===void 0?[]:yield*Te(Array.isArray(t)?t:[t])})}function De(e,t){return C.gen(function*(){let n=document.createElement(e);yield*B(n,t);let r=`children`in t?t.children:void 0;if(r!==void 0){let e=Array.isArray(r)?r:[r];for(let t of e)if(F(t)===void 0&&(I(t)||C.isEffect(t))){let e=yield*G(L(t));for(let t of e)n.appendChild(t)}else{let e=yield*W(t);if(e!==null)if(Array.isArray(e))for(let t of e)n.appendChild(t);else n.appendChild(e)}}return n})}function Oe(e,t){return C.gen(function*(){let n=e(t);if(I(n)||C.isEffect(n)){let e=yield*s,t=yield*A.fork(e.scope,`sequential`),r={...e,scope:t},i=yield*C.serviceOption(v),a=L(n);return D.isSome(i)&&(yield*i.value.register,a=N(a,j.zipWithIndex,j.flatMap(([e,t])=>t===0?j.fromEffect(C.as(i.value.settle,e)):j.make(e)))),yield*G(a).pipe(C.provideService(s,r),C.provideService(A.Scope,t))}return yield*W(n)})}function G(e){return C.gen(function*(){let t=yield*s,n=yield*R(),[r,i]=ke(n),a=null;return yield*H(j.runForEach(e,e=>C.gen(function*(){a!==null&&(yield*A.close(a,w.void)),a=yield*A.fork(t.scope,`sequential`);let n={...t,scope:a};yield*Ae(r,i,e).pipe(C.provideService(s,n),C.provideService(A.Scope,a))})),t.scope,`child:stream-${n}`,t.reportUnhandled),[r,i]})}function ke(e){return[document.createComment(a(e)),document.createComment(_(e))]}function Ae(e,t,n){return C.gen(function*(){let r=e.nextSibling,i=r!==null&&r!==t&&r.nextSibling===t;if(i&&r.nodeType===at&&je(n)){let e=String(n);r.data!==e&&(r.data=e);return}if(i&&r.nodeType===Y){let e=Me(n);if(e!==void 0&&typeof e.type==`string`&&r.tagName.toLowerCase()===e.type.toLowerCase()){yield*Ne(r,e);return}}K(e,t);let a=yield*W(n),o=e.parentNode;if(o!==null&&a!==null)if(Array.isArray(a))for(let e of a)o.insertBefore(e,t);else o.insertBefore(a,t)})}function je(e){return typeof e==`string`||typeof e==`number`||typeof e==`bigint`}function Me(e){let t=F(e);if(t!==void 0)return t;if(typeof e==`object`&&e&&`type`in e&&!(Symbol.iterator in e)&&!I(e)&&!C.isEffect(e))return e}function Ne(e,t){return C.gen(function*(){yield*B(e,t.props);let n=t.props.children,r=n===void 0?[]:Array.isArray(n)?n:[n];if(!(yield*Pe(e,r))){for(;e.firstChild!==null;)e.firstChild.remove();yield*Fe(e,r)}})}function Pe(e,t){return C.gen(function*(){let n=Array.from(e.childNodes);if(n.length!==t.length)return!1;for(let e=0;e<t.length;e++){let r=t[e],i=n[e];if(je(r)){if(i.nodeType!==at)return!1}else{let e=Me(r);if(e===void 0||typeof e.type!=`string`||i.nodeType!==Y||i.tagName.toLowerCase()!==e.type.toLowerCase())return!1}}for(let e=0;e<t.length;e++){let r=t[e],i=n[e];if(je(r)){let e=String(r);i.data!==e&&(i.data=e)}else yield*Ne(i,Me(r))}return!0})}function Fe(e,t){return C.gen(function*(){for(let n of t)if(I(n)||C.isEffect(n)){let t=yield*G(L(n));for(let n of t)e.appendChild(n)}else{let t=yield*W(n);if(t!==null)if(Array.isArray(t))for(let n of t)e.appendChild(n);else e.appendChild(t)}})}function K(e,t){let n=e.nextSibling;for(;n!==null&&n!==t;){let e=n.nextSibling;n.remove(),n=e}}function Ie(e){return C.gen(function*(){let t=yield*s,{of:n,by:r,render:i}=e,a=yield*R(),[o,c]=ke(a),l=yield*A.fork(t.scope,`sequential`),u=yield*ue.toSubscribable(n).pipe(C.provideService(A.Scope,l)),d=P.changes(u),f={records:T.empty(),order:[]};return yield*H(j.runForEach(d,e=>C.gen(function*(){f=yield*Re(Array.from(e),r,i,f,l,c,t)})),l,`list:stream-${a}`,t.reportUnhandled),[o,c]})}function Le(e,n){return C.gen(function*(){let r=[],i=E.empty();for(let a=0;a<e.length;a++){let o=n===void 0?e[a]:n(e[a],a);if(E.has(i,o))return yield*C.fail(new t({cause:o,message:`List.each: duplicate key ${He(o)} in a single emission; keys must be unique (set a stable \`by\`).`}));i=E.add(i,o),r.push(o)}return r})}function Re(e,t,n,r,i,a,o){return C.gen(function*(){let s=yield*Le(e,t),c=T.empty();r.order.forEach((e,t)=>{c=T.set(c,e,t)});let l=[],u=[];for(let t=0;t<e.length;t++){let a=s[t],d=T.get(r.records,a);if(D.isSome(d))l.push(d.value),u.push(D.getOrElse(T.get(c,a),()=>-1));else{let r=yield*ze(a,e[t],t,n,i,o);l.push(r),u.push(-1)}}let d=E.empty();for(let e of s)d=E.add(d,e);for(let e of r.order)if(!E.has(d,e)){let t=T.get(r.records,e);D.isSome(t)&&(yield*A.close(t.value.scope,w.void),Ve(t.value.startMarker,t.value.endMarker))}let f=Ue(u),p=a.parentNode;if(p!==null)for(let e=l.length-1;e>=0;e--){let t=l[e];if(u[e]!==-1&&f.has(e))continue;let n=e+1<l.length?l[e+1].startMarker:a,r=u[e]===-1?[t.startMarker,...t.nodes,t.endMarker]:Be(t.startMarker,t.endMarker);for(let e of r)p.insertBefore(e,n)}let m=T.empty();for(let e of l)m=T.set(m,e.key,e);return{records:m,order:s}})}function ze(e,t,r,i,a,o){return C.gen(function*(){let c=yield*A.fork(a,`sequential`),l={...o,scope:c},u=yield*R(),d=document.createComment(p(u)),f=document.createComment(n(u)),m=yield*W(i(t,r)).pipe(C.provideService(s,l),C.provideService(A.Scope,c));return{key:e,scope:c,startMarker:d,endMarker:f,nodes:m===null?[]:Array.isArray(m)?m:[m]}})}function Be(e,t){let n=[],r=e;for(;r!==null&&(n.push(r),r!==t);)r=r.nextSibling;return n}function Ve(e,t){let n=e;for(;n!==null;){let e=n.nextSibling;if(n.remove(),n===t)break;n=e}}function He(e){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`object`&&e)try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}return String(e)}function Ue(e){let t=e.length,n=[],r=Array.from({length:t},()=>-1);for(let i=0;i<t;i++){let t=e[i];if(t===-1)continue;let a=0,o=n.length;for(;a<o;){let r=a+o>>1;e[n[r]]<t?a=r+1:o=r}a>0&&(r[i]=n[a-1]),n[a]=i}let i=new Set,a=n.length>0?n[n.length-1]:-1;for(;a!==-1;)i.add(a),a=r[a];return i}function q(e,t,n){return C.gen(function*(){if(typeof e==`string`||typeof e==`number`||typeof e==`bigint`)return yield*We(String(e),t,n);if(typeof e==`boolean`||e==null)return t;if(I(e)||C.isEffect(e)){let r=F(e);if(r!==void 0)return yield*q(r,t,n);if(C.isEffect(e)){let r=C.runSyncExit(e);if(w.isSuccess(r))return yield*q(r.value,t,n)}return yield*qe(L(e),t,n)}if(typeof e==`object`&&Symbol.iterator in e&&!(`type`in e)){let r=t,i=0;for(let t of e)r=yield*q(t,r,`${n}[${i}]`),i++;return r}if(typeof e==`object`&&`type`in e&&!(Symbol.iterator in e)){let{type:i,props:a}=e;if(i===oe)return yield*J(a,t,n);if(i===le){if(t!==null&&t.nodeType===X){let e=u(t);if(e!==null&&e.kind===`start`)return yield*Ye(t,n)}return yield*J(a,t,n)}return i===ae?yield*Ze(a,t,n):i===ce?yield*$e(a,t,n):i===se?yield*tt(a,t,n):typeof i==`string`?yield*et(i,a,t,n):typeof i==`function`?yield*q(i(a),t,n):yield*C.fail(new r({type:i,message:`Invalid Renderable type during hydration at ${n}: expected string, FRAGMENT, or function, got ${typeof i}`}))}return t})}function We(e,t,n){return C.gen(function*(){if(e.length===0)return t;if(t===null||t.nodeType!==at)return yield*Q(`text ${JSON.stringify(e)}`,Z(t),n);let r=t;return r.data.startsWith(e)?r.data.length>e.length?r.splitText(e.length):r.nextSibling:yield*Q(`text ${JSON.stringify(e)}`,Z(t),n)})}function Ge(){return C.gen(function*(){let e=yield*k.make(1),t=yield*S.make(),n=N(k.updateAndGet(e,e=>e-1),C.flatMap(e=>e<=0?C.asVoid(S.succeed(t,void 0)):C.void));return{register:k.update(e,e=>e+1),settle:n,awaitReady:S.await(t)}})}function Ke(e){let t=!1;return C.suspend(()=>t||e===void 0?C.void:(t=!0,e.settle))}function qe(e,t,n){return C.gen(function*(){let r=yield*s;if(t===null||t.nodeType!==X)return yield*Q(`reactive region start marker`,Z(t),n);let a=t,o=i(a);if(o===null||o.kind!==`start`)return yield*Q(`reactive region start marker`,Z(t),n);let c=st(a);if(c===null)return yield*Q(`reactive region end marker`,`unterminated region starting at ${JSON.stringify(a.data)}`,n);let l=Ke(r.hydrationReady),u=!0,d=null,f=j.runForEach(e,e=>C.gen(function*(){d!==null&&(yield*A.close(d,w.void)),d=yield*A.fork(r.scope,`sequential`);let t={...r,scope:d};yield*C.gen(function*(){u?(u=!1,yield*Je(e,a,c,n),yield*l):yield*Ae(a,c,e)}).pipe(C.provideService(s,t),C.provideService(A.Scope,d))})).pipe(C.ensuring(l));return r.hydrationReady!==void 0&&(yield*r.hydrationReady.register),yield*H(f,r.scope,`hydrate:stream-${o.id} (${n})`,r.reportUnhandled),c.nextSibling})}function Je(e,t,n,r){return C.gen(function*(){let i=yield*q(e,t.nextSibling,`${r}<resume>`).pipe(C.map(e=>e===n?null:`adopted content did not align with the end marker`),C.catchTag(`HydrationMismatchError`,e=>C.succeed(`expected ${e.expected}, found ${e.actual} at ${e.path}`)));i!==null&&(console.error(`[weft] hydrate: reactive region at ${r} diverged from server output (${i}); patching.`),yield*Ae(t,n,e))})}function Ye(e,t){return C.gen(function*(){let n=Xe(e);if(n===null)return yield*Q(`substituted suspense end marker`,`unterminated region starting at ${JSON.stringify(e.data)}`,t);let r=null;for(let t=e.nextSibling;t!==null&&t!==n;t=t.nextSibling)if(t.nodeType===Y&&t.tagName===`SCRIPT`&&t.getAttribute(`type`)===`application/json`&&t.hasAttribute(`data-weft-suspense-failure`)){r=t;break}let i=null;if(r!==null){let e=r.textContent??``;i=yield*C.try({try:()=>JSON.parse(e),catch:e=>e}).pipe(C.catch(()=>C.succeed(null)))}if(typeof i!=`object`||!i||!(`error`in i))return console.error(`[weft] hydrate: substituted suspense region at ${t} has no decodable failure sentinel; leaving its static content.`),n.nextSibling;let a=yield*C.serviceOption(d);return D.isNone(a)?(console.error(`[weft] hydrate: substituted suspense region at ${t} has no enclosing Boundary to replay its failure to; leaving its static content.`,i.error),n.nextSibling):(yield*a.value.reportError(b.fail(i.error)),n.nextSibling)})}function Xe(e){let t=0,n=e.nextSibling;for(;n!==null;){if(n.nodeType===X){let e=u(n);if(e!==null)if(e.kind===`start`)t++;else if(t===0)return n;else t--}n=n.nextSibling}return null}function Ze(e,t,n){return C.gen(function*(){if(t===null||t.nodeType!==Y||t.tagName!==`SCRIPT`||t.getAttribute(`type`)!==`application/json`||!t.hasAttribute(`data-weft-boundary-failure`)){let r=yield*s,i=yield*C.serviceOption(d),a=yield*A.fork(r.scope,`sequential`),o={...r,scope:a},c=yield*S.make(),l=yield*J(e,t,n).pipe(C.provideService(d,{reportError:e=>S.fail(c,e).pipe(C.asVoid)}),C.provideService(s,o),C.provideService(A.Scope,a)),u=t?.parentNode??null;if(t===null||t===l||u===null)return console.error(`[weft] hydrate: boundary at ${n} adopted an empty extent; live failure recovery is not installed for it.`),l;let p=z(),m=document.createComment(h(p)),g=document.createComment(f(p));return u.insertBefore(m,t),l===null?u.appendChild(g):u.insertBefore(g,l),yield*C.forkIn(be(e,c,a,i,m,g),r.scope),l}let r=t,i=r.textContent??``,a=yield*C.gen(function*(){let t=yield*C.try({try:()=>JSON.parse(i),catch:e=>e}),n=y(e.children)[t.index];if(n===void 0)return null;let r=yield*re.decodeUnknownEffect(n.errorSchema)(t.error);return e.match(b.fail(r))}).pipe(C.catch(e=>(console.error(`[weft] hydrate: boundary failure payload at ${n} failed to decode; cannot replay.`,e),C.succeed(null))));if(a===null)return yield*Q(`replayable boundary failure`,`undecodable failure payload`,n);let o=yield*q(a,r.nextSibling,n);return r.remove(),o})}function Qe(e,t,n,r){return C.gen(function*(){let i=yield*M.make(n),a=yield*M.make(!1),o=yield*M.make(D.none()),s=D.match(r,{onNone:()=>C.void,onSome:n=>C.gen(function*(){(yield*M.get(a))||(yield*M.set(a,!0),yield*C.gen(function*(){let r=yield*C.exit(n.call(e,t()));w.isSuccess(r)?(yield*M.set(i,r.value),yield*M.set(o,D.none())):yield*M.set(o,D.some(b.squash(r.cause)))}).pipe(C.ensuring(M.set(a,!1))))})});return{value:P.make({get:M.get(i),changes:M.changes(i)}),refetch:s,pending:P.make({get:M.get(a),changes:M.changes(a)}),error:P.make({get:M.get(o),changes:M.changes(o)})}})}function $e(e,t,n){return C.gen(function*(){if(t===null||t.nodeType!==Y||t.tagName!==`SCRIPT`||t.getAttribute(`type`)!==`application/json`)return yield*Q(`server boundary payload <script type="application/json">`,Z(t),n);if(t.hasAttribute(`data-weft-boundary-failure`))return yield*Q(`server boundary success payload <script type="application/json">`,`boundary failure payload`,n);let r=t,i=r.textContent??``,a=yield*C.try({try:()=>JSON.parse(i),catch:e=>e}).pipe(C.flatMap(t=>re.decodeUnknownEffect(e.successSchema)(t)),C.catch(e=>(console.error(`[weft] hydrate: server boundary payload at ${n} failed to decode; cannot replay.`,e),Q(`decodable server boundary payload`,`undecodable payload`,n)))),o=yield*C.serviceOption(ie),s=yield*Qe(e.tag,e.payload,a,o),c=yield*q(e.render(s),r.nextSibling,n);return r.remove(),c})}function et(e,t,n,r){return C.gen(function*(){if(n===null||n.nodeType!==Y)return yield*Q(`<${e}>`,Z(n),r);let i=n;return i.tagName.toLowerCase()===e.toLowerCase()?(yield*B(i,t),yield*J(t,i.firstChild,`${r} > ${e}`),i.nextSibling):yield*Q(`<${e}>`,Z(n),r)})}function J(e,t,n){return C.gen(function*(){let r=`children`in e?e.children:void 0;if(r===void 0)return t;let i=Array.isArray(r)?r:[r],a=t,o=0;for(let e of i)a=yield*q(e,a,`${n}[${o}]`),o++;return a})}function tt(e,t,n){return C.gen(function*(){let r=yield*s,{of:a,by:o,render:c}=e;if(t===null||t.nodeType!==X)return yield*Q(`list region start marker`,Z(t),n);let l=t,u=i(l);if(u===null||u.kind!==`start`)return yield*Q(`list region start marker`,Z(t),n);let d=st(l);if(d===null)return yield*Q(`list region end marker`,`unterminated region starting at ${JSON.stringify(l.data)}`,n);let f=nt(l,d),p=yield*A.fork(r.scope,`sequential`),m=yield*ue.toSubscribable(a).pipe(C.provideService(A.Scope,p)),h=P.changes(m),g={records:T.empty(),order:[]},_=!0,v=Ke(r.hydrationReady),y=j.runForEach(h,e=>C.gen(function*(){let t=Array.from(e);_?(_=!1,g=yield*rt(t,o,c,f,p,l,d,r,n),yield*v):g=yield*Re(t,o,c,g,p,d,r)})).pipe(C.ensuring(v));return r.hydrationReady!==void 0&&(yield*r.hydrationReady.register),yield*H(y,p,`hydrate:list-${u.id} (${n})`,r.reportUnhandled),d.nextSibling})}function nt(e,t){let n=[],r=e.nextSibling;for(;r!==null&&r!==t;){let e=r.nodeType===X?g(r):null;if(e===null||e.kind!==`start`){r=r.nextSibling;continue}let i=r,a=[],o=0,s=null,c=i.nextSibling;for(;c!==null&&c!==t;){if(c.nodeType===X){let e=g(c);if(e!==null)if(e.kind===`start`)o++;else if(o===0){s=c;break}else o--}a.push(c),c=c.nextSibling}if(s===null)break;n.push({startMarker:i,endMarker:s,nodes:a}),r=s.nextSibling}return n}function rt(e,t,n,r,i,a,o,s,c){return C.gen(function*(){let l=yield*Le(e,t);if(l.length!==r.length)return console.error(`[weft] hydrate: list region at ${c} had ${r.length} server item(s) but the first emission has ${l.length}; rebuilding.`),K(a,o),yield*Re(e,t,n,{records:T.empty(),order:[]},i,o,s);let u=[];for(let t=0;t<e.length;t++){let a=yield*it(l[t],e[t],t,n,r[t],i,s,c);u.push(a)}let d=T.empty();for(let e of u)d=T.set(d,e.key,e);return{records:d,order:l}})}function it(e,t,n,r,i,a,o,c){return C.gen(function*(){let l=yield*A.fork(a,`sequential`),u={...o,scope:l},d=r(t,n),f=yield*q(d,i.startMarker.nextSibling,`${c}<item>`).pipe(C.provideService(s,u),C.provideService(A.Scope,l),C.map(e=>e===i.endMarker?null:`adopted item content did not align with its end marker`),C.catchTag(`HydrationMismatchError`,e=>C.succeed(`expected ${e.expected}, found ${e.actual} at ${e.path}`)));if(f===null)return{key:e,scope:l,startMarker:i.startMarker,endMarker:i.endMarker,nodes:i.nodes};console.error(`[weft] hydrate: list item at ${c} diverged from server output (${f}); patching.`),yield*A.close(l,w.void);let p=yield*A.fork(a,`sequential`),m={...o,scope:p};K(i.startMarker,i.endMarker);let h=yield*W(d).pipe(C.provideService(s,m),C.provideService(A.Scope,p)),g=h===null?[]:Array.isArray(h)?h:[h],_=i.endMarker.parentNode;if(_!==null)for(let e of g)_.insertBefore(e,i.endMarker);return{key:e,scope:p,startMarker:i.startMarker,endMarker:i.endMarker,nodes:g}})}const Y=1,at=3,X=8;function ot(e,t){let n=document.createTreeWalker(e,128),r=t.current;for(let e=n.nextNode();e!==null;e=n.nextNode()){let t=e,n=i(t)??u(t)??g(t);n!==null&&n.id>r&&(r=n.id)}t.current=r}function st(e){let t=0,n=e.nextSibling;for(;n!==null;){if(n.nodeType===8){let e=i(n);if(e!==null)if(e.kind===`start`)t++;else if(t===0)return n;else t--}n=n.nextSibling}return null}function Z(e){if(e===null)return`end of children`;switch(e.nodeType){case 1:return`<${e.tagName.toLowerCase()}>`;case 3:return`text ${JSON.stringify(e.data)}`;case 8:return`comment ${JSON.stringify(e.data)}`;default:return`node(type ${e.nodeType})`}}function Q(e,t,n){return C.fail(new c({expected:e,actual:t,path:n}))}var ct=e({TypeId:()=>lt,dispose:()=>yt,errors:()=>vt,hydrate:()=>_t,make:()=>ht,mount:()=>gt});const lt=Symbol.for(`@weftui/dom/WeftApp`),ut=new WeakMap;function $(e){let t=ut.get(e);if(t===void 0)throw Error(`Expected a WeftApp created by WeftApp.make`);return t}function dt(e,t){return C.gen(function*(){e.subscribers===0&&(yield*N(C.logError(t.cause),C.annotateLogs(`weft.region`,t.region))),yield*O.publish(e.hub,t)})}function ft(e){return C.suspend(()=>$(e).disposed?C.die(Error(`Cannot mount on a disposed WeftApp`)):e.runtime.contextEffect)}function pt(e,t){return C.gen(function*(){let n=$(e),r=yield*A.fork(n.appScope,`sequential`),i=!1,a={element:t,unmount:()=>C.suspend(()=>i?C.void:(i=!0,A.close(r,w.void)))};return{context:{runtime:e.runtime,scope:r,rootScope:r,streamIdCounter:{current:0},reportUnhandled:(e,t)=>dt(n,{cause:e,region:t,root:a})},handle:a,rootScope:r}})}function mt(e,t){let n=ne.make(e??te.empty,t),r=C.runSync(O.unbounded()),i={[lt]:lt,runtime:n};return ut.set(i,{appScope:A.makeUnsafe(`sequential`),hub:r,subscribers:0,disposed:!1}),i}const ht=mt,gt=(e,t,n)=>C.gen(function*(){let r=yield*ft(e),{context:i,handle:a,rootScope:o}=yield*pt(e,n);n.innerHTML=``;let c=yield*N(W(t),C.setContext(N(r,x.add(s,i),x.add(A.Scope,o))),C.tapError(()=>A.close(o,w.void)));if(c!==null)if(Array.isArray(c))for(let e of c)n.appendChild(e);else n.appendChild(c);return a});function _t(e,t,n){return C.gen(function*(){let r=yield*ft(e),{context:i,handle:a,rootScope:o}=yield*pt(e,n),c=yield*Ge(),l={...i,hydrationReady:c};return ot(n,l.streamIdCounter),yield*N(q(t,n.firstChild,`root`),C.setContext(N(r,x.add(s,l),x.add(A.Scope,o))),C.tapError(()=>A.close(o,w.void))),yield*c.settle,yield*c.awaitReady,a})}const vt=e=>{let t=$(e);return j.unwrap(C.sync(()=>(t.subscribers++,N(j.fromPubSub(t.hub),j.ensuring(C.sync(()=>{t.subscribers--}))))))},yt=e=>C.suspend(()=>{let t=$(e);return t.disposed?C.void:(t.disposed=!0,N(A.close(t.appScope,w.void),C.andThen(e.runtime.disposeEffect),C.andThen(O.shutdown(t.hub))))});export{ct as WeftApp};
1
+ import{t as e}from"../rolldown-runtime-DK3Fl9T5.js";import{_ as t,a as n,b as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,u as _,y as v}from"../shared-Dz0KM9ku.js";import{n as y}from"../boundary-replay-BY4GyLot.js";import{Cause as b,Context as x,Deferred as S,Effect as C,Exit as w,Fiber as ee,HashMap as T,HashSet as E,Layer as te,ManagedRuntime as ne,Option as D,PubSub as re,Ref as O,Schema as ie,Scope as k,Stream as A,SubscriptionRef as j,pipe as M}from"effect";import{AppRpcClientTag as ae,FAILURE_BOUNDARY as oe,FRAGMENT as se,LIST as ce,SERVER_BOUNDARY as le,SUSPENSE_BOUNDARY as ue,Source as de,Subscribable as fe,getElementDescriptor as N,isStream as P,toStream as F}from"@weftui/core";const pe=new WeakMap;function me(e){let t=pe.get(e);if(t===void 0)throw Error(`Expected a Loom created by makeLoomUnsafe`);return t}function he(e,t){return C.suspend(()=>t.alive?(t.alive=!1,e.cells.delete(t.seq),e.dirty.delete(t),!t.committedOnce&&t.onDiscard!==void 0?ge(t.onDiscard):C.void):C.void)}function ge(e){return M(C.exit(e),C.flatMap(e=>w.isFailure(e)?M(C.logError(e.cause),C.annotateLogs(`weft.region`,`loom:flush`)):C.void))}function I(e){return C.suspend(()=>{let t=e.barriers;return e.barriers=[],C.forEach(t,t=>S.succeed(t,e.generation),{discard:!0})})}function _e(e){return C.gen(function*(){yield*S.await(e.wake),e.flushing=!0,e.wake=S.makeUnsafe();let t=!1;for(;e.dirty.size>0;){let n=[...e.dirty].sort((e,t)=>e.seq-t.seq);for(let r of n){if(e.dirty.delete(r),!r.alive)continue;let n=yield*C.exit(r.commit(r.latest));if(!r.alive){w.isSuccess(n)&&(t=!0);continue}w.isSuccess(n)?(t=!0,r.committedOnce||(r.committedOnce=!0,r.onFirstCommit!==void 0&&(yield*ge(r.onFirstCommit)))):b.hasInterruptsOnly(n.cause)||(yield*ge(D.isSome(r.boundary)?r.boundary.value.reportError(n.cause):r.reportUnhandled(n.cause,r.label)),yield*he(e,r),r.pumpFiber!==void 0&&(yield*M(ee.interrupt(r.pumpFiber),C.forkDetach)))}}t&&e.generation++,e.flushing=!1,yield*I(e)})}function ve(){let e={nextSeq:0,cells:new Map,dirty:new Set,wake:S.makeUnsafe(),barriers:[],generation:0,flushing:!1,flushStarted:!1},t={register:t=>C.gen(function*(){let n={seq:e.nextSeq++,label:t.label,latest:void 0,everWritten:!1,committedOnce:!1,alive:!0,commit:t.commit,boundary:t.boundary,reportUnhandled:t.reportUnhandled,onFirstCommit:t.onFirstCommit,onDiscard:t.onDiscard,pumpFiber:void 0};return e.cells.set(n.seq,n),yield*k.addFinalizer(t.scope,he(e,n)),{write:t=>C.suspend(()=>n.alive?(n.latest=t,n.everWritten=!0,e.dirty.add(n),C.asVoid(S.succeed(e.wake,void 0))):C.void),everWritten:()=>n.everWritten,attachPumpFiber:e=>{n.pumpFiber=e}}}),awaitCommit:C.suspend(()=>{if(e.dirty.size===0&&!e.flushing)return C.succeed(e.generation);let t=S.makeUnsafe();return e.barriers.push(t),S.await(t)}),commitGeneration:C.sync(()=>e.generation)};return pe.set(t,e),t}function ye(e,t){return C.suspend(()=>{let n=me(e);return n.flushStarted?C.void:(n.flushStarted=!0,M(_e(n),C.catchCause(e=>M(C.logError(e),C.annotateLogs(`weft.region`,`loom:flush`),C.andThen(C.suspend(()=>(n.flushing=!1,I(n)))))),C.forever,C.onInterrupt(()=>C.suspend(()=>(n.flushing=!1,I(n)))),C.forkIn(t),C.asVoid))})}function L(){return C.gen(function*(){let e=yield*s;return++e.streamIdCounter.current})}const be=L;let xe=0;const R=()=>++xe;function z(e,t){return C.gen(function*(){for(let[n,r]of Object.entries(t))if(n!==`children`){if(l(n)){yield*ke(e,n,r);continue}if(n===`ref`&&typeof r==`object`&&j.isSubscriptionRef(r)){yield*j.set(r,D.some(e));continue}if(n===`ref`&&Array.isArray(r)){yield*C.forEach(r.filter(e=>j.isSubscriptionRef(e)),t=>j.set(t,D.some(e)),{discard:!0});continue}if(n===`style`){yield*Ee(e,r);continue}Se(e,n)?yield*Ce(e,n,r):yield*we(e,n,r)}})}function Se(e,t){if(t.startsWith(`data-`)||t.startsWith(`aria-`))return!1;let n=Object.getPrototypeOf(e);for(;n!==null;){if(Object.hasOwn(n,t))return!0;n=Object.getPrototypeOf(n)}return t in e}function Ce(e,t,n){return C.gen(function*(){P(n)||C.isEffect(n)?yield*H(F(n),n=>{n==null?delete e[t]:e[t]=n},`property:${t}`):n!=null&&(e[t]=n)})}function we(e,t,n){return C.gen(function*(){if(P(n)||C.isEffect(n))yield*H(F(n),n=>{if(n==null)e.removeAttribute(t);else{let r=Te(n);r!==void 0&&(typeof n==`boolean`?n?e.setAttribute(t,``):e.removeAttribute(t):e.setAttribute(t,r))}},`attribute:${t}`);else{let r=Te(n);r!==void 0&&(typeof n==`boolean`?n?e.setAttribute(t,``):e.removeAttribute(t):e.setAttribute(t,r))}})}function Te(e){if(e!=null)return String(e)}function Ee(e,t){return C.gen(function*(){if(P(t)||C.isEffect(t)){yield*H(F(t),t=>{if(typeof t==`string`)e.setAttribute(`style`,t);else if(typeof t==`object`&&t){e.style.cssText=``;for(let[n,r]of Object.entries(t))r!=null&&e.style.setProperty(B(n),String(r))}},`style`);return}if(typeof t==`string`){e.setAttribute(`style`,t);return}typeof t==`object`&&t&&(yield*De(e,t))})}function De(e,t){return C.gen(function*(){for(let[n,r]of Object.entries(t))P(r)||C.isEffect(r)?yield*H(F(r),t=>{t!=null&&e.style.setProperty(B(n),String(t))},`style.${n}`):r!=null&&e.style.setProperty(B(n),String(r))})}function B(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function Oe(e){return e.reasons.every(e=>e._tag===`Interrupt`||e._tag===`Fail`&&b.isDone(e.error)||e._tag===`Die`&&b.isDone(e.defect))}function V(e,t,n,r){return C.gen(function*(){let i=yield*C.serviceOption(d),a=M(e,C.onExit(e=>w.isFailure(e)&&!Oe(e.cause)?D.isSome(i)?i.value.reportError(e.cause):r(e.cause,n):C.void));return yield*C.forkIn(a,t)})}function H(e,t,n){return C.gen(function*(){let r=yield*s,i=yield*C.serviceOption(d),a=yield*r.loom.register({label:n,scope:r.scope,boundary:i,reportUnhandled:r.reportUnhandled,commit:e=>C.sync(()=>void t(e))}),o=yield*V(A.runForEach(e,a.write),r.scope,n,r.reportUnhandled);a.attachPumpFiber(o)})}function ke(e,t,n){return C.gen(function*(){let r=yield*s,i=t.slice(2).toLowerCase(),a=null,o=()=>{a&&=(e.removeEventListener(i,a),null)},c=n=>{o(),!(n==null||n===!1)&&typeof n==`function`&&(a=e=>{let i=n(e);C.isEffect(i)&&r.runtime.runFork(M(i,C.provideService(k.Scope,r.rootScope),C.exit,C.flatMap(e=>w.isFailure(e)&&!b.hasInterruptsOnly(e.cause)?r.reportUnhandled(e.cause,`event:${t}`):C.void)))},e.addEventListener(i,a))};yield*k.addFinalizer(r.scope,C.sync(o)),P(n)||C.isEffect(n)?yield*H(F(n),e=>c(e),`event:${t}`):c(n)})}function Ae(e,t,n,r,i,a){return C.gen(function*(){let o=yield*s,c=yield*S.await(t).pipe(C.flip,C.catch(()=>C.interrupt)),l=e.match(c);if(yield*k.close(n,w.void),l===null)return D.isSome(r)?yield*r.value.reportError(c):yield*o.reportUnhandled(c,`boundary:outermost`);K(i,a);let u=yield*U(l),d=a.parentNode;if(d!==null&&u!==null)if(Array.isArray(u))for(let e of u)d.insertBefore(e,a);else d.insertBefore(u,a)})}function je(e){return C.gen(function*(){let t=yield*s,n=yield*C.serviceOption(d),r=R(),i=document.createComment(h(r)),a=document.createComment(f(r)),o=yield*k.fork(t.scope,`sequential`),c={...t,scope:o},l=yield*S.make(),u=yield*M(Fe(e.children),C.provideService(d,{reportError:e=>S.fail(l,e).pipe(C.asVoid)}),C.provideService(s,c),C.provideService(k.Scope,o),C.catchCause(t=>{let n=e.match(t);return n===null?C.failCause(t):M(k.close(o,w.void),C.flatMap(()=>U(n)),C.map(e=>e===null?[]:Array.isArray(e)?e:[e]))}));return yield*C.forkIn(Ae(e,l,o,n,i,a),t.scope),[i,...u,a]})}function Me(e){return C.gen(function*(){let t=yield*s,n=yield*O.make(1),r=yield*S.make(),i=M(O.updateAndGet(n,e=>e-1),C.flatMap(e=>e<=0?C.asVoid(S.succeed(r,void 0)):C.void)),a={register:O.update(n,e=>e+1),settle:i},c=e.children,l=yield*U((c===void 0?[]:Array.isArray(c)?c:[c]).map(e=>N(e)===void 0&&(C.isEffect(e)||P(e))?{type:()=>e,props:{}}:e)).pipe(C.provideService(v,a)),u=l===null?[]:Array.isArray(l)?l:[l];yield*i;let d=yield*S.poll(r);if(D.isSome(d))return u;let f=yield*be(),p=document.createComment(m(f)),h=document.createComment(o(f)),g=yield*U(e.fallback??null),_=[];g!==null&&(Array.isArray(g)?_.push(...g):_.push(g));let y=document.createDocumentFragment();for(let e of u)y.appendChild(e);let b=C.gen(function*(){yield*S.await(r),K(p,h);let e=h.parentNode;e!==null&&(e.insertBefore(y,h),p.remove(),h.remove())});return yield*C.forkIn(b,t.scope),[p,..._,h]})}function Ne(e){return C.gen(function*(){let n=yield*s,r=yield*C.serviceOption(ae);if(D.isNone(r))return yield*C.fail(new t({cause:void 0,message:`Boundary.rpc "${e.tag}" was mounted client-first without an AppRpcClient in context. Mount the app under @weftui/router (RouterLive), which provides the rpc client, so the boundary can resolve its data.`}));let i=r.value,a=R(),o=document.createComment(h(a)),c=document.createComment(f(a)),l=yield*U(e.fallback??null),u=[];l!==null&&(Array.isArray(l)?u.push(...l):u.push(l));let d=C.gen(function*(){let t=yield*i.call(e.tag,e.payload()),n=yield*st(e.tag,e.payload,t,r),a=yield*U(e.render(n));K(o,c);let s=c.parentNode;if(s!==null&&a!==null)if(Array.isArray(a))for(let e of a)s.insertBefore(e,c);else s.insertBefore(a,c)}).pipe(C.catchCause(t=>C.logError(`[weft] Boundary.rpc "${e.tag}" mount failed to resolve; fallback left in place.`,t)));return yield*C.forkIn(d,n.scope),[o,...u,c]})}function U(e){return C.gen(function*(){if(typeof e==`string`||typeof e==`number`||typeof e==`bigint`)return document.createTextNode(String(e));if(typeof e==`boolean`||e==null)return null;if(P(e)||C.isEffect(e)){let t=N(e);if(t!==void 0)return yield*U(t);if(C.isEffect(e)){let t=yield*C.context(),n=C.runSyncExitWith(t)(e);if(w.isSuccess(n))return yield*U(n.value)}return yield*W(F(e))}if(typeof e==`object`&&Symbol.iterator in e&&!(`type`in e))return yield*Fe(Pe(e));if(typeof e==`object`&&`type`in e&&!(Symbol.iterator in e)){let{type:t,props:n}=e;return t===se?yield*Ie(n):t===ue?yield*Me(n):t===le?yield*Ne(n):t===oe?yield*je(n):t===ce?yield*Ge(n):typeof t==`string`?yield*Le(t,n):typeof t==`function`?yield*Re(t,n):yield*C.fail(new r({type:t,message:`Invalid Renderable type: expected string, FRAGMENT, or function, got ${typeof t}`}))}return null})}function Pe(e){let t=[];function n(e){if(P(e)||C.isEffect(e)){t.push(e);return}if(typeof e==`object`&&e&&Symbol.iterator in e&&!(`type`in e))for(let t of e)n(t);else t.push(e)}return n(e),t}function Fe(e){return C.gen(function*(){let t=[];for(let n of e)if(N(n)===void 0&&(P(n)||C.isEffect(n))){let e=yield*W(F(n));t.push(...e)}else{let e=yield*U(n);e!==null&&(Array.isArray(e)?t.push(...e):t.push(e))}return t})}function Ie(e){return C.gen(function*(){let t=`children`in e?e.children:void 0;return t===void 0?[]:yield*Fe(Array.isArray(t)?t:[t])})}function Le(e,t){return C.gen(function*(){let n=document.createElement(e);yield*z(n,t);let r=`children`in t?t.children:void 0;if(r!==void 0){let e=Array.isArray(r)?r:[r];for(let t of e)if(N(t)===void 0&&(P(t)||C.isEffect(t))){let e=yield*W(F(t));for(let t of e)n.appendChild(t)}else{let e=yield*U(t);if(e!==null)if(Array.isArray(e))for(let t of e)n.appendChild(t);else n.appendChild(e)}}return n})}function Re(e,t){return C.gen(function*(){let n=e(t);if(P(n)||C.isEffect(n)){let e=yield*s,t=yield*k.fork(e.scope,`sequential`),r={...e,scope:t},i=yield*C.serviceOption(v),a=F(n),o;if(D.isSome(i)){yield*i.value.register;let e=!1;o=C.suspend(()=>e?C.void:(e=!0,i.value.settle))}return yield*W(a,{onFirstCommit:o}).pipe(C.provideService(s,r),C.provideService(k.Scope,t))}return yield*U(n)})}function W(e,t){return C.gen(function*(){let n=yield*s,r=yield*C.serviceOption(d),i=yield*C.context(),a=yield*L(),[o,c]=ze(a),l=null,u=yield*n.loom.register({label:`child:stream-${a}`,scope:n.scope,boundary:r,reportUnhandled:n.reportUnhandled,onFirstCommit:t?.onFirstCommit,onDiscard:t?.onFirstCommit,commit:e=>C.gen(function*(){l!==null&&(yield*k.close(l,w.void)),l=yield*k.fork(n.scope,`sequential`);let t={...n,scope:l};yield*G(o,c,e).pipe(C.provideService(s,t),C.provideService(k.Scope,l))}).pipe(C.provide(i))}),f=A.runForEach(e,u.write);if(t?.onFirstCommit!==void 0){let e=t.onFirstCommit;f=M(f,C.ensuring(C.suspend(()=>u.everWritten()?C.void:e)))}let p=yield*V(f,n.scope,`child:stream-${a}`,n.reportUnhandled);return u.attachPumpFiber(p),[o,c]})}function ze(e){return[document.createComment(a(e)),document.createComment(_(e))]}function G(e,t,n){return C.gen(function*(){let r=e.nextSibling,i=r!==null&&r!==t&&r.nextSibling===t;if(i&&r.nodeType===mt&&Be(n)){let e=String(n);r.data!==e&&(r.data=e);return}if(i&&r.nodeType===Y){let e=Ve(n);if(e!==void 0&&typeof e.type==`string`&&r.tagName.toLowerCase()===e.type.toLowerCase()){yield*He(r,e);return}}K(e,t);let a=yield*U(n),o=e.parentNode;if(o!==null&&a!==null)if(Array.isArray(a))for(let e of a)o.insertBefore(e,t);else o.insertBefore(a,t)})}function Be(e){return typeof e==`string`||typeof e==`number`||typeof e==`bigint`}function Ve(e){let t=N(e);if(t!==void 0)return t;if(typeof e==`object`&&e&&`type`in e&&!(Symbol.iterator in e)&&!P(e)&&!C.isEffect(e))return e}function He(e,t){return C.gen(function*(){yield*z(e,t.props);let n=t.props.children,r=n===void 0?[]:Array.isArray(n)?n:[n];if(!(yield*Ue(e,r))){for(;e.firstChild!==null;)e.firstChild.remove();yield*We(e,r)}})}function Ue(e,t){return C.gen(function*(){let n=Array.from(e.childNodes);if(n.length!==t.length)return!1;for(let e=0;e<t.length;e++){let r=t[e],i=n[e];if(Be(r)){if(i.nodeType!==mt)return!1}else{let e=Ve(r);if(e===void 0||typeof e.type!=`string`||i.nodeType!==Y||i.tagName.toLowerCase()!==e.type.toLowerCase())return!1}}for(let e=0;e<t.length;e++){let r=t[e],i=n[e];if(Be(r)){let e=String(r);i.data!==e&&(i.data=e)}else yield*He(i,Ve(r))}return!0})}function We(e,t){return C.gen(function*(){for(let n of t)if(P(n)||C.isEffect(n)){let t=yield*W(F(n));for(let n of t)e.appendChild(n)}else{let t=yield*U(n);if(t!==null)if(Array.isArray(t))for(let n of t)e.appendChild(n);else e.appendChild(t)}})}function K(e,t){let n=e.nextSibling;for(;n!==null&&n!==t;){let e=n.nextSibling;n.remove(),n=e}}function Ge(e){return C.gen(function*(){let t=yield*s,{of:n,by:r,render:i}=e,a=yield*L(),[o,c]=ze(a),l=yield*k.fork(t.scope,`sequential`),u=yield*C.serviceOption(d),f=yield*C.context(),p=de.changes(n),m={records:T.empty(),order:[]},h=yield*t.loom.register({label:`list:stream-${a}`,scope:l,boundary:u,reportUnhandled:t.reportUnhandled,commit:e=>C.gen(function*(){m=yield*qe(Array.from(e),r,i,m,l,c,t)}).pipe(C.provideService(s,t),C.provideService(k.Scope,l),C.provide(f))}),g=yield*V(A.runForEach(p,h.write),l,`list:stream-${a}`,t.reportUnhandled);return h.attachPumpFiber(g),[o,c]})}function Ke(e,n){return C.gen(function*(){let r=[],i=E.empty();for(let a=0;a<e.length;a++){let o=n===void 0?e[a]:n(e[a],a);if(E.has(i,o))return yield*C.fail(new t({cause:o,message:`List.each: duplicate key ${Ze(o)} in a single emission; keys must be unique (set a stable \`by\`).`}));i=E.add(i,o),r.push(o)}return r})}function qe(e,t,n,r,i,a,o){return C.gen(function*(){let s=yield*Ke(e,t),c=T.empty();r.order.forEach((e,t)=>{c=T.set(c,e,t)});let l=[],u=[];for(let t=0;t<e.length;t++){let a=s[t],d=T.get(r.records,a);if(D.isSome(d))l.push(d.value),u.push(D.getOrElse(T.get(c,a),()=>-1));else{let r=yield*Je(a,e[t],t,n,i,o);l.push(r),u.push(-1)}}let d=E.empty();for(let e of s)d=E.add(d,e);for(let e of r.order)if(!E.has(d,e)){let t=T.get(r.records,e);D.isSome(t)&&(yield*k.close(t.value.scope,w.void),Xe(t.value.startMarker,t.value.endMarker))}let f=Qe(u),p=a.parentNode;if(p!==null)for(let e=l.length-1;e>=0;e--){let t=l[e];if(u[e]!==-1&&f.has(e))continue;let n=e+1<l.length?l[e+1].startMarker:a,r=u[e]===-1?[t.startMarker,...t.nodes,t.endMarker]:Ye(t.startMarker,t.endMarker);for(let e of r)p.insertBefore(e,n)}let m=T.empty();for(let e of l)m=T.set(m,e.key,e);return{records:m,order:s}})}function Je(e,t,r,i,a,o){return C.gen(function*(){let c=yield*k.fork(a,`sequential`),l={...o,scope:c},u=yield*L(),d=document.createComment(p(u)),f=document.createComment(n(u)),m=yield*U(i(t,r)).pipe(C.provideService(s,l),C.provideService(k.Scope,c));return{key:e,scope:c,startMarker:d,endMarker:f,nodes:m===null?[]:Array.isArray(m)?m:[m]}})}function Ye(e,t){let n=[],r=e;for(;r!==null&&(n.push(r),r!==t);)r=r.nextSibling;return n}function Xe(e,t){let n=e;for(;n!==null;){let e=n.nextSibling;if(n.remove(),n===t)break;n=e}}function Ze(e){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`object`&&e)try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}return String(e)}function Qe(e){let t=e.length,n=[],r=Array.from({length:t},()=>-1);for(let i=0;i<t;i++){let t=e[i];if(t===-1)continue;let a=0,o=n.length;for(;a<o;){let r=a+o>>1;e[n[r]]<t?a=r+1:o=r}a>0&&(r[i]=n[a-1]),n[a]=i}let i=new Set,a=n.length>0?n[n.length-1]:-1;for(;a!==-1;)i.add(a),a=r[a];return i}function q(e,t,n){return C.gen(function*(){if(typeof e==`string`||typeof e==`number`||typeof e==`bigint`)return yield*$e(String(e),t,n);if(typeof e==`boolean`||e==null)return t;if(P(e)||C.isEffect(e)){let r=N(e);if(r!==void 0)return yield*q(r,t,n);if(C.isEffect(e)){let r=C.runSyncExit(e);if(w.isSuccess(r))return yield*q(r.value,t,n)}return yield*nt(F(e),t,n)}if(typeof e==`object`&&Symbol.iterator in e&&!(`type`in e)){let r=t,i=0;for(let t of e)r=yield*q(t,r,`${n}[${i}]`),i++;return r}if(typeof e==`object`&&`type`in e&&!(Symbol.iterator in e)){let{type:i,props:a}=e;if(i===se)return yield*J(a,t,n);if(i===ue){if(t!==null&&t.nodeType===X){let e=u(t);if(e!==null&&e.kind===`start`)return yield*it(t,n)}return yield*J(a,t,n)}return i===oe?yield*ot(a,t,n):i===le?yield*ct(a,t,n):i===ce?yield*ut(a,t,n):typeof i==`string`?yield*lt(i,a,t,n):typeof i==`function`?yield*q(i(a),t,n):yield*C.fail(new r({type:i,message:`Invalid Renderable type during hydration at ${n}: expected string, FRAGMENT, or function, got ${typeof i}`}))}return t})}function $e(e,t,n){return C.gen(function*(){if(e.length===0)return t;if(t===null||t.nodeType!==mt)return yield*Q(`text ${JSON.stringify(e)}`,Z(t),n);let r=t;return r.data.startsWith(e)?r.data.length>e.length?r.splitText(e.length):r.nextSibling:yield*Q(`text ${JSON.stringify(e)}`,Z(t),n)})}function et(){return C.gen(function*(){let e=yield*O.make(1),t=yield*S.make(),n=M(O.updateAndGet(e,e=>e-1),C.flatMap(e=>e<=0?C.asVoid(S.succeed(t,void 0)):C.void));return{register:O.update(e,e=>e+1),settle:n,awaitReady:S.await(t)}})}function tt(e){let t=!1;return C.suspend(()=>t||e===void 0?C.void:(t=!0,e.settle))}function nt(e,t,n){return C.gen(function*(){let r=yield*s;if(t===null||t.nodeType!==X)return yield*Q(`reactive region start marker`,Z(t),n);let a=t,o=i(a);if(o===null||o.kind!==`start`)return yield*Q(`reactive region start marker`,Z(t),n);let c=gt(a);if(c===null)return yield*Q(`reactive region end marker`,`unterminated region starting at ${JSON.stringify(a.data)}`,n);let l=tt(r.hydrationReady),u=yield*C.serviceOption(d),f=yield*C.context(),p=!0,m=null,h=yield*r.loom.register({label:`hydrate:stream-${o.id} (${n})`,scope:r.scope,boundary:u,reportUnhandled:r.reportUnhandled,onFirstCommit:l,onDiscard:l,commit:e=>C.gen(function*(){m!==null&&(yield*k.close(m,w.void)),m=yield*k.fork(r.scope,`sequential`);let t={...r,scope:m};yield*C.gen(function*(){p?(p=!1,yield*rt(e,a,c,n)):yield*G(a,c,e)}).pipe(C.provideService(s,t),C.provideService(k.Scope,m))}).pipe(C.provide(f))}),g=M(A.runForEach(e,h.write),C.ensuring(C.suspend(()=>h.everWritten()?C.void:l)));r.hydrationReady!==void 0&&(yield*r.hydrationReady.register);let _=yield*V(g,r.scope,`hydrate:stream-${o.id} (${n})`,r.reportUnhandled);return h.attachPumpFiber(_),c.nextSibling})}function rt(e,t,n,r){return C.gen(function*(){let i=yield*q(e,t.nextSibling,`${r}<resume>`).pipe(C.map(e=>e===n?null:`adopted content did not align with the end marker`),C.catchTag(`HydrationMismatchError`,e=>C.succeed(`expected ${e.expected}, found ${e.actual} at ${e.path}`)));i!==null&&(console.error(`[weft] hydrate: reactive region at ${r} diverged from server output (${i}); patching.`),yield*G(t,n,e))})}function it(e,t){return C.gen(function*(){let n=at(e);if(n===null)return yield*Q(`substituted suspense end marker`,`unterminated region starting at ${JSON.stringify(e.data)}`,t);let r=null;for(let t=e.nextSibling;t!==null&&t!==n;t=t.nextSibling)if(t.nodeType===Y&&t.tagName===`SCRIPT`&&t.getAttribute(`type`)===`application/json`&&t.hasAttribute(`data-weft-suspense-failure`)){r=t;break}let i=null;if(r!==null){let e=r.textContent??``;i=yield*C.try({try:()=>JSON.parse(e),catch:e=>e}).pipe(C.catch(()=>C.succeed(null)))}if(typeof i!=`object`||!i||!(`error`in i))return console.error(`[weft] hydrate: substituted suspense region at ${t} has no decodable failure sentinel; leaving its static content.`),n.nextSibling;let a=yield*C.serviceOption(d);return D.isNone(a)?(console.error(`[weft] hydrate: substituted suspense region at ${t} has no enclosing Boundary to replay its failure to; leaving its static content.`,i.error),n.nextSibling):(yield*a.value.reportError(b.fail(i.error)),n.nextSibling)})}function at(e){let t=0,n=e.nextSibling;for(;n!==null;){if(n.nodeType===X){let e=u(n);if(e!==null)if(e.kind===`start`)t++;else if(t===0)return n;else t--}n=n.nextSibling}return null}function ot(e,t,n){return C.gen(function*(){if(t===null||t.nodeType!==Y||t.tagName!==`SCRIPT`||t.getAttribute(`type`)!==`application/json`||!t.hasAttribute(`data-weft-boundary-failure`)){let r=yield*s,i=yield*C.serviceOption(d),a=yield*k.fork(r.scope,`sequential`),o={...r,scope:a},c=yield*S.make(),l=yield*J(e,t,n).pipe(C.provideService(d,{reportError:e=>S.fail(c,e).pipe(C.asVoid)}),C.provideService(s,o),C.provideService(k.Scope,a)),u=t?.parentNode??null;if(t===null||t===l||u===null)return console.error(`[weft] hydrate: boundary at ${n} adopted an empty extent; live failure recovery is not installed for it.`),l;let p=R(),m=document.createComment(h(p)),g=document.createComment(f(p));return u.insertBefore(m,t),l===null?u.appendChild(g):u.insertBefore(g,l),yield*C.forkIn(Ae(e,c,a,i,m,g),r.scope),l}let r=t,i=r.textContent??``,a=yield*C.gen(function*(){let t=yield*C.try({try:()=>JSON.parse(i),catch:e=>e}),n=y(e.children)[t.index];if(n===void 0)return null;let r=yield*ie.decodeUnknownEffect(n.errorSchema)(t.error);return e.match(b.fail(r))}).pipe(C.catch(e=>(console.error(`[weft] hydrate: boundary failure payload at ${n} failed to decode; cannot replay.`,e),C.succeed(null))));if(a===null)return yield*Q(`replayable boundary failure`,`undecodable failure payload`,n);let o=yield*q(a,r.nextSibling,n);return r.remove(),o})}function st(e,t,n,r){return C.gen(function*(){let i=yield*j.make(n),a=yield*j.make(!1),o=yield*j.make(D.none()),s=D.match(r,{onNone:()=>C.void,onSome:n=>C.gen(function*(){(yield*j.get(a))||(yield*j.set(a,!0),yield*C.gen(function*(){let r=yield*C.exit(n.call(e,t()));w.isSuccess(r)?(yield*j.set(i,r.value),yield*j.set(o,D.none())):yield*j.set(o,D.some(b.squash(r.cause)))}).pipe(C.ensuring(j.set(a,!1))))})});return{value:fe.make({get:j.get(i),changes:j.changes(i)}),refetch:s,pending:fe.make({get:j.get(a),changes:j.changes(a)}),error:fe.make({get:j.get(o),changes:j.changes(o)})}})}function ct(e,t,n){return C.gen(function*(){if(t===null||t.nodeType!==Y||t.tagName!==`SCRIPT`||t.getAttribute(`type`)!==`application/json`)return yield*Q(`server boundary payload <script type="application/json">`,Z(t),n);if(t.hasAttribute(`data-weft-boundary-failure`))return yield*Q(`server boundary success payload <script type="application/json">`,`boundary failure payload`,n);let r=t,i=r.textContent??``,a=yield*C.try({try:()=>JSON.parse(i),catch:e=>e}).pipe(C.flatMap(t=>ie.decodeUnknownEffect(e.successSchema)(t)),C.catch(e=>(console.error(`[weft] hydrate: server boundary payload at ${n} failed to decode; cannot replay.`,e),Q(`decodable server boundary payload`,`undecodable payload`,n)))),o=yield*C.serviceOption(ae),s=yield*st(e.tag,e.payload,a,o),c=yield*q(e.render(s),r.nextSibling,n);return r.remove(),c})}function lt(e,t,n,r){return C.gen(function*(){if(n===null||n.nodeType!==Y)return yield*Q(`<${e}>`,Z(n),r);let i=n;return i.tagName.toLowerCase()===e.toLowerCase()?(yield*z(i,t),yield*J(t,i.firstChild,`${r} > ${e}`),i.nextSibling):yield*Q(`<${e}>`,Z(n),r)})}function J(e,t,n){return C.gen(function*(){let r=`children`in e?e.children:void 0;if(r===void 0)return t;let i=Array.isArray(r)?r:[r],a=t,o=0;for(let e of i)a=yield*q(e,a,`${n}[${o}]`),o++;return a})}function ut(e,t,n){return C.gen(function*(){let r=yield*s,{of:a,by:o,render:c}=e;if(t===null||t.nodeType!==X)return yield*Q(`list region start marker`,Z(t),n);let l=t,u=i(l);if(u===null||u.kind!==`start`)return yield*Q(`list region start marker`,Z(t),n);let f=gt(l);if(f===null)return yield*Q(`list region end marker`,`unterminated region starting at ${JSON.stringify(l.data)}`,n);let p=dt(l,f),m=yield*k.fork(r.scope,`sequential`),h=yield*C.serviceOption(d),g=yield*C.context(),_=de.changes(a),v={records:T.empty(),order:[]},y=!0,b=tt(r.hydrationReady),x=yield*r.loom.register({label:`hydrate:list-${u.id} (${n})`,scope:m,boundary:h,reportUnhandled:r.reportUnhandled,onFirstCommit:b,onDiscard:b,commit:e=>C.gen(function*(){let t=Array.from(e);y?(y=!1,v=yield*ft(t,o,c,p,m,l,f,r,n)):v=yield*qe(t,o,c,v,m,f,r)}).pipe(C.provideService(s,r),C.provideService(k.Scope,m),C.provide(g))}),S=M(A.runForEach(_,x.write),C.ensuring(C.suspend(()=>x.everWritten()?C.void:b)));r.hydrationReady!==void 0&&(yield*r.hydrationReady.register);let w=yield*V(S,m,`hydrate:list-${u.id} (${n})`,r.reportUnhandled);return x.attachPumpFiber(w),f.nextSibling})}function dt(e,t){let n=[],r=e.nextSibling;for(;r!==null&&r!==t;){let e=r.nodeType===X?g(r):null;if(e===null||e.kind!==`start`){r=r.nextSibling;continue}let i=r,a=[],o=0,s=null,c=i.nextSibling;for(;c!==null&&c!==t;){if(c.nodeType===X){let e=g(c);if(e!==null)if(e.kind===`start`)o++;else if(o===0){s=c;break}else o--}a.push(c),c=c.nextSibling}if(s===null)break;n.push({startMarker:i,endMarker:s,nodes:a}),r=s.nextSibling}return n}function ft(e,t,n,r,i,a,o,s,c){return C.gen(function*(){let l=yield*Ke(e,t);if(l.length!==r.length)return console.error(`[weft] hydrate: list region at ${c} had ${r.length} server item(s) but the first emission has ${l.length}; rebuilding.`),K(a,o),yield*qe(e,t,n,{records:T.empty(),order:[]},i,o,s);let u=[];for(let t=0;t<e.length;t++){let a=yield*pt(l[t],e[t],t,n,r[t],i,s,c);u.push(a)}let d=T.empty();for(let e of u)d=T.set(d,e.key,e);return{records:d,order:l}})}function pt(e,t,n,r,i,a,o,c){return C.gen(function*(){let l=yield*k.fork(a,`sequential`),u={...o,scope:l},d=r(t,n),f=yield*q(d,i.startMarker.nextSibling,`${c}<item>`).pipe(C.provideService(s,u),C.provideService(k.Scope,l),C.map(e=>e===i.endMarker?null:`adopted item content did not align with its end marker`),C.catchTag(`HydrationMismatchError`,e=>C.succeed(`expected ${e.expected}, found ${e.actual} at ${e.path}`)));if(f===null)return{key:e,scope:l,startMarker:i.startMarker,endMarker:i.endMarker,nodes:i.nodes};console.error(`[weft] hydrate: list item at ${c} diverged from server output (${f}); patching.`),yield*k.close(l,w.void);let p=yield*k.fork(a,`sequential`),m={...o,scope:p};K(i.startMarker,i.endMarker);let h=yield*U(d).pipe(C.provideService(s,m),C.provideService(k.Scope,p)),g=h===null?[]:Array.isArray(h)?h:[h],_=i.endMarker.parentNode;if(_!==null)for(let e of g)_.insertBefore(e,i.endMarker);return{key:e,scope:p,startMarker:i.startMarker,endMarker:i.endMarker,nodes:g}})}const Y=1,mt=3,X=8;function ht(e,t){let n=document.createTreeWalker(e,128),r=t.current;for(let e=n.nextNode();e!==null;e=n.nextNode()){let t=e,n=i(t)??u(t)??g(t);n!==null&&n.id>r&&(r=n.id)}t.current=r}function gt(e){let t=0,n=e.nextSibling;for(;n!==null;){if(n.nodeType===8){let e=i(n);if(e!==null)if(e.kind===`start`)t++;else if(t===0)return n;else t--}n=n.nextSibling}return null}function Z(e){if(e===null)return`end of children`;switch(e.nodeType){case 1:return`<${e.tagName.toLowerCase()}>`;case 3:return`text ${JSON.stringify(e.data)}`;case 8:return`comment ${JSON.stringify(e.data)}`;default:return`node(type ${e.nodeType})`}}function Q(e,t,n){return C.fail(new c({expected:e,actual:t,path:n}))}var _t=e({TypeId:()=>vt,dispose:()=>Ot,errors:()=>Dt,hydrate:()=>Et,make:()=>wt,mount:()=>Tt});const vt=Symbol.for(`@weftui/dom/WeftApp`),yt=new WeakMap;function $(e){let t=yt.get(e);if(t===void 0)throw Error(`Expected a WeftApp created by WeftApp.make`);return t}function bt(e,t){return C.gen(function*(){e.subscribers===0&&(yield*M(C.logError(t.cause),C.annotateLogs(`weft.region`,t.region))),yield*re.publish(e.hub,t)})}function xt(e){return C.suspend(()=>$(e).disposed?C.die(Error(`Cannot mount on a disposed WeftApp`)):e.runtime.contextEffect)}function St(e,t){return C.gen(function*(){let n=$(e),r=yield*k.fork(n.appScope,`sequential`);yield*ye(n.loom,n.appScope);let i=!1,a={element:t,unmount:()=>C.suspend(()=>i?C.void:(i=!0,k.close(r,w.void))),awaitCommit:n.loom.awaitCommit,commitGeneration:n.loom.commitGeneration};return{context:{runtime:e.runtime,scope:r,rootScope:r,loom:n.loom,streamIdCounter:{current:0},reportUnhandled:(e,t)=>bt(n,{cause:e,region:t,root:a})},handle:a,rootScope:r}})}function Ct(e,t){let n=ne.make(e??te.empty,t),r=C.runSync(re.unbounded()),i={[vt]:vt,runtime:n};return yt.set(i,{appScope:k.makeUnsafe(`sequential`),hub:r,loom:ve(),subscribers:0,disposed:!1}),i}const wt=Ct,Tt=(e,t,n)=>C.gen(function*(){let r=yield*xt(e),{context:i,handle:a,rootScope:o}=yield*St(e,n);n.innerHTML=``;let c=yield*M(U(t),C.setContext(M(r,x.add(s,i),x.add(k.Scope,o))),C.tapError(()=>k.close(o,w.void)));if(c!==null)if(Array.isArray(c))for(let e of c)n.appendChild(e);else n.appendChild(c);return a});function Et(e,t,n){return C.gen(function*(){let r=yield*xt(e),{context:i,handle:a,rootScope:o}=yield*St(e,n),c=yield*et(),l={...i,hydrationReady:c};return ht(n,l.streamIdCounter),yield*M(q(t,n.firstChild,`root`),C.setContext(M(r,x.add(s,l),x.add(k.Scope,o))),C.tapError(()=>k.close(o,w.void))),yield*c.settle,yield*c.awaitReady,a})}const Dt=e=>{let t=$(e);return A.unwrap(C.sync(()=>(t.subscribers++,M(A.fromPubSub(t.hub),A.ensuring(C.sync(()=>{t.subscribers--}))))))},Ot=e=>C.suspend(()=>{let t=$(e);return t.disposed?C.void:(t.disposed=!0,M(k.close(t.appScope,w.void),C.andThen(e.runtime.disposeEffect),C.andThen(re.shutdown(t.hub))))});export{_t as WeftApp};
@@ -1,4 +1,4 @@
1
- import { Cause, Context, Effect, ManagedRuntime, Scope } from "effect";
1
+ import { Cause, Context, Effect, Fiber, ManagedRuntime, Option, Scope } from "effect";
2
2
  //#region src/data.d.ts
3
3
  declare const UnsupportedNodeTypeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
4
4
  readonly _tag: "UnsupportedNodeTypeError";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as UnsupportedNodeTypeError, n as RenderError, r as StreamSubscriptionError, t as HydrationMismatchError } from "./data-C88W1AwU.js";
1
+ import { i as UnsupportedNodeTypeError, n as RenderError, r as StreamSubscriptionError, t as HydrationMismatchError } from "./data-DeNpcBZh.js";
2
2
  import { Effect, Option, Stream, SubscriptionRef } from "effect";
3
3
  import { NoPropValue, Source, Subscribable } from "@weftui/core";
4
4
  declare namespace props_d_exports {
@@ -40,15 +40,28 @@ An unhandled failure re-raises to the **nearest enclosing** boundary; if none ca
40
40
 
41
41
  ### Post-mount failures with no enclosing boundary
42
42
 
43
- The routing above describes what happens while a node is being built. Once mounted, a reactive region (an attribute, child, or list stream, or a hydrated equivalent) keeps running for the lifetime of its scope. It can still fail later: a `Stream` backing a `Boundary.rpc` resource might raise `RouterNotFound` after a client-side navigation. If a `BoundaryContext` encloses the region, the failure routes to it exactly as above, and the boundary's fallback swaps in.
43
+ The routing above describes what happens while a node is being built. Once mounted, a reactive region keeps running for the lifetime of its scope: an attribute, a child, a list stream, or a hydrated equivalent. It can still fail later, e.g. a `Boundary.rpc` resource's refetch stream raising after a client-side navigation.
44
44
 
45
- If no boundary encloses it, there is nothing to swap to. Weft does not synthesize one. The region's DOM keeps its last rendered content, and a watcher fiber (forked into the same scope alongside the subscription itself) observes its exit directly.
45
+ If a boundary encloses the region, the failure routes to it exactly as above and its fallback swaps in. If none does, there is nothing to swap to. Weft does not synthesize one: the region's DOM keeps its last rendered content, and a watcher fiber (forked alongside the subscription itself) observes the exit instead.
46
46
 
47
- When that exit is a failure whose cause is not interruption-only, Weft reports it explicitly via `Effect.logError(exit.cause)`. The log is annotated with `weft.region` to identify the failing region by kind and identity (e.g. `attribute:class`, `child:stream-3`, `list:stream-2`, `hydrate:stream-1 (/products/42)`). This fires for typed failures and defects alike, in both dev and prod, exactly once per failing region, at the `"Error"` level. Interruption (the ordinary case of unmount tearing down the region's scope) is never reported; only genuine failures are.
47
+ An exit whose cause is not interruption-only publishes an `UnhandledError` (`cause`, `region`, `root`) to the app's unhandled-error hub, exposed as `WeftApp.errors(app)`. `region` names the failing spot: `attribute:class`, `child:stream-3`, or `boundary:outermost` for a failure that escapes even the outermost boundary. Subscribe to observe every occurrence yourself:
48
48
 
49
- This is deliberate. Rather than leave the failure to whatever the Effect runtime would do with an unobserved fiber exit, Weft observes and logs it itself. Visibility is therefore controlled by the same knobs any Effect program uses: `References.MinimumLogLevel` (provided via `Effect.provideService`) to filter it, or a custom `Logger` to route it elsewhere.
49
+ ```typescript
50
+ import { WeftApp } from "@weftui/dom/client";
51
+ import { Effect, Stream } from "effect";
52
+
53
+ Effect.runFork(
54
+ Stream.runForEach(WeftApp.errors(app), (error) =>
55
+ Effect.log(`unhandled in ${error.region}`, error.cause),
56
+ ),
57
+ );
58
+ ```
50
59
 
51
- A stream that can fail and has no enclosing boundary is a stream whose failures you've chosen not to route into the UI. The log is what tells you that decision has consequences at runtime.
60
+ With zero subscribers, each unhandled error instead runs a default `Effect.logError(cause)` annotated with `weft.region`, exactly once per occurrence, in dev and prod alike. Subscribing suppresses that fallback for as long as at least one subscriber stays attached.
61
+
62
+ This is deliberate: rather than leave an unobserved fiber exit to the runtime, Weft always surfaces it, either to your subscriber or to the log. Interruption (ordinary unmount teardown) is never published or logged; only genuine failures are.
63
+
64
+ A stream that can fail with no enclosing boundary is a stream whose failures you've chosen not to route into the UI. `WeftApp.errors` (and the log fallback) is what tells you that decision has consequences at runtime. Full contract: [`WeftApp.errors` / `UnhandledError`](https://weftui.dev/docs/reference/dom#weftapperrors).
52
65
 
53
66
  ## Suspense boundaries
54
67
 
@@ -100,11 +113,28 @@ Its channel behavior is also distinct. The rpc's typed `error` schema joins the
100
113
 
101
114
  The unifying idea: failure, async pending state, and server data are not three separate subsystems bolted onto the renderer. They are three **boundary nodes** in the one tree, each intercepting a different thing flowing through it. Each has channel behavior you can read off its type.
102
115
 
103
- That is why they nest freely. A `Boundary.catchTag` can wrap a `Boundary.rpc` to catch its typed failure. A `Boundary.suspend` can wrap async siblings that themselves contain rpc boundaries.
116
+ That is why they nest freely. A `Boundary.catchTag` can wrap a `Boundary.rpc` to catch its typed failure, and a `Boundary.suspend` can wrap async siblings that themselves contain rpc boundaries:
117
+
118
+ ```typescript
119
+ import { Boundary, h, Subscribable } from "@weftui/core";
120
+ import { Stream } from "effect";
121
+
122
+ Boundary.catchTag({ tag: "StockRpcError", fallback: () => h.p("Couldn't load stock.") }, [
123
+ Boundary.rpc(
124
+ GetStock,
125
+ () => ({ id: productId }),
126
+ (resource) =>
127
+ h.span([Stream.map(Subscribable.changes(resource.value), (s) => String(s.units))]),
128
+ ),
129
+ ]);
130
+ ```
131
+
132
+ Each layer only sees the channel its own kind produces: `catchTag` narrows `E`, `Boundary.rpc` widens it by the rpc's error schema. Neither cares how the other renders.
104
133
 
105
134
  ## See also
106
135
 
107
136
  - [The Rendering Model](https://weftui.dev/docs/explanation/rendering-model): why a boundary is just a node in a static tree
108
137
  - [`Boundary` API reference](https://weftui.dev/docs/reference/core#boundary-namespace): every variant's signature and channel algebra
138
+ - [`WeftApp.errors` / `UnhandledError`](https://weftui.dev/docs/reference/dom#weftapperrors): the unhandled-error hub for post-mount failures with no enclosing boundary
109
139
  - [Load Data with RPC](https://weftui.dev/docs/how-to/load-data-with-rpc): the full `Boundary.rpc` walkthrough and its four lifecycles
110
140
  - [Render on the Server](https://weftui.dev/docs/how-to/render-on-the-server): how suspense and rpc boundaries stream and hydrate
@@ -7,7 +7,14 @@ description: How h, h.fragment, and Component.gen / Component.make work; why Nod
7
7
 
8
8
  # The Combinator API
9
9
 
10
- Weft builds UI trees by calling builder functions. Because component return types stay as generic `Effect.Effect<ElementDescriptor, E, R>`, the error channel (`E`) and requirements channel (`R`) propagate through the entire tree: visible to the type checker, satisfiable at the mount boundary.
10
+ Weft builds UI trees by calling builder functions, not by writing markup. There is no JSX runtime and no `h(Component)` overload: a component is a plain function you call, and its result goes straight into the tree.
11
+
12
+ ```typescript
13
+ // No JSX, no deferred element. Header/Main/Footer already ran; these are Nodes.
14
+ const tree = h.div({ class: "app" }, [Header(), Main(), Footer()]);
15
+ ```
16
+
17
+ Because a component's return type stays a concrete `Effect.Effect<ElementDescriptor, E, R>`, its error channel (`E`) and requirement channel (`R`) propagate through the whole tree. Both are visible to the type checker and satisfiable exactly once, at the mount boundary.
11
18
 
12
19
  JSX collapses every component's return type to an opaque `JSX.Element`, erasing both channels. The combinator API exists specifically to keep them intact.
13
20
 
@@ -110,7 +117,7 @@ const TableRow = ({ user }: { user: User }) =>
110
117
 
111
118
  ## Custom components with `Component.gen` / `Component.make`
112
119
 
113
- Plain functions work fine for simple components, but the `Component` factories provide type-level wiring so the caller's reactive prop types contribute their `E`/`R` to the returned node. Pick `Component.make` for a plain-function body and `Component.gen` for a generator body (when you need `yield*` to set up local state or pull from services).
120
+ Plain functions work fine for simple components. The `Component` factories add type-level wiring: the caller's actual reactive prop types contribute their `E`/`R` to the node returned at that call site, not just the types you wrote in the signature. Pick `Component.make` for a plain-function body, `Component.gen` for a generator body (when you need `yield*` for local state or a service).
114
121
 
115
122
  ```typescript
116
123
  import { Component, h } from "@weftui/core";
@@ -132,30 +139,29 @@ declare const labelStream: Stream.Stream<string, never, I18nService>;
132
139
  const btn = Button({ label: labelStream });
133
140
  ```
134
141
 
135
- Components also accept an optional `children` argument, either as `readonly Renderable[]` or as a `(input) => readonly Renderable[]` function (render-prop pattern). `E`/`R` from children, including the array returned by a function-children call, accumulate on the resulting node.
142
+ Components also accept an optional `children` argument: either `readonly Renderable[]`, or a `(input) => readonly Renderable[]` function for the render-prop pattern. Either way, the children's `E`/`R` accumulate onto the resulting node, including the array a function-children call returns.
136
143
 
137
- Without `Component`, a plain function's return type is fixed at definition time and does not reflect the caller's reactive prop types.
144
+ A plain function without `Component` has its return type fixed at definition time. It reflects only the prop types you wrote, never a specific caller's reactive prop types.
138
145
 
139
- See [component-authoring.md](https://weftui.dev/docs/how-to/author-components) for a full walkthrough.
146
+ See [Author Components](https://weftui.dev/docs/how-to/author-components) for a full walkthrough.
140
147
 
141
- ## Suspense boundaries
148
+ ## Boundaries accumulate channels too
142
149
 
143
- `Boundary.suspend` wraps async children and shows a fallback until all of them have emitted their first value:
150
+ `Boundary.suspend`, `Boundary.catch`, and the rest of the `Boundary` namespace are Nodes, not a separate concept. A boundary wraps children and its own type is `Node<ChildrenE, ChildrenR>`, so the same accumulation rules apply:
144
151
 
145
152
  ```typescript
146
153
  import { Boundary, h } from "@weftui/core";
147
154
 
155
+ // Node<ChildrenE, ChildrenR>: transparent to E/R, like a plain h.* parent
148
156
  Boundary.suspend({ fallback: h.div({ class: "spinner" }, "Loading...") }, [
149
157
  AsyncCard({ id: 1 }),
150
158
  AsyncCard({ id: 2 }),
151
159
  ]);
152
160
  ```
153
161
 
154
- The fallback is replaced atomically: either all children are visible or none are. This prevents partial flicker when multiple async siblings resolve at different times. The boundary's node type is `Node<ChildrenE, ChildrenR>`: the children's `E`/`R` channels accumulate onto it, exactly as they would for a plain `h.*` parent.
155
-
156
- On the server, `renderToStreamHydratable` emits the fallback inline and appends patch scripts as children resolve. On the client, `hydrate` sees through `Boundary.suspend` boundaries and adopts the already-resolved DOM directly.
162
+ A boundary changes _when_ and _whether_ its children's output reaches the DOM, not what its type carries. `Boundary.catchTag` is the one exception: it removes the matched tag from `E`, since that's the failure it discharges.
157
163
 
158
- `Boundary.suspend` is one of the boundary combinators. See the [core reference](https://weftui.dev/docs/reference/core#boundarysuspend) for the full `Boundary.*` surface, including the failure-catch variants and `Boundary.rpc`.
164
+ See [Boundaries and Suspense](https://weftui.dev/docs/explanation/boundaries-and-suspense) for what each boundary variant does, and the [core reference](https://weftui.dev/docs/reference/core#boundary-namespace) for the full `Boundary.*` surface.
159
165
 
160
166
  ## See also
161
167
 
@@ -7,16 +7,14 @@ description: The Source<A, E, R> vocabulary; Stream, Effect, and Subscribable as
7
7
 
8
8
  # Reactive Primitives
9
9
 
10
- The unified `Source` vocabulary lets static values, Effects, Streams, and Subscribables be used interchangeably. Props, children, and style values all accept the same type.
10
+ Weft accepts a `Source` for any prop value, any child, and any style value: one vocabulary, four kinds, used interchangeably wherever reactivity is supported.
11
11
 
12
- Weft accepts a `Source` for prop values and children. Any of these is valid wherever reactivity is supported:
13
-
14
- - A plain static value (`string`, `number`, `boolean`, ...)
15
- - An `Effect.Effect<A, E, R>`: runs once and resolves to a value
16
- - A `Stream.Stream<A, E, R>`: each emission replaces the previous value
17
- - A `Subscribable<A, E, R>`: like a hot stream; already has a "current value"
18
-
19
- The `Source<A, E, R>` type captures this union:
12
+ | Kind | Behavior |
13
+ | --------------------------------------------------------- | ----------------------------------------- |
14
+ | a plain static value (`string`, `number`, `boolean`, ...) | set once, never updates |
15
+ | `Effect.Effect<A, E, R>` | runs once, resolves to a value |
16
+ | `Stream.Stream<A, E, R>` | each emission replaces the previous value |
17
+ | `Subscribable<A, E, R>` | a hot stream: already has a current value |
20
18
 
21
19
  ```typescript
22
20
  type Source<A, E, R> = A | Effect.Effect<A, E, R> | Stream.Stream<A, E, R> | Subscribable<A, E, R>;
@@ -139,13 +137,42 @@ h.div({
139
137
  });
140
138
  ```
141
139
 
140
+ ## Latest-value-wins conflation
141
+
142
+ Every reactive region and prop is drained by one shared commit scheduler, the
143
+ Loom (see [The Rendering Model](https://weftui.dev/docs/explanation/rendering-model#the-loom-one-scheduler-per-app-committing-asynchronously)).
144
+ When a source emits faster than the DOM commits, the Loom conflates the burst:
145
+ it keeps only the newest value per region and skips the intermediate ones.
146
+
147
+ ```typescript
148
+ const ticks = Stream.range(0, 999); // publishes far faster than the DOM commits
149
+
150
+ h.span([ticks]); // the span settles on 999; 0 through 998 may never render
151
+ ```
152
+
153
+ The final DOM state always reflects the newest value; nothing is lost
154
+ permanently. What is skipped are the values in between, by design: this is
155
+ what keeps a fast-publishing source from piling up unbounded DOM work.
156
+
157
+ Code that must observe every emission, not just the settled one (an audit
158
+ log, a counter that sums each tick), should consume the stream directly
159
+ instead of relying on what lands in the DOM:
160
+
161
+ ```typescript
162
+ yield * Stream.runForEach(ticks, (n) => Effect.sync(() => total.push(n)));
163
+ ```
164
+
142
165
  ## NoPropValue
143
166
 
144
- When a `Stream` prop ends before emitting, the renderer raises a `NoPropValue` tagged error. This carries an optional `key` field identifying which prop triggered it:
167
+ A finite `Stream` prop can end without ever emitting, e.g. `Stream.empty` or `Stream.take(0, stream)`. When it does, the renderer raises a `NoPropValue` tagged error carrying an optional `key` that identifies the prop:
168
+
169
+ ```typescript
170
+ h.span([Stream.empty]); // completes without emitting: raises NoPropValue
171
+ ```
172
+
173
+ `Effect.catchTag` matches by the string tag, so handling it at the mount boundary needs no `NoPropValue` import:
145
174
 
146
175
  ```typescript
147
- // Handle at the mount boundary if needed. `Effect.catchTag` matches the error
148
- // by its string tag, so no `NoPropValue` import is required here.
149
176
  pipe(
150
177
  WeftApp.mount(app, App(), root),
151
178
  Effect.catchTag("NoPropValue", (e) =>
@@ -154,7 +181,7 @@ pipe(
154
181
  );
155
182
  ```
156
183
 
157
- In practice you only encounter `NoPropValue` when a finite `Stream` prop ends before emitting (e.g., `Stream.empty` or `Stream.take(0, stream)`). Most usage with `SubscriptionRef.changes` or infinite streams never raises it.
184
+ `SubscriptionRef.changes` and other infinite streams always emit before completing, so most usage never raises it.
158
185
 
159
186
  ## See also
160
187
 
@@ -37,12 +37,22 @@ When a stream emits, only the DOM at _that_ point updates. Nothing above it re-r
37
37
 
38
38
  ## Streams drive all updates
39
39
 
40
- There is no `setState`, no render-triggering scheduler, no "re-render this component." A region of the DOM is live **if and only if** a stream is woven into it. To make something update, you thread a stream through it; to keep something static, you pass a plain value.
40
+ There is no `setState`, no "re-render this component," no vdom diff. A region of the DOM is live **if and only if** a stream is woven into it. To make something update, you thread a stream through it; to keep something static, you pass a plain value.
41
41
 
42
- The renderer subscribes to each woven stream and patches its target in place on every emission. It reuses the existing DOM node and patches text and attributes rather than recreating elements, so identity, focus, and typed input survive an update.
42
+ The renderer reuses the existing DOM node and patches text and attributes in place rather than recreating elements, so identity, focus, and typed input survive an update. Updates stay local: a stream woven at one point never touches an untouched sibling or re-runs a parent.
43
43
 
44
44
  This also fixes the update _shape_. Because the structure is fixed, an update is always "new value into a known hole," never "reconcile these two trees." Even list rendering, where the number of children genuinely varies, is expressed as a keyed region ([`List.each`](https://weftui.dev/docs/how-to/render-keyed-lists)). It reconciles by key rather than by structural diff.
45
45
 
46
+ ## The Loom: one scheduler per app, committing asynchronously
47
+
48
+ Every woven stream feeds one shared scheduler per `WeftApp`: the **Loom**. It keeps one latest-value slot per reactive region or prop and commits changes to the DOM in passes.
49
+
50
+ The name follows the metaphor: individual streams spin as fast as they like, like threads paid out from a bobbin. The loom only ever weaves the newest state of each thread into the fabric, one pass at a time. A region that receives several values before its next commit collapses to the last one: intermediate emissions are conflated, never committed. This bounds DOM work no matter how fast a source publishes.
51
+
52
+ Commits are asynchronous: they happen on the scheduler's own turn, not synchronously with the write. `RootHandle.awaitCommit` is the acknowledgement. It resolves once everything pending at call time has either committed or been discarded, returning the commit generation. See the [`RootHandle` reference](https://weftui.dev/docs/reference/dom#roothandle) for its exact semantics.
53
+
54
+ None of this changes what you write. You still thread a `Stream`, `Effect`, or `Subscribable` through a prop or child; the Loom is an implementation detail of how those emissions reach the DOM. Code that must observe every intermediate value, not just the settled one, should consume the stream directly instead of relying on what lands in the DOM (see [Reactive Primitives](https://weftui.dev/docs/explanation/reactive-primitives#latest-value-wins-conflation)).
55
+
46
56
  ## One tree, two sides, hydrate in place
47
57
 
48
58
  The same component tree renders on the server and the client:
@@ -56,6 +66,7 @@ Because the same `Node<E, R>` describes both passes, there is nothing to keep in
56
66
 
57
67
  - **No diff cost.** Updates are O(changed value), not O(tree). There is no reconciliation pass to pay for.
58
68
  - **Local reasoning.** A stream woven at one point cannot affect another. What is reactive is exactly what you made reactive.
69
+ - **Bounded commit work.** The Loom conflates bursts to one commit per region, so a fast-publishing source cannot outrun the DOM.
59
70
  - **Type-honest edges.** The app node's `E`/`R` is the whole app's error and dependency surface, checked at compile time and discharged once at the edge.
60
71
  - **Flash-free SSR by construction.** Hydration adopts rather than replaces, because the tree is identical on both sides.
61
72
 
@@ -65,3 +76,4 @@ Because the same `Node<E, R>` describes both passes, there is nothing to keep in
65
76
  - [Reactive Primitives](https://weftui.dev/docs/explanation/reactive-primitives): the stream-shaped values you weave through the tree
66
77
  - [Boundaries and Suspense](https://weftui.dev/docs/explanation/boundaries-and-suspense): how failure and async are modeled as nodes in the same tree
67
78
  - [Render on the Server](https://weftui.dev/docs/how-to/render-on-the-server): the server/client split and `hydrate`
79
+ - [`@weftui/dom` reference](https://weftui.dev/docs/reference/dom#roothandle): `RootHandle.awaitCommit` and `commitGeneration`
@@ -329,10 +329,7 @@ import { RouterApp, RouterLive } from "@weftui/router/client";
329
329
  import { Effect } from "effect";
330
330
  import { App } from "./app";
331
331
 
332
- const root = document.getElementById("root");
333
- if (root === null) {
334
- throw new Error("#root not found");
335
- }
332
+ const root = document.getElementById("root")!;
336
333
 
337
334
  const app = WeftApp.make(RouterLive(App));
338
335
  void Effect.runPromise(WeftApp.mount(app, RouterApp(App), root));
@@ -485,10 +482,7 @@ import { RouterApp, RouterLive } from "@weftui/router/client";
485
482
  import { Effect } from "effect";
486
483
  import { App } from "./app";
487
484
 
488
- const root = document.getElementById("root");
489
- if (root === null) {
490
- throw new Error("#root not found");
491
- }
485
+ const root = document.getElementById("root")!;
492
486
 
493
487
  const app = WeftApp.make(RouterLive(App));
494
488
  void Effect.runPromise(WeftApp.hydrate(app, RouterApp(App), root));
@@ -557,7 +551,7 @@ Option.isSome(httpApiClient); // true under RouterLive, false under RouterServer
557
551
  | `RouterNotFound` | `notFound()`, or no route matched | `Boundary.catchTag(…)` (or the app-level `notFound` page) |
558
552
  | `RouterParamsError` | `Router.params` / `Router.query` on a missing/invalid key or no match | `Boundary.catchTag(…)` |
559
553
 
560
- Both are modeled as `Schema.TaggedErrorClass`, so they encode/decode across the wire the same way `Boundary.rpc` replays typed failures.
554
+ Both are modeled as `Schema.TaggedError`, so they encode/decode across the wire the same way `Boundary.rpc` replays typed failures.
561
555
 
562
556
  Recover locally by wrapping just the subtree that can fail, rather than relying on the app-level `notFound` page for everything:
563
557