@krate/runtime 0.5.0-alpha.2 → 0.5.0-alpha.3

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 (85) hide show
  1. package/dist/action-context.d.ts +49 -0
  2. package/dist/action-context.js +37 -0
  3. package/dist/action-context.test.d.ts +1 -0
  4. package/dist/action-context.test.js +47 -0
  5. package/dist/actions.d.ts +120 -0
  6. package/dist/actions.js +533 -0
  7. package/dist/actions.test.d.ts +1 -0
  8. package/dist/actions.test.js +391 -0
  9. package/dist/boundary.d.ts +121 -0
  10. package/dist/boundary.js +429 -0
  11. package/dist/class-component.d.ts +66 -0
  12. package/dist/class-component.js +633 -0
  13. package/dist/class-component.test.d.ts +1 -0
  14. package/dist/class-component.test.js +411 -0
  15. package/dist/context.d.ts +13 -0
  16. package/dist/context.js +58 -32
  17. package/dist/context.test.d.ts +1 -0
  18. package/dist/context.test.js +57 -0
  19. package/dist/derived.test.d.ts +1 -0
  20. package/dist/derived.test.js +140 -0
  21. package/dist/discrete.test.d.ts +1 -0
  22. package/dist/discrete.test.js +100 -0
  23. package/dist/dom.d.ts +55 -0
  24. package/dist/dom.js +414 -63
  25. package/dist/effects.d.ts +88 -0
  26. package/dist/effects.js +719 -0
  27. package/dist/effects.test.d.ts +1 -0
  28. package/dist/effects.test.js +485 -0
  29. package/dist/events.d.ts +58 -0
  30. package/dist/events.js +503 -0
  31. package/dist/events.test.d.ts +1 -0
  32. package/dist/events.test.js +447 -0
  33. package/dist/index.d.ts +12 -2
  34. package/dist/index.js +8 -2
  35. package/dist/jsx-types.d.ts +2 -0
  36. package/dist/krate-hydrate-lite.js +7 -1
  37. package/dist/krate-hydrate.js +7 -1
  38. package/dist/krate-runtime.js +7 -1
  39. package/dist/krate-suspense.js +2 -0
  40. package/dist/lanes.test.d.ts +1 -0
  41. package/dist/lanes.test.js +59 -0
  42. package/dist/list.d.ts +20 -0
  43. package/dist/list.js +466 -0
  44. package/dist/list.test.d.ts +1 -0
  45. package/dist/list.test.js +344 -0
  46. package/dist/optimistic-lanes.test.d.ts +1 -0
  47. package/dist/optimistic-lanes.test.js +45 -0
  48. package/dist/portal.d.ts +43 -0
  49. package/dist/portal.js +178 -0
  50. package/dist/portal.test.d.ts +1 -0
  51. package/dist/portal.test.js +99 -0
  52. package/dist/react-effects.test.d.ts +1 -0
  53. package/dist/react-effects.test.js +96 -0
  54. package/dist/react-suspense.test.d.ts +1 -0
  55. package/dist/react-suspense.test.js +194 -0
  56. package/dist/react.d.ts +132 -32
  57. package/dist/react.js +335 -81
  58. package/dist/react.test.js +12 -2
  59. package/dist/reconcile.js +13 -0
  60. package/dist/refs.d.ts +33 -0
  61. package/dist/refs.js +142 -0
  62. package/dist/refs.test.d.ts +1 -0
  63. package/dist/refs.test.js +257 -0
  64. package/dist/resource.js +20 -1
  65. package/dist/server-renderer.js +39 -1
  66. package/dist/server.d.ts +4 -1
  67. package/dist/server.js +30 -1
  68. package/dist/server.test.js +20 -0
  69. package/dist/signal-lanes.test.d.ts +1 -0
  70. package/dist/signal-lanes.test.js +32 -0
  71. package/dist/signal.d.ts +150 -1
  72. package/dist/signal.js +750 -65
  73. package/dist/slots.d.ts +18 -0
  74. package/dist/slots.js +108 -0
  75. package/dist/slots.test.d.ts +1 -0
  76. package/dist/slots.test.js +169 -0
  77. package/dist/snapshots.test.d.ts +1 -0
  78. package/dist/snapshots.test.js +208 -0
  79. package/dist/suspense-actions.test.d.ts +1 -0
  80. package/dist/suspense-actions.test.js +72 -0
  81. package/dist/suspense.d.ts +220 -0
  82. package/dist/suspense.js +901 -0
  83. package/dist/suspense.test.d.ts +1 -0
  84. package/dist/suspense.test.js +518 -0
  85. package/package.json +1 -1
