@atom.io/spa 0.0.3 → 0.0.5

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 (120) hide show
  1. package/README.md +202 -138
  2. package/README.mdx +62 -26
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-client.d.ts +3 -2
  5. package/dist/astro-client.d.ts.map +1 -1
  6. package/dist/astro-client.js +11 -10
  7. package/dist/astro-client.js.map +1 -1
  8. package/dist/astro-resumability-client.d.ts +10 -0
  9. package/dist/astro-resumability-client.d.ts.map +1 -0
  10. package/dist/astro-resumability-client.js +29 -0
  11. package/dist/astro-resumability-client.js.map +1 -0
  12. package/dist/astro-resumability-server.d.ts +3 -0
  13. package/dist/astro-resumability-server.d.ts.map +1 -0
  14. package/dist/astro-resumability-server.js +7 -0
  15. package/dist/astro-resumability-server.js.map +1 -0
  16. package/dist/astro-server.d.ts +3 -2
  17. package/dist/astro-server.d.ts.map +1 -1
  18. package/dist/astro-server.js +28 -9
  19. package/dist/astro-server.js.map +1 -1
  20. package/dist/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  21. package/dist/astro-shared-83hxw7-M.js.map +1 -0
  22. package/dist/{astro-shared-BkWvVZWZ.d.ts → astro-shared-DHIpjNIG.d.ts} +2 -2
  23. package/dist/{astro-shared-BkWvVZWZ.d.ts.map → astro-shared-DHIpjNIG.d.ts.map} +1 -1
  24. package/dist/astro.d.ts +1 -1
  25. package/dist/astro.js +5 -7
  26. package/dist/astro.js.map +1 -1
  27. package/dist/{capabilities-CFP-HIuY.d.ts → capabilities-BCtBG-ni.d.ts} +19 -14
  28. package/dist/capabilities-BCtBG-ni.d.ts.map +1 -0
  29. package/dist/client.min.js +1 -1
  30. package/dist/{core-DCmqLZQP.js → core-DjFJ0aIJ.js} +31 -23
  31. package/dist/core-DjFJ0aIJ.js.map +1 -0
  32. package/dist/development/astro-client.js +11 -10
  33. package/dist/development/astro-client.js.map +1 -1
  34. package/dist/development/astro-resumability-client.js +29 -0
  35. package/dist/development/astro-resumability-client.js.map +1 -0
  36. package/dist/development/astro-resumability-server.js +7 -0
  37. package/dist/development/astro-resumability-server.js.map +1 -0
  38. package/dist/development/astro-server.js +28 -9
  39. package/dist/development/astro-server.js.map +1 -1
  40. package/dist/development/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  41. package/dist/development/astro-shared-83hxw7-M.js.map +1 -0
  42. package/dist/development/astro.js +5 -7
  43. package/dist/development/astro.js.map +1 -1
  44. package/dist/development/{core-p9vciX9C.js → core-DxPiKryn.js} +31 -23
  45. package/dist/development/core-DxPiKryn.js.map +1 -0
  46. package/dist/development/{dom-Ci1XvbVJ.js → dom-BytVV6Rp.js} +44 -12
  47. package/dist/development/dom-BytVV6Rp.js.map +1 -0
  48. package/dist/development/index.js +4 -4
  49. package/dist/development/jsx-runtime.js.map +1 -1
  50. package/dist/development/konva.js +1 -1
  51. package/dist/development/konva.js.map +1 -1
  52. package/dist/development/motion.js +1 -1
  53. package/dist/development/renderer.js +1 -1
  54. package/dist/development/renderer.js.map +1 -1
  55. package/dist/development/server-renderer-CUQXh9oF.js +90 -0
  56. package/dist/development/server-renderer-CUQXh9oF.js.map +1 -0
  57. package/dist/development/server.js +2 -83
  58. package/dist/development/server.js.map +1 -1
  59. package/dist/{src-DCQa6qxs.js → development/src-WSHJxR9b.js} +4 -4
  60. package/dist/development/src-WSHJxR9b.js.map +1 -0
  61. package/dist/development/three.js +1 -1
  62. package/dist/development/three.js.map +1 -1
  63. package/dist/{dom-dHQM0O7Q.js → dom-B5OxgHkr.js} +44 -12
  64. package/dist/dom-B5OxgHkr.js.map +1 -0
  65. package/dist/{index-CJJXcKaw.d.ts → index-DufwkB6W.d.ts} +5 -5
  66. package/dist/{index-CJJXcKaw.d.ts.map → index-DufwkB6W.d.ts.map} +1 -1
  67. package/dist/index.d.ts +4 -4
  68. package/dist/index.js +4 -4
  69. package/dist/{jsx-runtime-CREZYKDC.d.ts → jsx-runtime-DMDVr7A5.d.ts} +7 -7
  70. package/dist/{jsx-runtime-CREZYKDC.d.ts.map → jsx-runtime-DMDVr7A5.d.ts.map} +1 -1
  71. package/dist/jsx-runtime.d.ts +1 -1
  72. package/dist/jsx-runtime.js.map +1 -1
  73. package/dist/konva.d.ts +16 -16
  74. package/dist/konva.js +1 -1
  75. package/dist/konva.js.map +1 -1
  76. package/dist/motion.d.ts +1 -1
  77. package/dist/motion.js +1 -1
  78. package/dist/renderer.d.ts +4 -4
  79. package/dist/renderer.d.ts.map +1 -1
  80. package/dist/renderer.js +1 -1
  81. package/dist/renderer.js.map +1 -1
  82. package/dist/server-renderer-DcU55e6s.js +90 -0
  83. package/dist/server-renderer-DcU55e6s.js.map +1 -0
  84. package/dist/server.d.ts +2 -2
  85. package/dist/server.d.ts.map +1 -1
  86. package/dist/server.js +2 -83
  87. package/dist/server.js.map +1 -1
  88. package/dist/size.json +16 -16
  89. package/dist/{development/src-DG0xjuS5.js → src-DWIqXCiz.js} +4 -4
  90. package/dist/src-DWIqXCiz.js.map +1 -0
  91. package/dist/three.d.ts +17 -17
  92. package/dist/three.js +1 -1
  93. package/dist/three.js.map +1 -1
  94. package/package.json +27 -11
  95. package/src/astro-client.ts +20 -7
  96. package/src/astro-resumability-client.ts +40 -0
  97. package/src/astro-resumability-server.ts +7 -0
  98. package/src/astro-server.ts +58 -19
  99. package/src/astro-shared.ts +5 -2
  100. package/src/astro.ts +11 -3
  101. package/src/core.ts +54 -49
  102. package/src/dom.ts +73 -39
  103. package/src/index.ts +4 -4
  104. package/src/jsx-runtime.ts +7 -6
  105. package/src/jsx-types.d.ts +2 -2
  106. package/src/konva.ts +3 -3
  107. package/src/renderer.ts +24 -18
  108. package/src/server-renderer.ts +162 -0
  109. package/src/server.ts +4 -153
  110. package/src/three.ts +4 -4
  111. package/src/use-loadable.ts +3 -3
  112. package/dist/astro-shared-BT45auwR.js.map +0 -1
  113. package/dist/capabilities-CFP-HIuY.d.ts.map +0 -1
  114. package/dist/core-DCmqLZQP.js.map +0 -1
  115. package/dist/development/astro-shared-BT45auwR.js.map +0 -1
  116. package/dist/development/core-p9vciX9C.js.map +0 -1
  117. package/dist/development/dom-Ci1XvbVJ.js.map +0 -1
  118. package/dist/development/src-DG0xjuS5.js.map +0 -1
  119. package/dist/dom-dHQM0O7Q.js.map +0 -1
  120. package/dist/src-DCQa6qxs.js.map +0 -1
package/README.mdx CHANGED
@@ -2,21 +2,27 @@ import { Tonnage } from "tonnage";
2
2
  import config from "./tonnage.config.ts";
3
3
  import StoreExample from "./exhibits/store.tsx" with { type: "code" };
4
4
  import Families from "./exhibits/families.tsx" with { type: "code" };
5
+ import TimelineExample from "./exhibits/timeline.tsx" with { type: "code" };
5
6
  import LoadableExample from "./exhibits/loadable.tsx" with { type: "code" };
6
7
  import Point from "./exhibits/point.tsx" with { type: "code" };
7
8
  import ViteConfig from "./exhibits/vite.config.ts" with { type: "code" };
8
9
  import Main from "./exhibits/main.tsx" with { type: "code" };
9
10
  import Types from "./exhibits/tsconfig.json" with { type: "code" };
10
11
  import AstroConfig from "./exhibits/astro.config.ts" with { type: "code" };
11
- import AsyncAstro from "./exhibits/async-astro.spa.tsx" with { type: "code" };
12
- import Counter from "./exhibits/Counter.spa.tsx" with { type: "code" };
12
+ import AsyncAstro from "./exhibits/async-astro.tsx" with { type: "code" };
13
+ import Counter from "./exhibits/Counter.tsx" with { type: "code" };
14
+ import CounterPage from "./exhibits/counter-page.astro" with { type: "code" };
15
+ import VitePage from "./exhibits/index.html" with { type: "code" };
16
+ import CreateAstroTemplate from "./exhibits/create-astro-template.sh" with {
17
+ type: "code",
18
+ };
13
19
  import Verify from "./exhibits/verify.sh" with { type: "code" };
