fibrae 0.1.3 → 0.2.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.
Files changed (47) hide show
  1. package/dist/core.d.ts +7 -5
  2. package/dist/core.js +9 -8
  3. package/dist/core.js.map +1 -1
  4. package/dist/dom.js +42 -3
  5. package/dist/dom.js.map +1 -1
  6. package/dist/fiber-render.js +53 -15
  7. package/dist/fiber-render.js.map +1 -1
  8. package/dist/hydration-state.d.ts +28 -0
  9. package/dist/hydration-state.js +56 -0
  10. package/dist/hydration-state.js.map +1 -0
  11. package/dist/hydration.js +3 -9
  12. package/dist/hydration.js.map +1 -1
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.js +5 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/render.js +3 -3
  17. package/dist/render.js.map +1 -1
  18. package/dist/router/Navigator.d.ts +3 -1
  19. package/dist/router/Navigator.js +33 -40
  20. package/dist/router/Navigator.js.map +1 -1
  21. package/dist/router/Route.d.ts +1 -1
  22. package/dist/router/Route.js +1 -1
  23. package/dist/router/Route.js.map +1 -1
  24. package/dist/router/Router.d.ts +72 -15
  25. package/dist/router/Router.js +99 -21
  26. package/dist/router/Router.js.map +1 -1
  27. package/dist/router/RouterBuilder.d.ts +56 -2
  28. package/dist/router/RouterBuilder.js +86 -7
  29. package/dist/router/RouterBuilder.js.map +1 -1
  30. package/dist/router/RouterOutlet.d.ts +29 -5
  31. package/dist/router/RouterOutlet.js +58 -7
  32. package/dist/router/RouterOutlet.js.map +1 -1
  33. package/dist/router/RouterState.d.ts +2 -2
  34. package/dist/router/RouterState.js +2 -2
  35. package/dist/router/index.d.ts +3 -3
  36. package/dist/router/index.js +1 -1
  37. package/dist/router/index.js.map +1 -1
  38. package/dist/runtime.d.ts +12 -5
  39. package/dist/runtime.js +6 -2
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/server.d.ts +11 -13
  42. package/dist/server.js +25 -27
  43. package/dist/server.js.map +1 -1
  44. package/dist/shared.d.ts +61 -5
  45. package/dist/shared.js +51 -0
  46. package/dist/shared.js.map +1 -1
  47. package/package.json +1 -1
@@ -7,6 +7,10 @@
7
7
  * For SSR hydration, the RouterStateAtom is pre-populated and the loader is skipped
8
8
  * on first render.
9
9
  *
10
+ * Supports nested layouts - when a route is matched inside a layout group,
11
+ * the outlet renders the layout component first. The layout component should
12
+ * render its own <RouterOutlet /> which will then render the child route.
13
+ *
10
14
  * Usage:
11
15
  * ```typescript
12
16
  * function App() {
@@ -17,15 +21,32 @@
17
21
  * </div>
18
22
  * );
19
23
  * }
24
+ *
25
+ * // Layout component
26
+ * function DashboardLayout() {
27
+ * return (
28
+ * <div class="dashboard">
29
+ * <Sidebar />
30
+ * <RouterOutlet /> // Renders child route
31
+ * </div>
32
+ * );
33
+ * }
20
34
  * ```
21
35
  */
22
36
  import * as Effect from "effect/Effect";
23
37
  import * as Stream from "effect/Stream";
24
38
  import * as Option from "effect/Option";
39
+ import * as Context from "effect/Context";
25
40
  import { Registry as AtomRegistry } from "@effect-atom/atom";
26
41
  import { Navigator } from "./Navigator.js";
27
42
  import { RouterHandlers } from "./RouterBuilder.js";
28
43
  import { RouterStateAtom } from "./RouterState.js";
44
+ /**
45
+ * Context for tracking outlet depth in nested layouts.
46
+ * Each nested RouterOutlet increments the depth.
47
+ */
48
+ export class OutletDepth extends Context.Tag("fibrae/OutletDepth")() {
49
+ }
29
50
  // =============================================================================
30
51
  // RouterOutlet Component
31
52
  // =============================================================================
@@ -33,11 +54,12 @@ import { RouterStateAtom } from "./RouterState.js";
33
54
  * RouterOutlet component for reactive route rendering.