@@ -0,0 +1,391 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { createSignal } from './signal.js';
3
+ import { krateOn } from './events.js';
4
+ import { ACTION_ARGS_FIELD, ServerActionError, __krateAction, __krateActionState, __krateBeginAction, __krateBindFormAction, __krateFormStatusMount, __krateOptimistic, getFormStatus, installActionForms, isServerAction, requestFormReset, setActionTransitionRunner, } from './actions.js';
5
+ function deferred() {
6
+ let resolve;
7
+ let reject;
8
+ const promise = new Promise((res, rej) => {
9
+ resolve = res;
10
+ reject = rej;
11
+ });
12
+ return { promise, resolve, reject };
13
+ }
14
+ const tick = () => new Promise((r) => setTimeout(r, 0));
15
+ function makeForm(html) {
16
+ const host = document.createElement('div');
17
+ host.innerHTML = html;
18
+ document.body.appendChild(host);
19
+ return host.querySelector('form');
20
+ }
21
+ function submit(form, submitter) {
22
+ const ev = new Event('submit', { bubbles: true, cancelable: true });
23
+ Object.defineProperty(ev, 'submitter', { value: submitter || null });
24
+ form.dispatchEvent(ev);
25
+ }
26
+ function jsonResponse(body, status = 200) {
27
+ return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
28
+ }
29
+ beforeEach(() => {
30
+ document.body.innerHTML = '';
31
+ installActionForms(document);
32
+ });
33
+ afterEach(() => {
34
+ vi.unstubAllGlobals();
35
+ setActionTransitionRunner(null);
36
+ });
37
+ describe('form actions', () => {
38
+ it('runs a client function action with the form data, without navigating, and resets after success', async () => {
39
+ const form = makeForm('<form><input name="title" value="initial"><button type="submit">Go</button></form>');
40
+ const input = form.querySelector('input');
41
+ input.value = 'typed';
42
+ const gate = deferred();
43
+ const seen = [];
44
+ __krateBindFormAction(form, () => async (fd) => {
45
+ seen.push(String(fd.get('title')));
46
+ await gate.promise;
47
+ });
48
+ submit(form);
49
+ expect(seen).toEqual(['typed']);
50
+ expect(form.getAttribute('data-krate-action-pending')).toBe('1');
51
+ expect(getFormStatus(form).pending).toBe(true);
52
+ expect(input.value).toBe('typed');
53
+ gate.resolve();
54
+ await tick();
55
+ expect(getFormStatus(form).pending).toBe(false);
56
+ expect(form.hasAttribute('data-krate-action-pending')).toBe(false);
57
+ expect(input.value).toBe('initial');
58
+ });
59
+ it('keeps fields when the action fails and reports the error', async () => {
60
+ const form = makeForm('<form><input name="a" value="x"></form>');
61
+ const input = form.querySelector('input');
62
+ input.value = 'kept';
63
+ const errors = [];
64
+ form.addEventListener('krate:action-error', (e) => {
65
+ errors.push(e.detail.error);
66
+ e.preventDefault();
67
+ });
68
+ __krateBindFormAction(form, () => async () => {
69
+ throw new Error('boom');
70
+ });
71
+ submit(form);
72
+ await tick();
73
+ expect(errors[0].message).toBe('boom');
74
+ expect(input.value).toBe('kept');
75
+ expect(getFormStatus(form).pending).toBe(false);
76
+ });
77
+ it('drops the no-JS POST target once a function is bound', () => {
78
+ const form = makeForm('<form action="/__krate/action/a1?__krate_args=%5B0%5D" method="post" data-krate-action><button formaction="/x" formmethod="post">b</button></form>');
79
+ const button = form.querySelector('button');
80
+ __krateBindFormAction(form, () => () => { });
81
+ __krateBindFormAction(button, () => () => { });
82
+ expect(form.hasAttribute('action') || form.hasAttribute('method') || form.hasAttribute('data-krate-action')).toBe(false);
83
+ expect(button.hasAttribute('formaction') || button.hasAttribute('formmethod')).toBe(false);
84
+ });
85
+ it('prefers a submit button formAction over the form action', async () => {
86
+ const form = makeForm('<form><button type="submit" name="op" value="b">B</button></form>');
87
+ const button = form.querySelector('button');
88
+ const calls = [];
89
+ __krateBindFormAction(form, () => () => calls.push('form'));
90
+ __krateBindFormAction(button, () => (fd) => calls.push('button:' + fd.get('op')));
91
+ submit(form, button);
92
+ await tick();
93
+ expect(calls).toEqual(['button:b']);
94
+ });
95
+ it('leaves forms without an action and native formaction buttons alone', () => {
96
+ const form = makeForm('<form action="/search"><button formaction="/other">x</button></form>');
97
+ const ev = new Event('submit', { bubbles: true, cancelable: true });
98
+ form.dispatchEvent(ev);
99
+ expect(ev.defaultPrevented).toBe(false);
100
+ });
101
+ it('does not run the action when onSubmit prevented the default', async () => {
102
+ const form = makeForm('<form></form>');
103
+ const fn = vi.fn();
104
+ __krateBindFormAction(form, () => fn);
105
+ form.addEventListener('submit', (e) => e.preventDefault());
106
+ submit(form);
107
+ await tick();
108
+ expect(fn).not.toHaveBeenCalled();
109
+ });
110
+ it('runs onSubmit through the React event system first; preventDefault cancels the action', async () => {
111
+ const form = makeForm('<form><button>Go</button></form>');
112
+ const order = [];
113
+ let cancel = true;
114
+ krateOn(form, 'onSubmit', (e) => {
115
+ order.push('onSubmit');
116
+ if (cancel)
117
+ e.preventDefault();
118
+ });
119
+ __krateBindFormAction(form, () => () => order.push('action'));
120
+ submit(form);
121
+ await tick();
122
+ expect(order).toEqual(['onSubmit']);
123
+ cancel = false;
124
+ submit(form);
125
+ await tick();
126
+ expect(order).toEqual(['onSubmit', 'onSubmit', 'action']);
127
+ });
128
+ it('restores controlled fields after the reset', async () => {
129
+ const form = makeForm('<form><input name="c" value="" data-kattr-value="k:1"><input name="u" value="d"></form>');
130
+ const [controlled, uncontrolled] = Array.from(form.querySelectorAll('input'));
131
+ controlled.value = 'signal value';
132
+ uncontrolled.value = 'typed';
133
+ __krateBindFormAction(form, () => async () => { });
134
+ submit(form);
135
+ await tick();
136
+ expect(controlled.value).toBe('signal value');
137
+ expect(uncontrolled.value).toBe('d');
138
+ });
139
+ it('requestFormReset waits for the pending action', async () => {
140
+ const form = makeForm('<form><input name="a" value="d"></form>');
141
+ const input = form.querySelector('input');
142
+ const gate = deferred();
143
+ __krateBindFormAction(form, () => async () => {
144
+ await gate.promise;
145
+ throw new Error('fail');
146
+ });
147
+ form.addEventListener('krate:action-error', (e) => e.preventDefault());
148
+ input.value = 'typed';
149
+ submit(form);
150
+ requestFormReset(form);
151
+ expect(input.value).toBe('typed');
152
+ gate.resolve();
153
+ await tick();
154
+ expect(input.value).toBe('d');
155
+ });
156
+ it('posts server action forms as multipart and does not reload', async () => {
157
+ const fetchMock = vi.fn(async () => jsonResponse({ ok: true, result: { saved: true } }));
158
+ vi.stubGlobal('fetch', fetchMock);
159
+ const form = makeForm('<form action="/__krate/action/a1" method="post" data-krate-action><input name="text" value="hi"></form>');
160
+ submit(form);
161
+ await tick();
162
+ await tick();
163
+ expect(fetchMock).toHaveBeenCalledTimes(1);
164
+ const [url, init] = fetchMock.mock.calls[0];
165
+ expect(url).toContain('/__krate/action/a1');
166
+ expect(init.headers['x-krate-action']).toBe('fetch');
167
+ expect(init.body).toBeInstanceOf(FormData);
168
+ expect(init.body.get('text')).toBe('hi');
169
+ expect(getFormStatus(form).pending).toBe(false);
170
+ });
171
+ });
172
+ describe('useFormStatus', () => {
173
+ it('is scoped to the parent form of the component', async () => {
174
+ document.body.innerHTML =
175
+ '<form id="a"><button id="ba">A</button></form><form id="b"><button id="bb">B</button></form>';
176
+ const formA = document.getElementById('a');
177
+ const statusA = [];
178
+ const pendingB = [];
179
+ __krateFormStatusMount(document.getElementById('ba'), { status: (s) => statusA.push(s) });
180
+ __krateFormStatusMount(document.getElementById('bb'), { pending: (p) => pendingB.push(p) });
181
+ const gate = deferred();
182
+ const action = async () => {
183
+ await gate.promise;
184
+ };
185
+ __krateBindFormAction(formA, () => action);
186
+ submit(formA);
187
+ const live = statusA[statusA.length - 1];
188
+ expect(live.pending).toBe(true);
189
+ expect(live.method).toBe('get');
190
+ expect(live.action).toBe(action);
191
+ expect(live.data).toBeInstanceOf(FormData);
192
+ expect(pendingB).toEqual([false]);
193
+ gate.resolve();
194
+ await tick();
195
+ expect(statusA[statusA.length - 1].pending).toBe(false);
196
+ expect(pendingB).toEqual([false]);
197
+ });
198
+ it('does not report the form the component itself renders', () => {
199
+ document.body.innerHTML = '<form id="self"></form>';
200
+ const seen = [];
201
+ __krateFormStatusMount(document.getElementById('self'), { pending: (p) => seen.push(p) });
202
+ expect(seen).toEqual([]);
203
+ });
204
+ });
205
+ describe('useActionState', () => {
206
+ it('queues calls sequentially and threads the previous state', async () => {
207
+ const [state, setState] = createSignal(0);
208
+ const [pending, setPending] = createSignal(false);
209
+ const gates = [deferred(), deferred(), deferred()];
210
+ const log = [];
211
+ let call = 0;
212
+ const dispatch = __krateActionState(async (prev, payload) => {
213
+ const i = call++;
214
+ log.push(`start ${i} prev=${prev} payload=${payload}`);
215
+ await gates[i].promise;
216
+ return prev + payload;
217
+ }, state, setState, setPending);
218
+ dispatch(1);
219
+ dispatch(10);
220
+ dispatch(100);
221
+ expect(pending()).toBe(true);
222
+ await tick();
223
+ expect(log).toEqual(['start 0 prev=0 payload=1']);
224
+ gates[0].resolve();
225
+ await tick();
226
+ expect(state()).toBe(1);
227
+ expect(log[1]).toBe('start 1 prev=1 payload=10');
228
+ gates[1].resolve();
229
+ await tick();
230
+ gates[2].resolve();
231
+ await tick();
232
+ expect(state()).toBe(111);
233
+ expect(pending()).toBe(false);
234
+ });
235
+ it('cancels queued calls when an action throws', async () => {
236
+ const [state, setState] = createSignal('a');
237
+ const [pending, setPending] = createSignal(false);
238
+ const runs = [];
239
+ const errors = [];
240
+ const onErr = (e) => {
241
+ errors.push(e.detail.error);
242
+ e.preventDefault();
243
+ };
244
+ document.addEventListener('krate:action-error', onErr);
245
+ const dispatch = __krateActionState(async (prev, payload) => {
246
+ runs.push(String(payload));
247
+ if (payload === 'bad')
248
+ throw new Error('nope');
249
+ return prev + payload;
250
+ }, state, setState, setPending);
251
+ dispatch('bad');
252
+ dispatch('next');
253
+ await tick();
254
+ await tick();
255
+ document.removeEventListener('krate:action-error', onErr);
256
+ expect(runs).toEqual(['bad']);
257
+ expect(state()).toBe('a');
258
+ expect(pending()).toBe(false);
259
+ expect(errors[0].message).toBe('nope');
260
+ });
261
+ it('works as a form action and resets the form after success', async () => {
262
+ const [state, setState] = createSignal([]);
263
+ const [, setPending] = createSignal(false);
264
+ const form = makeForm('<form><input name="todo" value=""></form>');
265
+ const input = form.querySelector('input');
266
+ const dispatch = __krateActionState(async (prev, fd) => [...prev, String(fd.get('todo'))], state, setState, setPending);
267
+ __krateBindFormAction(form, () => dispatch);
268
+ input.value = 'one';
269
+ submit(form);
270
+ await tick();
271
+ await tick();
272
+ expect(state()).toEqual(['one']);
273
+ expect(input.value).toBe('');
274
+ });
275
+ it('sends the previous state to a server action as the leading argument', async () => {
276
+ const fetchMock = vi.fn(async () => jsonResponse({ ok: true, result: 5 }));
277
+ vi.stubGlobal('fetch', fetchMock);
278
+ const [state, setState] = createSignal(4);
279
+ const [, setPending] = createSignal(false);
280
+ const dispatch = __krateActionState(__krateAction('a9'), state, setState, setPending);
281
+ const fd = new FormData();
282
+ fd.set('n', '1');
283
+ dispatch(fd);
284
+ await tick();
285
+ await tick();
286
+ const init = fetchMock.mock.calls[0][1];
287
+ const body = init.body;
288
+ expect(JSON.parse(String(body.get(ACTION_ARGS_FIELD)))).toEqual([4]);
289
+ expect(body.get('n')).toBe('1');
290
+ expect(state()).toBe(5);
291
+ });
292
+ });
293
+ describe('useOptimistic', () => {
294
+ it('applies updates while an action is pending and reverts to the latest base', async () => {
295
+ const [base, setBase] = createSignal(['a']);
296
+ const [value, setValue] = createSignal(base());
297
+ const add = __krateOptimistic(base, setValue, (s, n) => [...s, n]);
298
+ const end = __krateBeginAction();
299
+ add('b');
300
+ add('c');
301
+ expect(value()).toEqual(['a', 'b', 'c']);
302
+ setBase(['a', 'x']);
303
+ await tick();
304
+ expect(value()).toEqual(['a', 'x', 'b', 'c']);
305
+ end();
306
+ expect(value()).toEqual(['a', 'x']);
307
+ });
308
+ it('drops an update made outside any action', async () => {
309
+ const [base] = createSignal(1);
310
+ const [value, setValue] = createSignal(base());
311
+ const add = __krateOptimistic(base, setValue);
312
+ add(2);
313
+ expect(value()).toBe(2);
314
+ await tick();
315
+ expect(value()).toBe(1);
316
+ });
317
+ it('keeps updates for a form action until it settles', async () => {
318
+ const [base, setBase] = createSignal(0);
319
+ const [value, setValue] = createSignal(base());
320
+ const add = __krateOptimistic(base, setValue, (s, n) => s + n);
321
+ const gate = deferred();
322
+ const form = makeForm('<form></form>');
323
+ __krateBindFormAction(form, () => async () => {
324
+ add(5);
325
+ await gate.promise;
326
+ setBase(1);
327
+ });
328
+ submit(form);
329
+ await tick();
330
+ expect(value()).toBe(5);
331
+ gate.resolve();
332
+ await tick();
333
+ await tick();
334
+ expect(value()).toBe(1);
335
+ });
336
+ it('uses a custom transition runner when one is installed', async () => {
337
+ const runs = [];
338
+ setActionTransitionRunner(async (fn) => {
339
+ runs.push(1);
340
+ const end = __krateBeginAction();
341
+ try {
342
+ return await fn();
343
+ }
344
+ finally {
345
+ end();
346
+ }
347
+ });
348
+ const form = makeForm('<form></form>');
349
+ __krateBindFormAction(form, () => async () => { });
350
+ submit(form);
351
+ await tick();
352
+ expect(runs).toEqual([1]);
353
+ });
354
+ });
355
+ describe('server action proxies', () => {
356
+ it('sends JSON args and returns the result', async () => {
357
+ const fetchMock = vi.fn(async () => jsonResponse({ ok: true, result: { n: 2 } }));
358
+ vi.stubGlobal('fetch', fetchMock);
359
+ const save = __krateAction('a1');
360
+ expect(isServerAction(save)).toBe(true);
361
+ expect(save.actionUrl).toBe('/__krate/action/a1');
362
+ await expect(save({ n: 1 })).resolves.toEqual({ n: 2 });
363
+ const [, init] = fetchMock.mock.calls[0];
364
+ expect(JSON.parse(String(init.body))).toEqual({ args: [{ n: 1 }] });
365
+ expect(init.headers['content-type']).toBe('application/json');
366
+ });
367
+ it('keeps bound arguments ahead of the call arguments', async () => {
368
+ const fetchMock = vi.fn(async () => jsonResponse({ ok: true, result: null }));
369
+ vi.stubGlobal('fetch', fetchMock);
370
+ const bound = __krateAction('a2').bind(null, 'id-7');
371
+ expect(isServerAction(bound)).toBe(true);
372
+ await bound('x');
373
+ const [, init] = fetchMock.mock.calls[0];
374
+ expect(JSON.parse(String(init.body))).toEqual({ args: ['id-7', 'x'] });
375
+ });
376
+ it('rejects with the structured error envelope', async () => {
377
+ vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({ ok: false, error: { message: 'An error occurred', digest: 'd1' } }, 500)));
378
+ const err = (await __krateAction('a3')().catch((e) => e));
379
+ expect(err).toBeInstanceOf(ServerActionError);
380
+ expect(err.message).toBe('An error occurred');
381
+ expect(err.digest).toBe('d1');
382
+ expect(err.status).toBe(500);
383
+ });
384
+ it('follows a redirect from the response', async () => {
385
+ vi.stubGlobal('fetch', vi.fn(async () => jsonResponse({ ok: true, result: null, redirect: '/next' })));
386
+ const nav = vi.fn();
387
+ vi.stubGlobal('navigate', nav);
388
+ await __krateAction('a4')();
389
+ expect(nav).toHaveBeenCalledWith('/next');
390
+ });
391
+ });
@@ -0,0 +1,121 @@
1
+ /** Second argument of componentDidCatch. */
2
+ export interface ErrorInfo {
3
+ componentStack: string;
4
+ }
5
+ /**
6
+ * Intercepts a value thrown by a descendant of the owner that installed it.
7
+ * Returns true when the value was handled (the walk stops), false to let the
8
+ * next boundary up see it.
9
+ */
10
+ export type BoundaryHandler = (thrown: unknown, info: ErrorInfo, source: Owner) => boolean;
11
+ /**
12
+ * dormant: registered, not running (hidden branch, unmounted subtree);
13
+ * mounted: setup ran and its effects are live;
14
+ * disposed: removed for good (page teardown).
15
+ */
16
+ export type OwnerState = 'dormant' | 'mounted' | 'disposed';
17
+ export interface Owner {
18
+ readonly id: string;
19
+ /** Component name, used for component stacks. */
20
+ readonly name: string;
21
+ readonly parent: Owner | null;
22
+ /** Owner whose render created this one's element (null when unknown). */
23
+ readonly creator: Owner | null;
24
+ readonly children: Owner[];
25
+ /** Pre-order registration index; orders siblings. */
26
+ readonly order: number;
27
+ state: OwnerState;
28
+ /** Error/Suspense interception for descendants. */
29
+ boundary: BoundaryHandler | null;
30
+ /** Kept dormant after a caught error until its boundary renders again. */
31
+ blocked: boolean;
32
+ /** Boundary flag: an error was caught and the boundary has not re-rendered since. */
33
+ inError: boolean;
34
+ /** Conditional slot and branch ('c' or 'a') this owner was rendered in. */
35
+ readonly cond: string;
36
+ readonly branch: string;
37
+ /** Re-runnable body (the component's hydration scope). */
38
+ readonly setup: (() => void) | null;
39
+ /** Free-form per-owner storage (class instances live here). */
40
+ readonly data: Record<string, unknown>;
41
+ }
42
+ /** The owner whose code is running, or null. */
43
+ export declare function getOwner(): Owner | null;
44
+ /**
45
+ * Creates a mounted owner under parent (default: the current owner). Use it for
46
+ * regions created at runtime; run code in it with runWithOwner.
47
+ */
48
+ export declare function createOwner(name: string, parent?: Owner | null): Owner;
49
+ /**
50
+ * Runs fn with owner current: effects and cleanups it creates belong to the
51
+ * owner and errors it throws are routed to the owner's boundaries. Returns
52
+ * fn's value, or undefined when it threw or the owner is not mounted.
53
+ */
54
+ export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T | undefined;
55
+ /** Registers fn to run when owner unmounts (immediately if it already has). */
56
+ export declare function onOwnerCleanup(owner: Owner, fn: () => void): void;
57
+ /** Installs a boundary handler on owner (null removes it). */
58
+ export declare function setBoundary(owner: Owner, handler: BoundaryHandler | null): void;
59
+ /** React-style component stack from source up to the root. */
60
+ export declare function componentStack(source: Owner | null): string;
61
+ /**
62
+ * Routes a thrown value from source to the nearest mounted ancestor boundary
63
+ * that handles it. An owner never catches its own errors: a boundary's own
64
+ * render or lifecycle failure goes to the boundary above it, as in React.
65
+ * Unhandled errors are reported and the failing subtree is unmounted.
66
+ */
67
+ export declare function handleError(thrown: unknown, source?: Owner | null): void;
68
+ /**
69
+ * Unmounts owner and its subtree: cleanups run parent-first (React calls
70
+ * componentWillUnmount top-down) and the owners become dormant, so they can
71
+ * be mounted again by running their setup.
72
+ */
73
+ export declare function unmountOwner(owner: Owner): void;
74
+ /** Mounts a dormant owner (and its mountable descendants). */
75
+ export declare function mountOwner(owner: Owner): void;
76
+ /** Unmounts every child of owner (an error boundary dropping its subtree). */
77
+ export declare function unmountChildren(owner: Owner): void;
78
+ /**
79
+ * Mounts owner's dormant children that their conditional branch allows,
80
+ * clearing the block a caught error put on them.
81
+ */
82
+ export declare function remountChildren(owner: Owner): void;
83
+ /** Compact registration metadata emitted by the compiler. */
84
+ export interface OwnMeta {
85
+ /** Parent owner id (nearest enclosing hydrated component). */
86
+ p?: string;
87
+ /** Component name. */
88
+ n?: string;
89
+ /** Conditional slot id and branch the component renders in. */
90
+ c?: string;
91
+ b?: string;
92
+ /** Owner id of the component whose render created this element. */
93
+ k?: string;
94
+ }
95
+ /**
96
+ * Hydration entry point: the compiler wraps each component's hydration scope
97
+ * in `__krateOwn(id, meta, setup)` on pages that use the owner tree. The setup
98
+ * runs now when the component is visible, or later when its branch is shown.
99
+ */
100
+ export declare function __krateOwn(id: string, meta: OwnMeta | null, setup: () => void): void;
101
+ /** Owner registered under id, if any (tests, devtools). */
102
+ export declare function __krateOwner(id: string): Owner | null;
103
+ /**
104
+ * Called by the hydration bootstrap before a conditional swaps branches: the
105
+ * outgoing branch's owners unmount while their DOM is still attached.
106
+ */
107
+ export declare function __krateCondPre(id: string, show: boolean): void;
108
+ /** Called after a conditional swapped: the incoming branch's owners mount. */
109
+ export declare function __krateCondPost(id: string, show: boolean): void;
110
+ /**
111
+ * Called by the hydration bootstrap's __safe wrapper. Routes an error thrown
112
+ * while a component's hydration scope runs; nodes outside the document (a
113
+ * hidden conditional branch React would not have rendered) are ignored.
114
+ */
115
+ export declare function __krateOnError(err: unknown, node?: Node | null): boolean;
116
+ /**
117
+ * Reports whether the error being handled was thrown in the commit phase
118
+ * (effects, lifecycles). React retries a failed render once, but not a
119
+ * failed commit.
120
+ */
121
+ export declare function inCommitPhaseError(): boolean;