14
- import KonvaExample from "./exhibits/konva.spa.tsx" with { type: "code" };
15
- import ThreeExample from "./exhibits/three.spa.tsx" with { type: "code" };
16
- import MotionPanel from "./exhibits/motion.spa.tsx" with { type: "code" };
20
+ import KonvaExample from "./exhibits/konva.tsx" with { type: "code" };
21
+ import ThreeExample from "./exhibits/three.tsx" with { type: "code" };
22
+ import MotionPanel from "./exhibits/motion.tsx" with { type: "code" };
17
23
  import MotionMain from "./exhibits/motion-main.tsx" with { type: "code" };
18
- import MotionExit from "./exhibits/motion-exit.spa.tsx" with { type: "code" };
19
- import MotionThree from "./exhibits/motion-three.spa.tsx" with { type: "code" };
24
+ import MotionExit from "./exhibits/motion-exit.tsx" with { type: "code" };
25
+ import MotionThree from "./exhibits/motion-three.tsx" with { type: "code" };
20
26
 
21
27
  <p align="center">
22
28
  <img src="https://raw.githubusercontent.com/jeremybanka/atom.io/main/apps/atom.io.fyi/public/spa/icon-512.png" alt="SPA logo" width="160" height="160" />
@@ -28,11 +34,33 @@ An experimental JSX framework whose state engine is atom.io. Components run once
28
34
 
29
35
  The npm package is named @atom.io/spa. Its browser runtime, Vite compiler, server renderer, and Astro integration are implemented here. It has no independent state primitive, effect API, React hook dispatcher, or compatibility layer.
30
36
 