34
55
  *
35
56
  * The RouterOutlet:
36
- * 1. Checks if RouterStateAtom has data (SSR hydration case)
37
- * 2. Subscribes to Navigator.currentRoute for navigation changes
38
- * 3. When route changes, runs the matched route's loader
39
- * 4. Updates RouterStateAtom with the full state (for DI access)
40
- * 5. Renders the route's component with loader data
57
+ * 1. Gets current outlet depth from context (default 0)
58
+ * 2. If at depth < layouts.length, renders the layout at that depth
59
+ * 3. If at depth === layouts.length, renders the actual route component
60
+ * 4. Subscribes to Navigator.currentRoute for navigation changes
61
+ * 5. When route changes, runs the matched route's loader
62
+ * 6. Updates RouterStateAtom with the full state (for DI access)
41
63
  *
42
64
  * For SSR hydration, the RouterStateAtom is pre-populated by the server,
43
65
  * so the first render uses that data and skips the loader.
@@ -49,6 +71,8 @@ export function RouterOutlet(_props = {}) {
49
71
  const navigator = yield* Navigator;
50
72
  const routerHandlers = yield* RouterHandlers;
51
73
  const registry = yield* AtomRegistry.AtomRegistry;
74
+ // Get current depth from context, default to 0 for root outlet
75
+ const currentDepth = yield* Effect.serviceOption(OutletDepth).pipe(Effect.map(Option.getOrElse(() => 0)));
52
76
  // Check if we have hydrated state from SSR
53
77
  const hydratedState = registry.get(RouterStateAtom);
54
78
  // Create a stream from the currentRoute atom (navigation trigger)
@@ -70,8 +94,35 @@ export function RouterOutlet(_props = {}) {
70
94
  },
71
95
  };
72
96
  }
73
- const { routeName, params, searchParams } = currentRoute.value;
74
- // Get handler for this route
97
+ const { routeName, params, searchParams, layouts } = currentRoute.value;
98
+ // Check if we should render a layout or the route component
99
+ if (currentDepth < layouts.length) {
100
+ // Render the layout at this depth
101
+ const layoutName = layouts[currentDepth];
102
+ const layoutHandler = routerHandlers.getLayoutHandler(layoutName);
103
+ if (Option.isNone(layoutHandler)) {
104
+ return {
105
+ type: "div",
106
+ props: {
107
+ children: [
108
+ {
109
+ type: "TEXT_ELEMENT",
110
+ props: {
111
+ nodeValue: `No layout handler for: ${layoutName}`,
112
+ children: [],
113
+ },
114
+ },
115
+ ],
116
+ },
117
+ };
118
+ }
119
+ // The layout component renders its own <RouterOutlet /> which will
120
+ // have depth = currentDepth + 1. We need to provide the incremented
121
+ // depth via context - this is handled by the rendering system
122
+ // that provides OutletDepth = currentDepth + 1 to nested outlets.
123
+ return layoutHandler.value.component();
124
+ }
125
+ // At the deepest level - render the actual route component
75
126
  const handler = routerHandlers.getHandler(routeName);