37
+ ## Start with the Astro template
38
+
39
+ Use the [SPA + Astro SSR template](https://github.com/jeremybanka/atom.io/tree/main/templates/spa-astro-ssr) for a ready-to-run application with Astro islands, resumable initial data, SQLite, and tRPC:
40
+
41
+ <CreateAstroTemplate />
42
+
43
+ For manual setup, see the [Astro](https://atom.io.fyi/docs/spa/astro) and [Vite](https://atom.io.fyi/docs/spa/vite) integration guides on atom.io.fyi.
44
+
31
45
  ## A point, not two signals
32
46
 
33
47
  <Point />
34
48
 
35
- The point accessor returns the current object. Each JSX attribute reads its coordinate when evaluated. Both bindings depend on the point atom, and unchanged primitive results skip DOM writes. Reads during setup are snapshots; reads in event handlers are current and untracked. Shared derived state belongs in atom.io selectors.
49
+ Name the getter and setter after the atom: pointAtom uses getPoint and setPoint. The getPoint getter returns the current object. Each JSX attribute reads its coordinate when evaluated. Both bindings depend on the point atom, and unchanged primitive results skip DOM writes. Reads during setup are snapshots; reads in event handlers are current and untracked. Shared derived state belongs in atom.io selectors.
50
+
51
+ ## Astro
52
+
53
+ Register the Astro integration, which compiles .tsx and .jsx components by default:
54
+
55
+ <AstroConfig />
56
+
57
+ Create a counter component:
58
+
59
+ <Counter />
60
+
61
+ Import it into an Astro page and use client:load to make it interactive. Astro handles server rendering and browser hydration:
62
+
63
+ <CounterPage />
36
64
 
37
65
  ## Vite
38
66
 
@@ -42,18 +70,22 @@ Add @atom.io/spa and atom.io to the application's dependencies. The spa plugin i
42
70
 
43
71
  <Types />
44
72
 
73
+ Add a host element in index.html, then mount the same counter from main.tsx:
74
+
75
+ <VitePage />
76
+
45
77
  <Main />
46
78
 
47
79
  The development plugin keeps SPA and atom.io outside dependency prebundling so renderer entrypoints, component hooks, and stores share one runtime, including Astro adapter environments. It uses full page reloads. Components and render computations are synchronous. Modern browsers with ES2022 and DOM Range support are the target.
48
80
 
49
- ## Component API
81
+ ## Hooks
50
82
 
51
83
  | API | Contract |
52
84
  | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
53
85
  | useLoadable(token, fallback?) | Return a tracked accessor for loading, last-observed values, and handled errors. |
54
- | useValue(token) | Return a live accessor for an atom or selector, bound to this instance's store. |
86
+ | useGetter(token) | Return a live accessor for an atom or selector, bound to this instance's store. |
55
87
  | useSetter(token) | Return a stable atom.io writer. |
56
- | useTimeline(token) | Return an accessor for at, length, undo, redo, clear, and available grouped transaction controls. |
88
+ | useTimeline(token) | Return a stable object with getCursor/getLength readers, undo/redo/clear commands, and transaction-group controls. |
57
89
  | useTransaction(token) | Bind an atom.io transaction, preserving its arguments and result. |
58
90
  | useRef(token) | Return an attachment callback for a nullable element atom. Clear it only while this attachment still owns the reference. |
59
91
  | useId() | Allocate an instance-stable ID using the root's prefix. |
@@ -63,6 +95,10 @@ The development plugin keeps SPA and atom.io outside dependency prebundling so r
63
95
 
64
96
  Call setup helpers synchronously during component setup or owned mount callbacks. Capture their results for event handlers. Tokens are fixed for an instance; use an application key in a reactive child expression to replace a component when its token changes. Component props stay live when read through the props object; destructuring during setup takes a snapshot.
65
97
 
98
+ useTimeline returns a TimelineControls object whose methods can be destructured during setup. getCursor and getLength read the current cursor position and recorded checkpoint count; calls inside JSX subscribe the computation, while calls during setup or in event handlers are untracked. undo, redo, and clear are stable commands. history.getTransaction() is a tracked reader that returns an object with optional undo and redo callbacks for the adjacent transaction groups. At a cursor between transactions, both callbacks may be present and target different groups. A missing callback means no transaction group is available in that direction; the reader returns an empty object when neither is available. Calling a returned callback travels its captured group across participating timelines where it remains at the relevant history head, leaving diverged timelines unchanged. Use history.getTransaction().undo?.() or history.getTransaction().redo?.() to retrieve and invoke the current action together.
99
+
100
+ <TimelineExample />
101
+
66
102
  Arrays support keyed components and elements. Reordering preserves instances and nodes; removed ranges release subscriptions, events, refs, and cleanup callbacks. Application keys must be unique among siblings. Explicit keys are compared as strings; unkeyed positions occupy a separate namespace. Unkeyed arrays use positions. A key identifies a row in a reactive child collection; it is not an independent reactive binding.
67
103
 
68
104
  HTML and SVG use native DOM properties and attributes, plus className/htmlFor aliases. Events use onClick/onInput-style names, with Capture suffixes and onDoubleClick support. Styles are CSS strings. Mutable atom values still invalidate their consumers; project primitive fields for precise DOM writes. Refs attach once per element instance.
@@ -75,11 +111,11 @@ useStore returns the current root's atom.io RootStore directly. It is the same o
75
111
 
76
112
  <StoreExample />
77
113
 
78
- Capture the store during component setup or an owned onMount callback, then pass it to store-aware atom.io operations or integrations. Getting the store creates no subscription. Direct reads such as getFromStore do not participate in SPA's dependency tracking; useValue and useLoadable provide tracked reads. The returned object is a store, not a Silo or a new wrapper.
114
+ Capture the store during component setup or an owned onMount callback, then pass it to store-aware atom.io operations or integrations. Getting the store creates no subscription. Direct reads such as getFromStore do not participate in SPA's dependency tracking; useGetter and useLoadable provide tracked reads. The returned object is a store, not a Silo or a new wrapper.
79
115
 
80
116
  ## Families
81
117
 
82
- useValue, useSetter, useRef, and useTimeline accept a family token followed by its key. useLoadable accepts a family, key, and optional fallback. Keys retain their declared types, including tuples, numbers, booleans, and null. Members resolve in the component's store, so isolated roots can use the same family tokens independently.
118
+ useGetter, useSetter, useRef, and useTimeline accept a family token followed by its key. useLoadable accepts a family, key, and optional fallback. Keys retain their declared types, including tuples, numbers, booleans, and null. Members resolve in the component's store, so isolated roots can use the same family tokens independently.
83
119
 
84
120
  <Families />
85
121
 
@@ -99,23 +135,25 @@ Atom.io owns promise settlement and subscriptions. SPA adds no fetching, retries
99
135
 
100
136
  The client exports render and hydrate. Both accept a setup callback, a host Element, and optional store, idPrefix, and onError options, and return dispose and flush methods. Updates coalesce in a microtask; flush drains them synchronously. Dispose is idempotent and removes only owned nodes. Cleanup continues after individual cleanup failures and aggregates errors. A failed computation disposes its root; asynchronous update failures reach onError, while explicit flush failures throw.
101
137
 
102
- The separate server entrypoint exports renderToString with the same setup callback and store/ID options. Supply a request-specific store for SSR. Server rendering retains no subscriptions and runs owner cleanup. Hydration reuses matching server nodes and IDs, attaches events, and recreates subscriptions. It requires the same initial state, component structure, and valid HTML on both sides; mismatches throw rather than silently remounting. Use explicit tbody elements in tables. Controlled form properties are applied during hydration.
103
-
104
- The production build omits development diagnostics and invalid-input checks; the development export condition enables them. Pure render computations must not write state. Promise children, async components, portals, suspense, error boundaries, style objects, and automatic token-as-child bindings are outside this first implementation. Applications handle asynchronous data through atom.io state and synchronous conditional JSX.
138
+ The separate server entrypoint exports renderToString with the same setup callback and store/ID options. Supply a request-specific store for SSR. Server rendering retains no subscriptions and runs owner cleanup. Hydration reuses matching server nodes and IDs, attaches events, and recreates subscriptions. Match initial state, component structure, and valid HTML on both sides. A hydration mismatch produces one human-readable console warning per root in development and production, identifying the host and expected/found nodes. SPA repairs mismatched nodes, inserts missing nodes, and removes unexpected leftovers during the same hydration pass. Component setup and mount hooks run once, subscriptions remain active, and matching nodes are reused. Replaced nodes can lose focus, selection, or unsaved browser input; unaffected roots continue running. An explicit client idPrefix takes precedence when repairing mismatched root markers. Use explicit tbody elements in tables. Controlled form properties are applied during hydration.
105
139
 
106
- ## Astro
140
+ The production build omits development-only diagnostics and invalid-input checks; the development export condition enables them. Hydration recovery warnings remain available in all builds. Pure render computations must not write state. Promise children, async components, portals, suspense, error boundaries, style objects, and automatic token-as-child bindings are outside this first implementation. Applications handle asynchronous data through atom.io state and synchronous conditional JSX.
107
141
 
108
- The integration transforms .spa.tsx and .spa.jsx files by default, so another JSX renderer can coexist. Configure include to change this filter. Top-level functions containing JSX are branded by the compiler for renderer detection.
142
+ ## Astro state and data
109
143
 
110
- <AstroConfig />
144
+ The integration compiles .tsx and .jsx files by default. Use the include option to limit compilation to SPA component directories when another JSX renderer is present. Top-level functions containing JSX are branded by the compiler for renderer detection.
111
145
 
112
146
  Default islands share the normal implicit atom.io store in the browser. Module-scoped tokens, SPA hooks, and ordinary getState/setState calls all address the same graph. SSR shares a separate store within each request; concurrent requests never share values. Definitions imported after an earlier island started are installed into that request's store before the next island prepares. Server reads and writes must use the selected store (through SPA hooks or store-aware atom.io operations); free getState/setState calls still target the process-global implicit store.
113
147
 
114
- The integration starts observing browser state before island preparation. Untouched initial islands hydrate their matching server DOM. Once application state changes or a shared client:only island starts, delayed islands mount fresh against the live graph. Astro ClientRouter navigation also makes newly introduced islands mount fresh, preserving existing browser values instead of replaying the incoming server snapshot. Mounted and persisted roots keep their subscriptions and DOM. This decision is conservative across the application: even an unrelated state change disables hydration for later roots. Ordinary defaults must still produce matching initial values; SPA does not serialize stores or repair nondeterministic renders.
148
+ The integration starts observing browser state before island preparation. Untouched initial islands hydrate their matching server DOM. Once application state changes or a shared client:only island starts, delayed islands mount fresh against the live graph. Astro ClientRouter navigation also makes newly introduced islands mount fresh, preserving existing browser values instead of replaying the incoming server snapshot. Mounted and persisted roots keep their subscriptions and DOM. This decision is conservative across the application: even an unrelated state change disables hydration for later roots. Ordinary defaults should still produce matching initial values. DOM mismatch recovery keeps a view interactive; it does not reconstruct missing server data or resolve nondeterministic application logic.
149
+
150
+ With resumability/astro installed alongside SPA, resumability owns Astro's request collection, page sidecars, and browser scope. SPA awaits async state used by JSX and uses the host's renderer adapter to attach seeds to islands. Ordinary atom defaults use the host without changing the store's evaluator; private stores bind a separate scope so lazy work ends with the island. Define resumable defaults at module scope and render ordinary Astro islands. Components need no Resumption wrapper, prepareStore callback, or preload list. The same host supports plain Astro constants without atom.io. See the [resumability guide](https://atom.io.fyi/docs/spa/astro#resumability) and the inventory starter for a complete example. Resumability is an optional peer, loaded only by this adapter.
151
+
152
+ Server-rendered views record the state tokens they read so the browser can check readiness before hydration. If an ordinary async default is still pending without a synchronous seed, SPA mounts a fresh view with its loading state; seeded values continue to hydrate existing DOM. This also handles cached server reads and mixed ordinary/resumable state. Private server preparation and rendering are cancelled with their request, releasing cleanup resources even when a producer ignores its abort signal.
115
153
 
116
154
  Set a component's isolate property to true to opt into a private store copied from registered definitions. An optional createStore(props, context) factory supplies a custom RootStore or promise and retains a private preparation lifetime. Custom factories that return the same store are responsible for coordinating their hydration and cleanup. Keep atom definitions at module scope in either mode.
117
155
 
118
- An optional prepareStore(store, props, context) callback initializes the selected store and may return a promise. SPA awaits it before component setup on the server and browser. Existing one-argument synchronous factories still work. Use serialized props or an independent transport such as resumability for server-produced initial data. Shared preparation must be safe to call for multiple islands; use context.application.get(key, initialize) to create an application resource once.
156
+ An optional prepareStore(store, props, context) callback initializes the selected store and may return a promise. SPA awaits it before component setup on the server and browser. Existing one-argument synchronous factories still work. Shared preparation must be safe to call for multiple islands; use context.application.get(key, initialize) to create an application resource once.
119
157
 
120
158
  The context provides element (the browser astro-island host, undefined on the server), signal, and onCleanup for the individual island. Its application provides get, signal, onCleanup, and canResume for the shared lifetime. Browser application resources survive island removal and ClientRouter navigation; they end on a full page exit, with back/forward-cache suspension preserved. SSR application resources end after the response stream finishes or is cancelled. Private islands' application resources end with the island. Use application cleanup and cancellation for shared fetches or resumption scopes; use the outer context for resources owned by one island.
121
159
 
@@ -125,8 +163,6 @@ Register cleanup as resources are acquired, before awaiting work that might fail
125
163
 
126
164
  AstroApplicationContext, AstroStoreContext, AstroStoreFactory, AstroStorePreparation, and Island types are exported from @atom.io/spa/astro. Preparation runs before component setup, so use the context's cleanup registrar there; use SPA's onCleanup inside components. Preparation failures reject the Astro render or hydration operation, retaining cleanup errors alongside the original failure. The factory and preparation callback are awaited per render; component setup and the standalone renderToString API remain synchronous.
127
165
 
128
- <Counter />
129
-
130
166
  Astro client:load, client:idle, client:visible, client:media, and client:only use Astro's scheduling. The integration hydrates eligible initial server markup or renders fresh content and releases the root on astro:unmount. Default slot content arrives as children and named content through slots. Reserved astro-slot wrappers contain Astro's already-rendered HTML; never use their innerHTML escape hatch for untrusted strings.
131
167
 
132
168
  Persisted islands receive live prop and slot updates without rerunning component setup or recreating their store. Repeated hydration calls during preparation share one factory and preparation invocation. New client mounts use the latest props and slots; hydration attaches to the original server tree first, then applies any changes received while preparing. The factory receives the initial props and runs only when an island is first mounted; put changing values in props rather than relying on the factory to run again.
@@ -137,7 +173,7 @@ The checked Astro fixture demonstrates default/named slots and custom independen
137
173
 
138
174
  The build audits every browser export, including the JSX runtime, from the built JavaScript. Atom.io is an external peer in the incremental measurement. Compiler, server, and integration code have separate entrypoints. The report also includes the complete client plus atom.io, the Astro client entrypoint, and the installed Preact version under the same bundling/minification settings. These are full exported surfaces, not equivalent application benchmarks.
139
175
 
140
- The hard budget is under 4,100 bytes of ordinary level-9 gzip for the complete client export surface. Tsdown builds the package JavaScript and declarations, with separate production and development outputs that each share their runtime across entrypoints. The size audit then bundles the built exports with esbuild, minifies with Oxc, and measures compression using Node's gzip and Brotli implementations. The complete client export surface measures approximately 4.0 kB with gzip; dist/size.json records the exact build measurements. Actual application bundles add atom.io and compiler-generated application code.
176
+ The hard budget is under 4,300 bytes of ordinary level-9 gzip for the complete client export surface, including hydration recovery and its production diagnostics. Tsdown builds the package JavaScript and declarations, with separate production and development outputs that each share their runtime across entrypoints. The size audit then bundles the built exports with esbuild, minifies with Oxc, and measures compression using Node's gzip and Brotli implementations. The complete client export surface measures approximately 4.2 kB with gzip; dist/size.json records the exact build measurements. Actual application bundles add atom.io and compiler-generated application code.
141
177
 
142
178
  Build output includes the minified audit entrypoint and machine-readable dist/size.json. These audit files are a bundled measurement; use the package exports in applications so the bundler preserves one runtime instance across entrypoints. Source tests exercise development behavior; the production test executes the audited minified artifact. Chromium checks exercise the actual Astro build, island isolation, hydration, keyed identity, focus/selection, SVG namespaces, and teardown. A fresh-cache Astro development check also covers mount hooks, shared state, and ClientRouter navigation.
143
179
 
@@ -147,7 +183,7 @@ Build output includes the minified audit entrypoint and machine-readable dist/si
147
183
 
148
184
  Breakage exercises the packed package in isolated, locked peer environments, including the coordinated atom.io workspace candidate. Until the first published release, Breakage reports a first-release baseline; these checks establish compatibility with the declared peers rather than a previous spa release. Coverage gates require 100% of statements, branches, functions, and lines across the package source.
149
185
 
150
- Tonnage measures combined browser bundles containing SPA and atom.io, with shared modules counted once and unused exports removed. The synchronous recipes include atom creation, useValue, useSetter, and JSX; the client recipe adds render, the hydration recipe adds hydrate, and the Astro recipe adds the browser island adapter. The async recipe uses useLoadable with render and useSetter. The family recipe includes keyed state, refs, and timeline controls, plus atomFamily, timelineFamily, and scopeFamily. SPA declares atom.io as a peer dependency; these consumer-app measurements include it in every total. Application components, Astro scheduling code, CSS, declarations, and source maps are excluded. The full-client gzip budget above remains a separate, SPA-only audit.
186
+ Tonnage measures combined browser bundles containing SPA and atom.io, with shared modules counted once and unused exports removed. The synchronous recipes include atom creation, useGetter, useSetter, and JSX; the client recipe adds render, the hydration recipe adds hydrate, and the Astro recipe adds the browser island adapter. The async recipe uses useLoadable with render and useSetter. The family recipe includes keyed state, refs, and timeline controls, plus atomFamily, timelineFamily, and scopeFamily. SPA declares atom.io as a peer dependency; these consumer-app measurements include it in every total. Application components, Astro scheduling code, CSS, declarations, and source maps are excluded. The full-client gzip budget above remains a separate, SPA-only audit.
151
187
 
152
188
  <Tonnage config={config} />
153
189
 
@@ -205,7 +241,7 @@ The same attributes animate numeric Konva properties and colors, or Three.js pos
205
241
 
206
242
  <MotionThree />
207
243
 
208
- When the motion capability is installed, Canvas draws in Motion's render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator. Presence hooks add approximately 300 bytes of gzip to the released 3.7 kB client surface; the optional Motion entrypoint owns the retention machinery. The full client budget is 4,100 bytes.
244
+ When the motion capability is installed, Canvas draws in Motion's render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator. Presence hooks add approximately 300 bytes of gzip to the released 3.7 kB client surface; the optional Motion entrypoint owns the retention machinery. The full client budget is 4,300 bytes.
209
245
 
210
246
  ### Exit animations and re-entry
211
247
 
@@ -1,4 +1,4 @@
1
- import { t as AstroApplicationContext } from "./astro-shared-BkWvVZWZ.js";
1
+ import { t as AstroApplicationContext } from "./astro-shared-DHIpjNIG.js";
2
2
  type Lifetime = {
3
3
  signal: AbortSignal;
4
4
  onCleanup(cleanup: () => void): () => void;
@@ -1,9 +1,10 @@
1
- import { a as Island } from "./astro-shared-BkWvVZWZ.js";
1
+ import { a as Island, i as AstroStorePreparation } from "./astro-shared-DHIpjNIG.js";
2
2
  type Props = Record<string, any>;
3
3
  type Slots = Record<string, string>;
4
4
  type Hydrator = (component: Island, props: Props, slots: Slots, metadata: {
5
5
  client: string;
6
6
  }) => Promise<void>;
7
- declare function _default(element: HTMLElement): Hydrator;
7
+ export declare const createHydrator: (prepare?: AstroStorePreparation) => (element: HTMLElement) => Hydrator;
8
+ declare const _default: (element: HTMLElement) => Hydrator;
8
9
  export { _default as default };
9
10
  //# sourceMappingURL=astro-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-client.d.ts","names":[],"sources":["../src/astro-client.ts"],"mappings":";KAiBK,QAAQ;KACR,QAAQ;KACR,YACJ,WAAW,QACX,OAAO,OACP,OAAO,OACP;EAAY;MACR;iBAcW,SAAA,SAAS,cAAc"}
1
+ {"version":3,"file":"astro-client.d.ts","names":[],"sources":["../src/astro-client.ts"],"mappings":";KAkBK,QAAQ;KACR,QAAQ;KACR,YACJ,WAAW,QACX,OAAO,OACP,OAAO,OACP;EAAY;MACR;qBAcQ,iBAAc,UACf,2BAAqB,SACtB,gBAAc;cAAd,WAAA,SAAA,gBAAc"}
@@ -1,14 +1,14 @@
1
1
  import { browserApplication } from "./astro-application.js";
2
2
  import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
3
- import { n as islandStore, t as island } from "./astro-shared-BT45auwR.js";
4
- import { b as useValue, c as onCleanup } from "./core-DCmqLZQP.js";
5
- import { n as render, t as hydrate } from "./dom-dHQM0O7Q.js";
6
- import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, setIntoStore } from "atom.io/internal";
3
+ import { n as islandStore, t as island } from "./astro-shared-83hxw7-M.js";
4
+ import { c as onCleanup, m as useGetter } from "./core-DjFJ0aIJ.js";
5
+ import { n as render, t as hydrate } from "./dom-B5OxgHkr.js";
6
+ import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, getFromStore, setIntoStore } from "atom.io/internal";
7
7
  // src/astro-client.ts
8
8
  const roots = /* @__PURE__ */ new WeakMap();
9
9
  const states = /* @__PURE__ */ new WeakMap();
10
10
  let serial = 0;
11
- var astro_client_default = (element) => async (component, props, slots, { client }) => {
11
+ const createHydrator = (prepare) => (element) => async (component, props, slots, { client }) => {
12
12
  const previous = roots.get(element);
13
13
  if (previous?.component === component) {
14
14
  previous.update(props, slots);
@@ -37,10 +37,10 @@ var astro_client_default = (element) => async (component, props, slots, { client
37
37
  if (lifetime.context.signal.aborted) return;
38
38
  let mounting = false;
39
39
  try {
40
- const store = await Promise.race([islandStore(component, props, lifetime.context, shared ? IMPLICIT.STORE : void 0), lifetime.cancelled]);
40
+ const store = await Promise.race([islandStore(component, props, lifetime.context, shared ? IMPLICIT.STORE : void 0, prepare), lifetime.cancelled]);
41
41
  if (lifetime.context.signal.aborted) return;
42
42
  mounting = true;
43
- const replace = client === `only` || previous !== void 0 || application?.canResume === false;
43
+ const replace = client === `only` || previous !== void 0 || application?.canResume === false || JSON.parse(element.getAttribute(`data-spa-reads`) ?? `[]`).some((token) => getFromStore(store, token) instanceof Promise);
44
44
  const sentinel = element.lastChild;
45
45
  if (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`) sentinel.remove();
46
46
  let family = states.get(store);
@@ -61,8 +61,8 @@ var astro_client_default = (element) => async (component, props, slots, { client
61
61
  });
62
62
  const mount = () => {
63
63
  onCleanup(dispose);
64
- const value = useValue(state);
65
- return () => island(component, value().props, value().slots);
64
+ const getState = useGetter(state);
65
+ return () => island(component, getState().props, getState().slots);
66
66
  };
67
67
  if (replace) element.replaceChildren();
68
68
  const root = (replace ? render : hydrate)(mount, element, {
@@ -96,6 +96,7 @@ var astro_client_default = (element) => async (component, props, slots, { client
96
96
  lifetime.context.onCleanup(dispose);
97
97
  return ready;
98
98
  };
99
- export { astro_client_default as default };
99
+ var astro_client_default = createHydrator();
100
+ export { createHydrator, astro_client_default as default };
100
101
 
101
102
  //# sourceMappingURL=astro-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-client.js","names":[],"sources":["../src/astro-client.ts"],"sourcesContent":["import type { RegularAtomFamilyToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { onCleanup, useValue } from \"./core.ts\"\nimport { hydrate, render } from \"./dom.ts\"\n\ntype Props = Record<string, any>\ntype Slots = Record<string, string>\ntype Hydrator = (\n\tcomponent: Island,\n\tprops: Props,\n\tslots: Slots,\n\tmetadata: { client: string },\n) => Promise<void>\nconst roots = new WeakMap<\n\tElement,\n\t{\n\t\tcomponent: Island\n\t\tready: Promise<void>\n\t\tupdate(props: Props, slots: Slots): void\n\t\tdispose(): void\n\t}\n>()\ntype State = { props: Props; slots: Slots }\nconst states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()\nlet serial = 0\n\nexport default (element: HTMLElement): Hydrator =>\n\tasync (component, props, slots, { client }) => {\n\t\tconst previous = roots.get(element)\n\t\tif (previous?.component === component) {\n\t\t\tprevious.update(props, slots)\n\t\t\treturn previous.ready\n\t\t}\n\t\tprevious?.dispose()\n\t\tconst shared = !component.createStore && !component.isolate\n\t\tconst application = shared\n\t\t\t? browserApplication(element.ownerDocument)\n\t\t\t: undefined\n\t\tif (application && client === `only`) application.canResume = false\n\t\tconst lifetime = storeContext(element, application)\n\t\tconst initial = { props, slots }\n\t\tlet current = initial\n\t\tlet update: ((value: State) => void) | undefined\n\t\tlet disposed = false\n\t\tconst dispose = () => {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\telement.removeEventListener(`astro:unmount`, dispose)\n\t\t\troots.delete(element)\n\t\t\tlifetime.dispose()\n\t\t}\n\t\t// Publish the pending owner before invoking user code. Repeated hydration\n\t\t// calls update its props and share its preparation rather than racing stores.\n\t\tconst ready = Promise.resolve().then(async () => {\n\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\tlet mounting = false\n\t\t\ttry {\n\t\t\t\tconst store = await Promise.race([\n\t\t\t\t\tislandStore(\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t\tlifetime.context,\n\t\t\t\t\t\tshared ? IMPLICIT.STORE : undefined,\n\t\t\t\t\t),\n\t\t\t\t\tlifetime.cancelled,\n\t\t\t\t])\n\t\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\t\tmounting = true\n\t\t\t\tconst replace =\n\t\t\t\t\tclient === `only` ||\n\t\t\t\t\tprevious !== undefined ||\n\t\t\t\t\tapplication?.canResume === false\n\t\t\t\t// Astro leaves this sentinel on islands inserted by ClientRouter.\n\t\t\t\tconst sentinel = element.lastChild\n\t\t\t\tif (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)\n\t\t\t\t\tsentinel.remove()\n\t\t\t\tlet family = states.get(store!)\n\t\t\t\tif (!family) {\n\t\t\t\t\tfamily = createRegularAtomFamily<State, number, never>(store!, {\n\t\t\t\t\t\tkey: `🔍 spa islands`,\n\t\t\t\t\t\tdefault: { props: {}, slots: {} },\n\t\t\t\t\t})\n\t\t\t\t\tstates.set(store!, family)\n\t\t\t\t}\n\t\t\t\tconst state = findInStore(store!, family, serial++)\n\t\t\t\tsetIntoStore(store!, state, replace ? current : initial)\n\t\t\t\tlifetime.context.onCleanup(() => {\n\t\t\t\t\tdisposeFromStore(store!, state)\n\t\t\t\t})\n\t\t\t\tconst mount = () => {\n\t\t\t\t\tonCleanup(dispose)\n\t\t\t\t\tconst value = useValue(state)\n\t\t\t\t\treturn () => island(component, value().props, value().slots)\n\t\t\t\t}\n\t\t\t\tif (replace) element.replaceChildren()\n\t\t\t\tconst root = (replace ? render : hydrate)(mount, element, {\n\t\t\t\t\tstore: store!,\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t})\n\t\t\t\tlifetime.context.onCleanup(root.dispose)\n\t\t\t\tupdate = (next) => {\n\t\t\t\t\tsetIntoStore(store!, state, next)\n\t\t\t\t\troot.flush()\n\t\t\t\t}\n\t\t\t\t// Match the existing SSR tree before applying a structural prop update\n\t\t\t\t// that arrived while its store was still being prepared.\n\t\t\t\tif (!replace && current !== initial) update(current)\n\t\t\t} catch (error) {\n\t\t\t\tif (lifetime.context.signal.aborted && !mounting) return\n\t\t\t\tfailPreparation(error, dispose)\n\t\t\t}\n\t\t})\n\t\troots.set(element, {\n\t\t\tcomponent,\n\t\t\tready,\n\t\t\tupdate(nextProps, nextSlots) {\n\t\t\t\tcurrent = { props: nextProps, slots: nextSlots }\n\t\t\t\tupdate?.(current)\n\t\t\t},\n\t\t\tdispose,\n\t\t})\n\t\telement.addEventListener(`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yToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { AstroStorePreparation, Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { onCleanup, useGetter } from \"./core.ts\"\nimport { hydrate, render } from \"./dom.ts\"\n\ntype Props = Record<string, any>\ntype Slots = Record<string, string>\ntype Hydrator = (\n\tcomponent: Island,\n\tprops: Props,\n\tslots: Slots,\n\tmetadata: { client: string },\n) => Promise<void>\nconst roots = new WeakMap<\n\tElement,\n\t{\n\t\tcomponent: Island\n\t\tready: Promise<void>\n\t\tupdate(props: Props, slots: Slots): void\n\t\tdispose(): void\n\t}\n>()\ntype State = { props: Props; slots: Slots }\nconst states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()\nlet serial = 0\n\nexport const createHydrator =\n\t(prepare?: AstroStorePreparation) =>\n\t(element: HTMLElement): Hydrator =>\n\tasync (component, props, slots, { client }) => {\n\t\tconst previous = roots.get(element)\n\t\tif (previous?.component === component) {\n\t\t\tprevious.update(props, slots)\n\t\t\treturn previous.ready\n\t\t}\n\t\tprevious?.dispose()\n\t\tconst shared = !component.createStore && !component.isolate\n\t\tconst application = shared\n\t\t\t? browserApplication(element.ownerDocument)\n\t\t\t: undefined\n\t\tif (application && client === `only`) application.canResume = false\n\t\tconst lifetime = storeContext(element, application)\n\t\tconst initial = { props, slots }\n\t\tlet current = initial\n\t\tlet update: ((value: State) => void) | undefined\n\t\tlet disposed = false\n\t\tconst dispose = () => {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\telement.removeEventListener(`astro:unmount`, dispose)\n\t\t\troots.delete(element)\n\t\t\tlifetime.dispose()\n\t\t}\n\t\t// Publish the pending owner before invoking user code. Repeated hydration\n\t\t// calls update its props and share its preparation rather than racing stores.\n\t\tconst ready = Promise.resolve().then(async () => {\n\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\tlet mounting = false\n\t\t\ttry {\n\t\t\t\tconst store = await Promise.race([\n\t\t\t\t\tislandStore(\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t\tlifetime.context,\n\t\t\t\t\t\tshared ? IMPLICIT.STORE : undefined,\n\t\t\t\t\t\tprepare,\n\t\t\t\t\t),\n\t\t\t\t\tlifetime.cancelled,\n\t\t\t\t])\n\t\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\t\tmounting = true\n\t\t\t\tconst replace =\n\t\t\t\t\tclient === `only` ||\n\t\t\t\t\tprevious !== undefined ||\n\t\t\t\t\tapplication?.canResume === false ||\n\t\t\t\t\t// Server-settled state without a synchronous browser seed needs a\n\t\t\t\t\t// fresh view, whose loading state can differ from the SSR markup.\n\t\t\t\t\t(\n\t\t\t\t\t\tJSON.parse(\n\t\t\t\t\t\t\telement.getAttribute(`data-spa-reads`) ?? `[]`,\n\t\t\t\t\t\t) as ReadableToken<unknown>[]\n\t\t\t\t\t).some((token) => getFromStore(store!, token) instanceof Promise)\n\t\t\t\t// Astro leaves this sentinel on islands inserted by ClientRouter.\n\t\t\t\tconst sentinel = element.lastChild\n\t\t\t\tif (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)\n\t\t\t\t\tsentinel.remove()\n\t\t\t\tlet family = states.get(store!)\n\t\t\t\tif (!family) {\n\t\t\t\t\tfamily = createRegularAtomFamily<State, number, never>(store!, {\n\t\t\t\t\t\tkey: `🔍 spa islands`,\n\t\t\t\t\t\tdefault: { props: {}, slots: {} },\n\t\t\t\t\t})\n\t\t\t\t\tstates.set(store!, family)\n\t\t\t\t}\n\t\t\t\tconst state = findInStore(store!, family, serial++)\n\t\t\t\tsetIntoStore(store!, state, replace ? current : initial)\n\t\t\t\tlifetime.context.onCleanup(() => {\n\t\t\t\t\tdisposeFromStore(store!, state)\n\t\t\t\t})\n\t\t\t\tconst mount = () => {\n\t\t\t\t\tonCleanup(dispose)\n\t\t\t\t\tconst getState = useGetter(state)\n\t\t\t\t\treturn () => island(component, getState().props, getState().slots)\n\t\t\t\t}\n\t\t\t\tif (replace) element.replaceChildren()\n\t\t\t\tconst root = (replace ? render : hydrate)(mount, element, {\n\t\t\t\t\tstore: store!,\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t})\n\t\t\t\tlifetime.context.onCleanup(root.dispose)\n\t\t\t\tupdate = (next) => {\n\t\t\t\t\tsetIntoStore(store!, state, next)\n\t\t\t\t\troot.flush()\n\t\t\t\t}\n\t\t\t\t// Match the existing SSR tree before applying a structural prop update\n\t\t\t\t// that arrived while its store was still being prepared.\n\t\t\t\tif (!replace && current !== initial) update(current)\n\t\t\t} catch (error) {\n\t\t\t\tif (lifetime.context.signal.aborted && !mounting) return\n\t\t\t\tfailPreparation(error, dispose)\n\t\t\t}\n\t\t})\n\t\troots.set(element, {\n\t\t\tcomponent,\n\t\t\tready,\n\t\t\tupdate(nextProps, nextSlots) {\n\t\t\t\tcurrent = { props: nextProps, slots: nextSlots }\n\t\t\t\tupdate?.(current)\n\t\t\t},\n\t\t\tdispose,\n\t\t})\n\t\telement.addEventListener(`astro:unmount`, dispose, { once: true })\n\t\tlifetime.context.onCleanup(dispose)\n\t\treturn ready\n\t}\n\nexport default createHydrator()\n"],"mappings":";;;;;;;AA0BA,MAAM,wBAAQ,IAAI,QAQhB;AAEF,MAAM,yBAAS,IAAI,QAA0D;AAC7E,IAAI,SAAS;AAEb,MAAa,kBACX,aACA,YACD,OAAO,WAAW,OAAO,OAAO,EAAE,aAAa;CAC9C,MAAM,WAAW,MAAM,IAAI,OAAO;CAClC,IAAI,UAAU,cAAc,WAAW;EACtC,SAAS,OAAO,OAAO,KAAK;EAC5B,OAAO,SAAS;CACjB;CACA,UAAU,QAAQ;CAClB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AU,OAAO;GACvD,SAAS,QAAQ,gBAAgB;IAChC,iBAAiB,OAAQ,KAAK;GAC/B,CAAC;GACD,MAAM,cAAc;IACnB,UAAU,OAAO;IACjB,MAAM,WAAW,UAAU,KAAK;IAChC,aAAa,OAAO,WAAW,SAAS,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,KAAK;GAClE;GACA,IAAI,SAAS,QAAQ,gBAAgB;GACrC,MAAM,QAAQ,UAAU,SAAS,QAAA,CAAS,OAAO,SAAS;IAClD;IACP,cAAc,UAAU,gBAAgB,CAAC;GAC1C,CAAC;GACD,SAAS,QAAQ,UAAU,KAAK,OAAO;GACvC,UAAU,SAAS;IAClB,aAAa,OAAQ,OAAO,IAAI;IAChC,KAAK,MAAM;GACZ;GAGA,IAAI,CAAC,WAAW,YAAY,SAAS,OAAO,OAAO;EACpD,SAAS,OAAO;GACf,IAAI,SAAS,QAAQ,OAAO,WAAW,CAAC,UAAU;GAClD,gBAAgB,OAAO,OAAO;EAC/B;CACD,CAAC;CACD,MAAM,IAAI,SAAS;EAClB;EACA;EACA,OAAO,WAAW,WAAW;GAC5B,UAAU;IAAE,OAAO;IAAW,OAAO;GAAU;GAC/C,SAAS,OAAO;EACjB;EACA;CACD,CAAC;CACD,QAAQ,iBAAiB,iBAAiB,SAAS,EAAE,MAAM,KAAK,CAAC;CACjE,SAAS,QAAQ,UAAU,OAAO;CAClC,OAAO;AACR;AAED,IAAA,uBAAe,eAAe"}
@@ -0,0 +1,10 @@
1
+ import { a as Island } from "./astro-shared-DHIpjNIG.js";
2
+ declare const _default: (element: HTMLElement) => (component: Island, props: {
3
+ [x: string]: any;
4
+ }, slots: {
5
+ [x: string]: string;
6
+ }, metadata: {
7
+ client: string;
8
+ }) => Promise<void>;
9
+ export { _default as default };
10
+ //# sourceMappingURL=astro-resumability-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-client.d.ts","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { browserApplication } from "./astro-application.js";
2
+ import { createHydrator } from "./astro-client.js";
3
+ import { browserResumption, captureElement, createResumption } from "resumability/astro-client";
4
+ // src/astro-resumability-client.ts
5
+ var astro_resumability_client_default = createHydrator((store, _props, { element, application }) => {
6
+ const scopes = application.get(createResumption, () => /* @__PURE__ */ new WeakMap());
7
+ let scope = scopes.get(store);
8
+ if (!scope) {
9
+ if (application === browserApplication(element.ownerDocument)) {
10
+ const host = browserResumption(element.ownerDocument);
11
+ application.onCleanup(host.resumeWhen(() => application.canResume));
12
+ scope = host;
13
+ } else {
14
+ const original = store.runDefault;
15
+ const local = createResumption();
16
+ store.runDefault = (run) => local.run(() => original.call(store, run), { resume: application.canResume });
17
+ application.onCleanup(() => {
18
+ local.dispose();
19
+ store.runDefault = original;
20
+ });
21
+ scope = local;
22
+ }
23
+ scopes.set(store, scope);
24
+ }
25
+ captureElement(scope, element);
26
+ });
27
+ export { astro_resumability_client_default as default };
28
+
29
+ //# sourceMappingURL=astro-resumability-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-client.js","names":[],"sources":["../src/astro-resumability-client.ts"],"sourcesContent":["import {\n\tbrowserResumption,\n\tcaptureElement,\n\tcreateResumption,\n} from \"resumability/astro-client\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { createHydrator } from \"./astro-client.ts\"\n\nexport default createHydrator((store, _props, { element, application }) => {\n\tconst scopes = application.get(\n\t\tcreateResumption,\n\t\t() => new WeakMap<object, ReturnType<typeof createResumption>>(),\n\t)\n\tlet scope = scopes.get(store)\n\tif (!scope) {\n\t\tconst shared = application === browserApplication(element!.ownerDocument)\n\t\tif (shared) {\n\t\t\tconst host = browserResumption(element!.ownerDocument)\n\t\t\tapplication.onCleanup(host.resumeWhen(() => application.canResume))\n\t\t\tscope = host\n\t\t} else {\n\t\t\t// Lazy defaults can run after component setup. Bind their private owner so\n\t\t\t// refreshes and pending work end with this island instead of the page.\n\t\t\tconst original = store.runDefault\n\t\t\tconst local = createResumption()\n\t\t\tstore.runDefault = <T>(run: () => T): T =>\n\t\t\t\tlocal.run(() => original.call(store, run) as T, {\n\t\t\t\t\tresume: application.canResume,\n\t\t\t\t})\n\t\t\tapplication.onCleanup(() => {\n\t\t\t\tlocal.dispose()\n\t\t\t\tstore.runDefault = original\n\t\t\t})\n\t\t\tscope = local\n\t\t}\n\t\tscopes.set(store, scope)\n\t}\n\tcaptureElement(scope, element!)\n})\n"],"mappings":";;;;AASA,IAAA,oCAAe,gBAAgB,OAAO,QAAQ,EAAE,SAAS,kBAAkB;CAC1E,MAAM,SAAS,YAAY,IAC1B,wCACM,IAAI,QAAqD,CAChE;CACA,IAAI,QAAQ,OAAO,IAAI,KAAK;CAC5B,IAAI,CAAC,OAAO;EAEX,IADe,gBAAgB,mBAAmB,QAAS,aAAa,GAC5D;GACX,MAAM,OAAO,kBAAkB,QAAS,aAAa;GACrD,YAAY,UAAU,KAAK,iBAAiB,YAAY,SAAS,CAAC;GAClE,QAAQ;EACT,OAAO;GAGN,MAAM,WAAW,MAAM;GACvB,MAAM,QAAQ,iBAAiB;GAC/B,MAAM,cAAiB,QACtB,MAAM,UAAU,SAAS,KAAK,OAAO,GAAG,GAAQ,EAC/C,QAAQ,YAAY,UACrB,CAAC;GACF,YAAY,gBAAgB;IAC3B,MAAM,QAAQ;IACd,MAAM,aAAa;GACpB,CAAC;GACD,QAAQ;EACT;EACA,OAAO,IAAI,OAAO,KAAK;CACxB;CACA,eAAe,OAAO,OAAQ;AAC/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("astro").NamedSSRLoadedRendererValue;
2
+ export { _default as default };
3
+ //# sourceMappingURL=astro-resumability-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-server.d.ts","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { createRenderer } from "./astro-server.js";
2
+ import { resumableRenderer } from "resumability/astro-server";
3
+ // src/astro-resumability-server.ts
4
+ var astro_resumability_server_default = resumableRenderer(createRenderer(true), { isolate: (component) => Boolean(component.createStore ?? component.isolate) });
5
+ export { astro_resumability_server_default as default };
6
+
7
+ //# sourceMappingURL=astro-resumability-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-server.js","names":[],"sources":["../src/astro-resumability-server.ts"],"sourcesContent":["import { resumableRenderer } from \"resumability/astro-server\"\n\nimport { createRenderer } from \"./astro-server.ts\"\n\nexport default resumableRenderer(createRenderer(true), {\n\tisolate: (component) => Boolean(component.createStore ?? component.isolate),\n})\n"],"mappings":";;;AAIA,IAAA,oCAAe,kBAAkB,eAAe,IAAI,GAAG,EACtD,UAAU,cAAc,QAAQ,UAAU,eAAe,UAAU,OAAO,EAC3E,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { NamedSSRLoadedRendererValue } from "astro";
2
- declare const renderer: NamedSSRLoadedRendererValue;
3
- export { renderer as default };
2
+ export declare const createRenderer: (awaitState?: boolean) => NamedSSRLoadedRendererValue;
3
+ declare const _default: NamedSSRLoadedRendererValue;
4
+ export { _default as default };
4
5
  //# sourceMappingURL=astro-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-server.d.ts","names":[],"sources":["../src/astro-server.ts"],"mappings":";cASM,UAAU"}
1
+ {"version":3,"file":"astro-server.d.ts","names":[],"sources":["../src/astro-server.ts"],"mappings":";qBAUa,iBAAc,yBAExB"}
@@ -1,31 +1,50 @@
1
1
  import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
2
2
  import { t as requestApplication } from "./astro-request-DRKvDjsO.js";
3
- import { n as islandStore, t as island } from "./astro-shared-BT45auwR.js";
4
- import { renderToString } from "./server.js";
3
+ import { n as islandStore, t as island } from "./astro-shared-83hxw7-M.js";
4
+ import { t as renderToStringWithReads } from "./server-renderer-DcU55e6s.js";
5
5
  // src/astro-server.ts
6
- const renderer = {
6
+ const createRenderer = (awaitState = false) => ({
7
7
  name: `spa`,
8
8
  async check(component) {
9
9
  return component?.spa === true;
10
10
  },
11
11
  async renderToStaticMarkup(component, props, slots) {
12
12
  const request = this.result?.request;
13
- const shared = !component.createStore && !component.isolate && request ? requestApplication(request) : void 0;
13
+ const requestOwner = request ? requestApplication(request) : void 0;
14
+ const shared = !component.createStore && !component.isolate ? requestOwner : void 0;
14
15
  const lifetime = storeContext(void 0, shared?.application);
16
+ if (requestOwner && !shared) lifetime.context.onCleanup(requestOwner.application.onCleanup(lifetime.dispose));
15
17
  try {
16
- const store = await islandStore(component, props, lifetime.context, shared?.store);
17
- return { html: renderToString(() => () => island(component, props, slots), {
18
+ lifetime.context.signal.throwIfAborted();
19
+ const store = await Promise.race([islandStore(component, props, lifetime.context, shared?.store), lifetime.cancelled]);
20
+ lifetime.context.signal.throwIfAborted();
21
+ const options = {
18
22
  store,
19
23
  idPrefix: crypto.randomUUID(),
20
24
  capabilities: component.capabilities ?? []
21
- }) };
25
+ };
26
+ for (;;) {
27
+ lifetime.context.signal.throwIfAborted();
28
+ const reads = /* @__PURE__ */ new Map();
29
+ const pending = /* @__PURE__ */ new Set();
30
+ const html = renderToStringWithReads(() => () => island(component, props, slots), options, awaitState ? (value, token) => {
31
+ reads.set(token.key, token);
32
+ if (value instanceof Promise) pending.add(value);
33
+ } : void 0);
34
+ if (!pending.size) return {
35
+ html,
36
+ ...reads.size ? { attrs: { "data-spa-reads": JSON.stringify([...reads.values()]) } } : {}
37
+ };
38
+ await Promise.race([Promise.all(pending), lifetime.cancelled]);
39
+ }
22
40
  } catch (error) {
23
41
  failPreparation(error, lifetime.dispose);
24
42
  } finally {
25
43
  lifetime.dispose();
26
44
  }
27
45
  }
28
- };
29
- export { renderer as default };
46
+ });
47
+ var astro_server_default = createRenderer();
48
+ export { createRenderer, astro_server_default as default };
30
49
 
31
50
  //# sourceMappingURL=astro-server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-server.js","names":[],"sources":["../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToString } from \"./server.ts\"\n\nconst renderer: NamedSSRLoadedRendererValue = {\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate && request\n\t\t\t\t? requestApplication(request)\n\t\t\t\t: undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\ttry {\n\t\t\tconst store = await islandStore(\n\t\t\t\tcomponent,\n\t\t\t\tprops,\n\t\t\t\tlifetime.context,\n\t\t\t\tshared?.store,\n\t\t\t)\n\t\t\treturn {\n\t\t\t\thtml: renderToString(() => () => island(component, props, slots), {\n\t\t\t\t\tstore,\n\t\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t}),\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailPreparation(error, lifetime.dispose)\n\t\t} finally {\n\t\t\tlifetime.dispose()\n\t\t}\n\t},\n}\nexport default renderer\n"],"mappings":";;;;;AASA,MAAM,WAAwC;CAC7C,MAAM;CACN,MAAM,MAAM,WAAmB;EAC9B,OAAO,WAAW,QAAQ;CAC3B;CACA,MAAM,qBAAqB,WAAmB,OAAO,OAAO;EAC3D,MAAM,UAAW,KAAsD,QACpE;EACH,MAAM,SACL,CAAC,UAAU,eAAe,CAAC,UAAU,WAAW,UAC7C,mBAAmB,OAAO,IAC1B,KAAA;EACJ,MAAM,WAAW,aAAa,KAAA,GAAW,QAAQ,WAAW;EAC5D,IAAI;GACH,MAAM,QAAQ,MAAM,YACnB,WACA,OACA,SAAS,SACT,QAAQ,KACT;GACA,OAAO,EACN,MAAM,2BAA2B,OAAO,WAAW,OAAO,KAAK,GAAG;IACjE;IACA,UAAU,OAAO,WAAW;IAC5B,cAAc,UAAU,gBAAgB,CAAC;GAC1C,CAAC,EACF;EACD,SAAS,OAAO;GACf,gBAAgB,OAAO,SAAS,OAAO;EACxC,UAAU;GACT,SAAS,QAAQ;EAClB;CACD;AACD"}
1
+ {"version":3,"file":"astro-server.js","names":[],"sources":["../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\nimport type { ReadableToken } from \"atom.io\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToStringWithReads } from \"./server-renderer.ts\"\n\nexport const createRenderer = (\n\tawaitState = false,\n): NamedSSRLoadedRendererValue => ({\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst requestOwner = request ? requestApplication(request) : undefined\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate ? requestOwner : undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\tif (requestOwner && !shared) {\n\t\t\tlifetime.context.onCleanup(\n\t\t\t\trequestOwner.application.onCleanup(lifetime.dispose),\n\t\t\t)\n\t\t}\n\t\ttry {\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst store = await Promise.race([\n\t\t\t\tislandStore(component, props, lifetime.context, shared?.store),\n\t\t\t\tlifetime.cancelled,\n\t\t\t])\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst options = {\n\t\t\t\tstore: store!,\n\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t}\n\t\t\t// Retry only after reads made by this view settle. Each discarded render\n\t\t\t// releases its scopes; conditional branches can discover more async state.\n\t\t\tfor (;;) {\n\t\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\t\tconst reads = new Map<string, ReadableToken<unknown>>()\n\t\t\t\tconst pending = new Set<Promise<unknown>>()\n\t\t\t\tconst html = renderToStringWithReads(\n\t\t\t\t\t() => () => island(component, props, slots),\n\t\t\t\t\toptions,\n\t\t\t\t\tawaitState\n\t\t\t\t\t\t? (value, token) => {\n\t\t\t\t\t\t\t\treads.set(token.key, token)\n\t\t\t\t\t\t\t\tif (value instanceof Promise) {\n\t\t\t\t\t\t\t\t\tpending.add(value)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t)\n\t\t\t\tif (!pending.size)\n\t\t\t\t\treturn {\n\t\t\t\t\t\thtml,\n\t\t\t\t\t\t// Even a cached synchronous server read can be async in the browser.\n\t\t\t\t\t\t...(reads.size\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tattrs: {\n\t\t\t\t\t\t\t\t\t\t\"data-spa-reads\": JSON.stringify([...reads.values()]),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t// Caught producer errors resolve as state values. An uncaught failure\n\t\t\t\t// must reject this render with its original error.\n\t\t\t\tawait Promise.race([Promise.all(pending), lifetime.cancelled])\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailPreparation(error, lifetime.dispose)\n\t\t} finally {\n\t\t\tlifetime.dispose()\n\t\t}\n\t},\n})\nexport default createRenderer()\n"],"mappings":";;;;;AAUA,MAAa,kBACZ,aAAa,WACqB;CAClC,MAAM;CACN,MAAM,MAAM,WAAmB;EAC9B,OAAO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;EAClB;CACD;AACD;AACA,IAAA,uBAAe,eAAe"}
@@ -1,13 +1,15 @@
1
1
  import { jsx } from "./jsx-runtime.js";
2
2
  import { IMPLICIT, Store } from "atom.io/internal";
3
3
  // src/astro-shared.ts
4
- async function islandStore(component, props, context, shared) {
4
+ async function islandStore(component, props, context, shared, prepare) {
5
5
  const store = await (component.createStore?.(props, context) ?? shared ?? new Store({
6
6
  name: `spa-island`,
7
7
  lifespan: `ephemeral`,
8
8
  isProduction: true
9
9
  }, IMPLICIT.STORE));
10
10
  context.signal.throwIfAborted();
11
+ await prepare?.(store, props, context);
12
+ context.signal.throwIfAborted();
11
13
  await component.prepareStore?.(store, props, context);
12
14
  context.signal.throwIfAborted();
13
15
  return store;
@@ -26,4 +28,4 @@ function island(component, props, slots) {
26
28
  }
27
29
  export { islandStore as n, island as t };
28
30
 
29
- //# sourceMappingURL=astro-shared-BT45auwR.js.map
31
+ //# sourceMappingURL=astro-shared-83hxw7-M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-shared-83hxw7-M.js","names":[],"sources":["../src/astro-shared.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT, Store } from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type { Component, SpaElement } from \"./core.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\n\nexport interface AstroApplicationContext {\n\t/** Whether the application still represents its initial server snapshot. */\n\treadonly canResume: boolean\n\treadonly signal: AbortSignal\n\tonCleanup(cleanup: () => void): void\n\t/** Initialize a resource once for this application lifetime. */\n\tget<T>(key: unknown, initialize: () => T): T\n}\nexport interface AstroStoreContext {\n\t/** Shared across default islands; private for explicitly isolated islands. */\n\tapplication: AstroApplicationContext\n\t/** The browser island host; undefined during server rendering. */\n\telement: HTMLElement | undefined\n\t/** Aborted when preparation is cancelled or the island is released. */\n\tsignal: AbortSignal\n\t/** Release resources even if preparation or rendering fails. */\n\tonCleanup(cleanup: () => void): void\n}\nexport type AstroStoreFactory<P = Record<string, any>> = (\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => RootStore | Promise<RootStore>\nexport type AstroStorePreparation<P = Record<string, any>> = (\n\tstore: RootStore,\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => void | Promise<void>\nexport type Island<P = any> = Component<P> & {\n\tspa?: boolean\n\t/** Capabilities are scoped to this island root on the server and client. */\n\tcapabilities?: readonly Capability[]\n\t/** Opt into a private island store instead of the shared application store. */\n\tisolate?: boolean\n\tcreateStore?: AstroStoreFactory<P>\n\tprepareStore?: AstroStorePreparation<P>\n}\nexport async function islandStore(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tcontext: AstroStoreContext,\n\tshared?: RootStore,\n\tprepare?: AstroStorePreparation,\n): Promise<RootStore> {\n\tconst store = await (component.createStore?.(props, context) ??\n\t\tshared ??\n\t\t(new Store(\n\t\t\t{ name: `spa-island`, lifespan: `ephemeral`, isProduction: true },\n\t\t\tIMPLICIT.STORE,\n\t\t) as RootStore))\n\tcontext.signal.throwIfAborted()\n\tawait prepare?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\tawait component.prepareStore?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\treturn store\n}\nexport function island(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tslots: Record<string, string>,\n): SpaElement {\n\tconst children = Object.fromEntries(\n\t\tObject.entries(slots).map(([name, html]) => [\n\t\t\tname,\n\t\t\tjsx(`astro-slot`, {\n\t\t\t\tkey: html,\n\t\t\t\tname: name === `default` ? undefined : name,\n\t\t\t\tinnerHTML: html,\n\t\t\t}),\n\t\t]),\n\t)\n\treturn jsx(component, {\n\t\t...props,\n\t\tslots: children,\n\t\tchildren: children[`default`],\n\t})\n}\n"],"mappings":";;;AA2CA,eAAsB,YACrB,WACA,OACA,SACA,QACA,SACqB;CACrB,MAAM,QAAQ,OAAO,UAAU,cAAc,OAAO,OAAO,KAC1D,UACC,IAAI,MACJ;EAAE,MAAM;EAAc,UAAU;EAAa,cAAc;CAAK,GAChE,SAAS,KACV;CACD,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,OAAO,OAAO,OAAO;CACrC,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,eAAe,OAAO,OAAO,OAAO;CACpD,QAAQ,OAAO,eAAe;CAC9B,OAAO;AACR;AACA,SAAgB,OACf,WACA,OACA,OACa;CACb,MAAM,WAAW,OAAO,YACvB,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAC3C,MACA,IAAI,cAAc;EACjB,KAAK;EACL,MAAM,SAAS,YAAY,KAAA,IAAY;EACvC,WAAW;CACZ,CAAC,CACF,CAAC,CACF;CACA,OAAO,IAAI,WAAW;EACrB,GAAG;EACH,OAAO;EACP,UAAU,SAAS;CACpB,CAAC;AACF"}
@@ -1,4 +1,4 @@
1
- import { o as Component, t as Capability } from "./capabilities-CFP-HIuY.js";
1
+ import { o as Component, t as Capability } from "./capabilities-BCtBG-ni.js";
2
2
  import { RootStore } from "atom.io/internal";
3
3
  interface AstroApplicationContext {
4
4
  /** Whether the application still represents its initial server snapshot. */
@@ -30,4 +30,4 @@ type Island<P = any> = Component<P> & {
30
30
  prepareStore?: AstroStorePreparation<P>;
31
31
  };
32
32
  export { Island as a, AstroStorePreparation as i, AstroStoreContext as n, AstroStoreFactory as r, AstroApplicationContext as t };
33
- //# sourceMappingURL=astro-shared-BkWvVZWZ.d.ts.map
33
+ //# sourceMappingURL=astro-shared-DHIpjNIG.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-shared-BkWvVZWZ.d.ts","names":[],"sources":["../src/astro-shared.ts"],"mappings":";;UAOiB;;WAEP;WACA,QAAQ;EACjB,UAAU;;EAEV,IAAI,GAAG,cAAc,kBAAkB,IAAI;;UAE3B;;EAEhB,aAAa;;EAEb,SAAS;;EAET,QAAQ;;EAER,UAAU;;KAEC,kBAAkB,IAAI,wBACjC,OAAO,GACP,SAAS,sBACL,YAAY,QAAQ;KACb,sBAAsB,IAAI,wBACrC,OAAO,WACP,OAAO,GACP,SAAS,6BACE;KACA,OAAO,WAAW,UAAU;EACvC;;EAEA,wBAAwB;;EAExB;EACA,cAAc,kBAAkB;EAChC,eAAe,sBAAsB"}
1
+ {"version":3,"file":"astro-shared-DHIpjNIG.d.ts","names":[],"sources":["../src/astro-shared.ts"],"mappings":";;UAOiB;;WAEP;WACA,QAAQ;EACjB,UAAU;;EAEV,IAAI,GAAG,cAAc,kBAAkB,IAAI;;UAE3B;;EAEhB,aAAa;;EAEb,SAAS;;EAET,QAAQ;;EAER,UAAU;;KAEC,kBAAkB,IAAI,wBACjC,OAAO,GACP,SAAS,sBACL,YAAY,QAAQ;KACb,sBAAsB,IAAI,wBACrC,OAAO,WACP,OAAO,GACP,SAAS,6BACE;KACA,OAAO,WAAW,UAAU;EACvC;;EAEA,wBAAwB;;EAExB;EACA,cAAc,kBAAkB;EAChC,eAAe,sBAAsB"}
package/dist/astro.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SpaPluginOptions } from "./vite.js";
2
- import { a as Island, i as AstroStorePreparation, n as AstroStoreContext, r as AstroStoreFactory, t as AstroApplicationContext } from "./astro-shared-BkWvVZWZ.js";
2
+ import { a as Island, i as AstroStorePreparation, n as AstroStoreContext, r as AstroStoreFactory, t as AstroApplicationContext } from "./astro-shared-DHIpjNIG.js";
3
3
  import { AstroIntegration } from "astro";
4
4
  export default function integration(options?: SpaPluginOptions): AstroIntegration;
5
5
  export type { AstroApplicationContext, AstroStoreContext, AstroStoreFactory, AstroStorePreparation, Island };
package/dist/astro.js CHANGED
@@ -3,21 +3,19 @@ import { t as spa } from "./vite-CSHoxzXU.js";
3
3
  function integration(options = {}) {
4
4
  return {
5
5
  name: `spa`,
6
- hooks: { "astro:config:setup"({ addRenderer, addMiddleware, injectScript, updateConfig }) {
6
+ hooks: { "astro:config:setup"({ config, addRenderer, addMiddleware, injectScript, updateConfig }) {
7
7
  addMiddleware({
8
8
  entrypoint: `@atom.io/spa/astro-middleware`,
9
9
  order: `pre`
10
10
  });
11
11
  injectScript(`page`, `import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`);
12
+ const resumable = config.integrations.some(({ name }) => name === `resumability`);
12
13
  addRenderer({
13
14
  name: `spa`,
14
- clientEntrypoint: `@atom.io/spa/astro-client`,
15
- serverEntrypoint: `@atom.io/spa/astro-server`
15
+ clientEntrypoint: resumable ? `@atom.io/spa/astro-resumability-client` : `@atom.io/spa/astro-client`,
16
+ serverEntrypoint: resumable ? `@atom.io/spa/astro-resumability-server` : `@atom.io/spa/astro-server`
16
17
  });
17
- updateConfig({ vite: { plugins: [spa({
18
- include: /\.spa\.[jt]sx$/,
19
- ...options
20
- })] } });
18
+ updateConfig({ vite: { plugins: [spa(options)] } });
21
19
  } }
22
20
  };
23
21
  }