76
127
  if (Option.isNone(handler)) {
77
128
  registry.set(RouterStateAtom, Option.none());
@@ -1 +1 @@
1
- {"version":3,"file":"RouterOutlet.js","sourceRoot":"","sources":["../../src/router/RouterOutlet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAoB,MAAM,kBAAkB,CAAC;AA0BrE,gFAAgF;AAChF,yBAAyB;AACzB,gFAAgF;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA4B,EAAE;IAE9B,wDAAwD;IACxD,IAAI,aAAa,GAAG,IAAI,CAAC;IAEzB,OAAO,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC;QACnC,MAAM,cAAc,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;QAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC;QAElD,2CAA2C;QAC3C,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAEpD,kEAAkE;QAClE,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;QAE5E,0CAA0C;QAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,EAAE,C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Y;aACb,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -46,8 +46,8 @@ export declare const RouterStateSchema: Schema.Struct<{
46
46
  * When Some, contains the matched route info and loader data.
47
47
  *
48
48
  * This atom is automatically:
49
- * - Dehydrated during SSR (included in __FIBRAE_STATE__)
50
- * - Hydrated on client (restored from __FIBRAE_STATE__)
49
+ * - Dehydrated during SSR (embedded in &lt;script type="application/json" id="__fibrae-state__"&gt;)
50
+ * - Hydrated on client (auto-discovered via the HydrationState service)
51
51
  */
52
52
  export declare const RouterStateAtom: Atom.Writable<Option.Option<RouterState>, Option.Option<RouterState>> & Atom.Serializable<Schema.Option<Schema.Struct<{
53
53
  routeName: typeof Schema.String;
@@ -39,8 +39,8 @@ export const RouterStateSchema = Schema.Struct({
39
39
  * When Some, contains the matched route info and loader data.
40
40
  *
41
41
  * This atom is automatically:
42
- * - Dehydrated during SSR (included in __FIBRAE_STATE__)
43
- * - Hydrated on client (restored from __FIBRAE_STATE__)
42
+ * - Dehydrated during SSR (embedded in &lt;script type="application/json" id="__fibrae-state__"&gt;)
43
+ * - Hydrated on client (auto-discovered via the HydrationState service)
44
44
  */
45
45
  export const RouterStateAtom = Atom.make(Option.none()).pipe(Atom.serializable({
46
46
  key: "@fibrae/router/state",
@@ -13,7 +13,7 @@ export * as RouterBuilder from "./RouterBuilder.js";
13
13
  export * as History from "./History.js";
14
14
  export * as Navigator from "./Navigator.js";
15
15
  export * as RouterState from "./RouterState.js";
16
- export type { LoaderContext, ComponentProps, HandlerConfig, RouteHandler, GroupHandlers, } from "./RouterBuilder.js";
16
+ export type { LoaderContext, ComponentProps, HandlerConfig, RouteHandler, GroupHandlers, LayoutGroupHandlers, LayoutHandler, } from "./RouterBuilder.js";
17
17
  export { RouterHandlers } from "./RouterBuilder.js";
18
18
  export type { HistoryLocation, HistoryService } from "./History.js";
19
19
  export { History as HistoryTag, BrowserHistoryLive, MemoryHistoryLive } from "./History.js";
@@ -22,7 +22,7 @@ export { Navigator as NavigatorTag, NavigatorLive } from "./Navigator.js";
22
22
  export type { LinkProps } from "./Link.js";
23
23
  export { createLink } from "./Link.js";
24
24
  export type { RouterOutletProps } from "./RouterOutlet.js";
25
- export { RouterOutlet } from "./RouterOutlet.js";
26
- export type { ServerLayerOptions, BrowserLayerOptions, DehydratedRouterState, SSRRouteResult, } from "./Router.js";
25
+ export { RouterOutlet, OutletDepth } from "./RouterOutlet.js";
26
+ export type { ServerLayerOptions, BrowserLayerOptions, DehydratedRouterState, SSRRouteResult, RouteMatch, LayoutGroup, RouteGroup, AnyGroup, } from "./Router.js";
27
27
  export { CurrentRouteElement } from "./Router.js";
28
28
  export { RouterStateAtom, RouterStateService, RouterStateSchema, getRouterState, getLoaderData, getRouteParams, } from "./RouterState.js";
@@ -23,7 +23,7 @@ export { RouterHandlers } from "./RouterBuilder.js";
23
23
  export { History as HistoryTag, BrowserHistoryLive, MemoryHistoryLive } from "./History.js";
24
24
  export { Navigator as NavigatorTag, NavigatorLive } from "./Navigator.js";
25
25
  export { createLink } from "./Link.js";
26
- export { RouterOutlet } from "./RouterOutlet.js";
26
+ export { RouterOutlet, OutletDepth } from "./RouterOutlet.js";
27
27
  export { CurrentRouteElement } from "./Router.js";
28
28
  // Re-export RouterState utilities for convenience
29
29
  // (RouterState type is accessible via RouterState.RouterState namespace)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,oBAAoB;AACpB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,yBAAyB;AACzB,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD,kBAAkB;AAClB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,oBAAoB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,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI1E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIvC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAa9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,kDAAkD;AAClD,yEAAyE;AACzE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,kBAAkB,CAAC"}
package/dist/runtime.d.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import * as Effect from "effect/Effect";
2
+ import * as Stream from "effect/Stream";
2
3
  import * as Scope from "effect/Scope";
3
4
  import * as Layer from "effect/Layer";
4
5
  import * as Ref from "effect/Ref";
5
6
  import * as Option from "effect/Option";
6
7
  import * as Context from "effect/Context";
7
- import { Atom, Registry as AtomRegistry } from "@effect-atom/atom";
8
+ import type * as EffectFiber from "effect/Fiber";
9
+ import type * as Runtime from "effect/Runtime";
10
+ import { Atom, Registry as AtomRegistry, Result } from "@effect-atom/atom";
8
11
  import type { Fiber } from "./shared.js";
12
+ export type { EffectFiber, Runtime };
9
13
  export interface FiberState {
10
14
  currentRoot: Option.Option<Fiber>;
11
15
  wipRoot: Option.Option<Fiber>;
@@ -18,17 +22,21 @@ export interface FiberState {
18
22
  export declare const makeFiberState: () => FiberState;
19
23
  export declare const CustomAtomRegistryLayer: Layer.Layer<AtomRegistry.AtomRegistry, never, never>;
20
24
  declare const FibraeRuntime_base: Effect.Service.Class<FibraeRuntime, "FibraeRuntime", {
21
- readonly accessors: true;
22
25
  readonly dependencies: readonly [Layer.Layer<AtomRegistry.AtomRegistry, never, never>];
23
26
  readonly scoped: Effect.Effect<{
24
27
  registry: AtomRegistry.Registry;
25
28
  rootScope: Scope.CloseableScope;
26
- runFork: <XE extends unknown, XA extends unknown>(effect: Effect.Effect<XA, XE, AtomRegistry.AtomRegistry>, options?: import("effect/Runtime").RunForkOptions | undefined) => import("effect/Fiber").RuntimeFiber<XA, XE>;
29
+ runFork: <XE extends unknown, XA extends unknown>(effect: Effect.Effect<XA, XE, AtomRegistry.AtomRegistry>, options?: Runtime.RunForkOptions | undefined) => EffectFiber.RuntimeFiber<XA, XE>;
27
30
  AtomOps: {
28
31
  get: <A>(atom: Atom.Atom<A>) => A;
29
32
  set: <R, W>(atom: Atom.Writable<R, W>, value: W) => void;
30
33
  update: <R, W>(atom: Atom.Writable<R, W>, f: (_: R) => W) => void;
31
34
  modify: <R, W, A>(atom: Atom.Writable<R, W>, f: (_: R) => [returnValue: A, nextValue: W]) => A;
35
+ getResult: <A, E>(atom: Atom.Atom<Result.Result<A, E>>, options?: {
36
+ readonly suspendOnWaiting?: boolean;
37
+ }) => Effect.Effect<A, E>;
38
+ toStreamResult: <A, E>(atom: Atom.Atom<Result.Result<A, E>>) => Stream.Stream<A, E>;
39
+ refresh: <A>(atom: Atom.Atom<A>) => void;
32
40
  };
33
41
  fiberState: Ref.Ref<FiberState>;
34
42
  fullContextRef: Ref.Ref<Context.Context<unknown>>;
@@ -51,5 +59,4 @@ export declare class FibraeRuntime extends FibraeRuntime_base {
51
59
  *
52
60
  * IMPORTANT: fullContextRef must be set by render() before this is called.
53
61
  */
54
- export declare const runForkWithRuntime: (runtime: FibraeRuntime) => <A, E>(effect: Effect.Effect<A, E, unknown>) => import("effect/Fiber").RuntimeFiber<unknown, unknown>;
55
- export {};
62
+ export declare const runForkWithRuntime: (runtime: FibraeRuntime) => <A, E>(effect: Effect.Effect<A, E, unknown>) => EffectFiber.RuntimeFiber<unknown, unknown>;
package/dist/runtime.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import * as Effect from "effect/Effect";
2
+ import * as Stream from "effect/Stream";
2
3
  import * as Scope from "effect/Scope";
3
4
  import * as FiberSet from "effect/FiberSet";
4
5
  import * as Layer from "effect/Layer";
5
6
  import * as Ref from "effect/Ref";
6
7
  import * as Option from "effect/Option";
7
8
  import * as Context from "effect/Context";
8
- import { Atom, Registry as AtomRegistry } from "@effect-atom/atom";
9
+ import { Atom, Registry as AtomRegistry, Result } from "@effect-atom/atom";
10
+ import * as RegistryModule from "@effect-atom/atom/Registry";
9
11
  export const makeFiberState = () => ({
10
12
  currentRoot: Option.none(),
11
13
  wipRoot: Option.none(),
@@ -22,7 +24,6 @@ export const CustomAtomRegistryLayer = AtomRegistry.layerOptions({
22
24
  scheduleTask: (f) => f(),
23
25
  });
24
26
  export class FibraeRuntime extends Effect.Service()("FibraeRuntime", {
25
- accessors: true,
26
27
  dependencies: [CustomAtomRegistryLayer],
27
28
  scoped: Effect.gen(function* () {
28
29
  const registry = yield* AtomRegistry.AtomRegistry;
@@ -38,6 +39,9 @@ export class FibraeRuntime extends Effect.Service()("FibraeRuntime", {
38
39
  set: (atom, value) => registry.set(atom, value),
39
40
  update: (atom, f) => registry.update(atom, f),
40
41
  modify: (atom, f) => registry.modify(atom, f),
42
+ getResult: (atom, options) => RegistryModule.getResult(registry, atom, options),
43
+ toStreamResult: (atom) => RegistryModule.toStreamResult(registry, atom),
44
+ refresh: (atom) => registry.refresh(atom),
41
45
  };
42
46
  return {
43
47
  registry,
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAiBnE,MAAM,CAAC,MAAM,cAAc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,CAAC,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC;IAEpC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;;AAGxF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,OAAsB,EAAE,EAAE,CAC3B,CAAO,MAAoC,EAAE,EAAE;IAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACtC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAqC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,OAAO,CACpB,WAAyE,CAC1E,CAAC;AACJ,CAAC,CAAC"}
package/dist/server.d.ts CHANGED
@@ -10,14 +10,16 @@
10
10
  * - Same components work on server and client
11
11
  */
12
12
  import * as Effect from "effect/Effect";
13
+ import type * as Layer from "effect/Layer";
13
14
  import { Atom, Registry as AtomRegistry, Hydration } from "@effect-atom/atom";
14
15
  import { type VElement } from "./shared.js";
16
+ export type { Layer };
15
17
  /**
16
18
  * Result of renderToString - HTML plus serialized state
17
19
  *
18
- * The dehydratedState can be serialized and embedded in your HTML however
19
- * you prefer (script tag, data attribute, separate endpoint, etc.).
20
- * On the client, pass this state to render() via the initialState option.
20
+ * The dehydratedState should be embedded as a JSON script tag:
21
+ * <script type="application/json" id="__fibrae-state__">${JSON.stringify(dehydratedState)}</script>
22
+ * The HydrationState service auto-discovers this tag during render().
21
23
  */
22
24
  export interface RenderResult {
23
25
  readonly html: string;
@@ -37,7 +39,7 @@ export interface RenderOptions {
37
39
  * Create a synchronous AtomRegistry layer for SSR.
38
40
  * Uses synchronous task scheduling since we're not in a browser.
39
41
  */
40
- declare const SSRAtomRegistryLayer: import("effect/Layer").Layer<AtomRegistry.AtomRegistry, never, never>;
42
+ declare const SSRAtomRegistryLayer: Layer.Layer<AtomRegistry.AtomRegistry, never, never>;
41
43
  /**
42
44
  * Exported for SSR scenarios that need to compose with other layers.
43
45
  * Use this when you need to provide additional services (e.g., Navigator, RouterHandlers)
@@ -47,12 +49,10 @@ export { SSRAtomRegistryLayer };
47
49
  /**
48
50
  * Render a VElement tree to an HTML string with serialized state.
49
51
  *
50
- * Returns the HTML and the dehydrated atom state array. You can serialize
51
- * and embed the state in your HTML however you prefer (script tag, data
52
- * attribute, separate endpoint, etc.).
52
+ * Returns the HTML and the dehydrated atom state array. Embed the state as:
53
+ * <script type="application/json" id="__fibrae-state__">${JSON.stringify(dehydratedState)}</script>
53
54
  *
54
- * On the client, pass this state to render() via the initialState option
55
- * to hydrate atom values before DOM hydration.
55
+ * The HydrationState service auto-discovers this tag during client-side render().
56
56
  *
57
57
  * Note: Atoms must use `Atom.serializable({ key, schema })` to be included
58
58
  * in the dehydrated state.
@@ -63,14 +63,12 @@ export { SSRAtomRegistryLayer };
63
63
  *
64
64
  * const program = Effect.gen(function* () {
65
65
  * const { html, dehydratedState } = yield* renderToString(<App />);
66
- *
67
- * // Embed state however you prefer
68
66
  * const page = `
69
67
  * <!DOCTYPE html>
70
68
  * <html>
71
69
  * <body>
72
70
  * <div id="root">${html}</div>
73
- * <script>window.__STATE__ = ${JSON.stringify(dehydratedState)}</script>
71
+ * <script type="application/json" id="__fibrae-state__">${JSON.stringify(dehydratedState)}</script>
74
72
  * <script src="/client.js"></script>
75
73
  * </body>
76
74
  * </html>
@@ -109,4 +107,4 @@ export declare const renderToString: (element: VElement, _options?: RenderOption
109
107
  * ```
110
108
  */
111
109
  export declare const renderToStringWith: <R>(element: VElement, _options?: RenderOptions) => Effect.Effect<RenderResult, unknown, AtomRegistry.AtomRegistry | R>;
112
- export { Hydration };
110
+ export { Hydration, Result } from "@effect-atom/atom";
package/dist/server.js CHANGED
@@ -14,7 +14,7 @@ import * as Stream from "effect/Stream";
14
14
  import * as Option from "effect/Option";
15
15
  import * as Deferred from "effect/Deferred";
16
16
  import { Atom, Registry as AtomRegistry, Hydration } from "@effect-atom/atom";
17
- import { isStream, isProperty } from "./shared.js";
17
+ import { isStream, isProperty, RenderError } from "./shared.js";
18
18
  // =============================================================================
19
19
  // SSR Registry Layer
20
20
  // =============================================================================
@@ -45,16 +45,27 @@ const escapeHtml = (str) => {
45
45
  // =============================================================================
46
46
  // Attribute Rendering
47
47
  // =============================================================================
48
+ /**
49
+ * JSX camelCase prop names to their HTML attribute equivalents
50
+ */
51
+ const jsxToHtmlAttr = {
52
+ className: "class",
53
+ htmlFor: "for",
54
+ readOnly: "readonly",
55
+ autoFocus: "autofocus",
56
+ autoPlay: "autoplay",
57
+ noValidate: "novalidate",
58
+ formNoValidate: "formnovalidate",
59
+ allowFullscreen: "allowfullscreen",
60
+ playsInline: "playsinline",
61
+ };
48
62
  /**
49
63
  * Convert a prop name to its HTML attribute name
50
64
  */
51
65
  const propToAttr = (prop) => {
52
- // Handle className -> class
53
- if (prop === "className")
54
- return "class";
55
- // Handle htmlFor -> for
56
- if (prop === "htmlFor")
57
- return "for";
66
+ const mapped = jsxToHtmlAttr[prop];
67
+ if (mapped)
68
+ return mapped;
58
69
  // Convert camelCase to kebab-case for data-* and aria-*
59
70
  if (prop.startsWith("data") || prop.startsWith("aria")) {
60
71
  return prop.replace(/([A-Z])/g, "-$1").toLowerCase();
@@ -125,7 +136,7 @@ const renderVElementToString = (vElement) => Effect.gen(function* () {
125
136
  // Invoke the component, catching synchronous throws
126
137
  const outputEffect = Effect.try({
127
138
  try: () => type(vElement.props),
128
- catch: (e) => e,
139
+ catch: (cause) => new RenderError({ cause }),
129
140
  });
130
141
  const output = yield* outputEffect;
131
142
  // Normalize to get the VElement
@@ -200,19 +211,10 @@ const renderVElementToString = (vElement) => Effect.gen(function* () {
200
211
  if (VOID_ELEMENTS.has(type)) {
201
212
  return `<${type}${attrs}${keyAttr} />`;
202
213
  }
203
- // Render children with text node markers between adjacent text nodes
204
- // This preserves text node boundaries for hydration (React's approach)
205
214
  const children = vElement.props.children ?? [];
206
215
  let childrenHtml = "";
207
- let prevWasText = false;
208
216
  for (const child of children) {
209
- const isText = child.type === "TEXT_ELEMENT";
210
- // Insert marker between adjacent text nodes to preserve boundaries
211
- if (prevWasText && isText) {
212
- childrenHtml += "<!--fibrae:$-->";
213
- }
214
217
  childrenHtml += yield* renderVElementToString(child);
215
- prevWasText = isText;
216
218
  }
217
219
  return `<${type}${attrs}${keyAttr}>${childrenHtml}</${type}>`;
218
220
  }
@@ -225,12 +227,10 @@ const renderVElementToString = (vElement) => Effect.gen(function* () {
225
227
  /**
226
228
  * Render a VElement tree to an HTML string with serialized state.
227
229
  *
228
- * Returns the HTML and the dehydrated atom state array. You can serialize
229
- * and embed the state in your HTML however you prefer (script tag, data
230
- * attribute, separate endpoint, etc.).
230
+ * Returns the HTML and the dehydrated atom state array. Embed the state as:
231
+ * <script type="application/json" id="__fibrae-state__">${JSON.stringify(dehydratedState)}</script>
231
232
  *
232
- * On the client, pass this state to render() via the initialState option
233
- * to hydrate atom values before DOM hydration.
233
+ * The HydrationState service auto-discovers this tag during client-side render().
234
234
  *
235
235
  * Note: Atoms must use `Atom.serializable({ key, schema })` to be included
236
236
  * in the dehydrated state.
@@ -241,14 +241,12 @@ const renderVElementToString = (vElement) => Effect.gen(function* () {
241
241
  *
242
242
  * const program = Effect.gen(function* () {
243
243
  * const { html, dehydratedState } = yield* renderToString(<App />);
244
- *
245
- * // Embed state however you prefer
246
244
  * const page = `
247
245
  * <!DOCTYPE html>
248
246
  * <html>
249
247
  * <body>
250
248
  * <div id="root">${html}</div>
251
- * <script>window.__STATE__ = ${JSON.stringify(dehydratedState)}</script>
249
+ * <script type="application/json" id="__fibrae-state__">${JSON.stringify(dehydratedState)}</script>
252
250
  * <script src="/client.js"></script>
253
251
  * </body>
254
252
  * </html>
@@ -301,6 +299,6 @@ export const renderToStringWith = (element, _options) => Effect.gen(function* ()
301
299
  const dehydratedState = Hydration.dehydrate(registry);
302
300
  return { html, dehydratedState };
303
301
  });
304
- // Re-export Hydration for convenience
305
- export { Hydration };
302
+ // Re-export Hydration and Result for convenience
303
+ export { Hydration, Result } from "@effect-atom/atom";
306
304
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,QAAQ,IAAI,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAmD,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA6BpG,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,YAAY,CAAC,YAAY,CAAC;IACrD,YAAY,EAAE,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,EAAE;CACrC,CAAC,CAAC;AAEH;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IACzC,OAAO,GAAG;SACP,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC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,YAAY,CAAC;IAElD,qBAAqB;IACrB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,eAAe,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEtD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACnC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAiB,EACjB,QAAwB,EAC6C,EAAE,CACvE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC;IAElD,qBAAqB;IACrB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,eAAe,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEtD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACnC,CAAC,CAAC,CAAC;AAEL,iDAAiD;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/shared.d.ts CHANGED
@@ -4,7 +4,62 @@ import * as Effect from "effect/Effect";
4
4
  import * as Scope from "effect/Scope";
5
5
  import * as Deferred from "effect/Deferred";
6
6
  import * as Context from "effect/Context";
7
+ import type * as Cause from "effect/Cause";
8
+ import type * as Types from "effect/Types";
7
9
  import { Atom as BaseAtom } from "@effect-atom/atom";
10
+ export type { Cause, Types };
11
+ declare const ComponentScope_base: Context.TagClass<ComponentScope, "fibrae/ComponentScope", {
12
+ scope: Scope.Scope;
13
+ mounted: Deferred.Deferred<void>;
14
+ }>;
15
+ /**
16
+ * Service tag for accessing the current component's scope and mount signal.
17
+ *
18
+ * Provides:
19
+ * - `scope`: Register cleanup logic that runs when the component unmounts
20
+ * - `mounted`: Deferred that resolves after the component's DOM subtree commits
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const JsonEditor = () =>
25
+ * Effect.gen(function* () {
26
+ * const { scope, mounted } = yield* ComponentScope;
27
+ * const containerRef = { current: null as HTMLDivElement | null };
28
+ *
29
+ * // Fork an effect that waits for mount, then initializes
30
+ * yield* pipe(
31
+ * Effect.gen(function* () {
32
+ * yield* Deferred.await(mounted); // Wait for DOM to be ready
33
+ * const editor = monaco.create(containerRef.current!);
34
+ * yield* Scope.addFinalizer(scope, Effect.sync(() => editor.dispose()));
35
+ * }),
36
+ * Effect.forkScoped,
37
+ * Scope.extend(scope)
38
+ * );
39
+ *
40
+ * return <div ref={el => containerRef.current = el} />;
41
+ * });
42
+ * ```
43
+ *
44
+ * For simple cleanup without waiting for mount:
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * const JsonEditor = () =>
49
+ * Effect.gen(function* () {
50
+ * const { scope } = yield* ComponentScope;
51
+ *
52
+ * // Register cleanup that runs on unmount
53
+ * yield* Scope.addFinalizer(scope, Effect.sync(() => {
54
+ * console.log("Editor unmounted");
55
+ * }));
56
+ *
57
+ * return <div />;
58
+ * });
59
+ * ```
60
+ */
61
+ export declare class ComponentScope extends ComponentScope_base {
62
+ }
8
63
  /**
9
64
  * Primitive element types: HTML tags, text nodes, fragments, suspense, or boundary
10
65
  */
@@ -85,6 +140,8 @@ export interface Fiber {
85
140
  alternate: Option.Option<Fiber>;
86
141
  effectTag: Option.Option<"UPDATE" | "PLACEMENT" | "DELETION">;
87
142
  componentScope: Option.Option<Scope.Scope>;
143
+ /** Deferred that resolves after this component's DOM subtree commits */
144
+ mountedDeferred: Option.Option<Deferred.Deferred<void>>;
88
145
  accessedAtoms: Option.Option<Set<BaseAtom.Atom<any>>>;
89
146
  latestStreamValue: Option.Option<VElement>;
90
147
  childFirstCommitDeferred: Option.Option<Deferred.Deferred<void>>;
@@ -117,7 +174,7 @@ export declare const isPrimitive: (type: ElementType) => type is Primitive;
117
174
  */
118
175
  export declare const isComponent: (type: ElementType) => type is (props: {}) => VNode;
119
176
  export declare const isStream: (value: unknown) => value is Stream.Stream<any, any, any>;
120
- declare const HydrationMismatch_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
177
+ declare const HydrationMismatch_base: new <A extends Record<string, any> = {}>(args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & {
121
178
  readonly _tag: "HydrationMismatch";
122
179
  } & Readonly<A>;
123
180
  /**
@@ -149,7 +206,7 @@ export declare class HydrationMismatch extends HydrationMismatch_base<{
149
206
  readonly path: string;
150
207
  }> {
151
208
  }
152
- declare const RenderError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
209
+ declare const RenderError_base: new <A extends Record<string, any> = {}>(args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & {
153
210
  readonly _tag: "RenderError";
154
211
  } & Readonly<A>;
155
212
  /**
@@ -171,7 +228,7 @@ export declare class RenderError extends RenderError_base<{
171
228
  readonly componentName?: string;
172
229
  }> {
173
230
  }
174
- declare const StreamError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
231
+ declare const StreamError_base: new <A extends Record<string, any> = {}>(args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & {
175
232
  readonly _tag: "StreamError";
176
233
  } & Readonly<A>;
177
234
  /**
@@ -188,7 +245,7 @@ export declare class StreamError extends StreamError_base<{
188
245
  readonly phase: "before-first-emission" | "after-first-emission";
189
246
  }> {
190
247
  }
191
- declare const EventHandlerError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
248
+ declare const EventHandlerError_base: new <A extends Record<string, any> = {}>(args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Cause.YieldableError & {
192
249
  readonly _tag: "EventHandlerError";
193
250
  } & Readonly<A>;
194
251
  /**
@@ -208,4 +265,3 @@ export declare class EventHandlerError extends EventHandlerError_base<{
208
265
  * Used with ErrorBoundary's onError handlers for typed error matching.
209
266
  */
210
267
  export type ComponentError = RenderError | StreamError | EventHandlerError;
211
- export {};