@krate/runtime 0.5.0-beta.1 → 0.5.0-beta.2

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 (134) hide show
  1. package/dist/actions.js +2 -1
  2. package/dist/assets-static.d.ts +5 -0
  3. package/dist/assets-static.js +31 -0
  4. package/dist/boundary.d.ts +12 -0
  5. package/dist/boundary.js +53 -13
  6. package/dist/cache-adapter.d.ts +113 -0
  7. package/dist/cache-adapter.js +217 -0
  8. package/dist/cache-adapter.test.d.ts +1 -0
  9. package/dist/cache-adapter.test.js +244 -0
  10. package/dist/cache-redis.d.ts +27 -0
  11. package/dist/cache-redis.js +110 -0
  12. package/dist/cache-scope.d.ts +25 -9
  13. package/dist/cache-scope.js +60 -12
  14. package/dist/cache.d.ts +1 -0
  15. package/dist/cache.js +3 -3
  16. package/dist/class-component.js +6 -0
  17. package/dist/class-component.test.js +53 -2
  18. package/dist/dev-overlay.js +10 -10
  19. package/dist/dom.d.ts +8 -0
  20. package/dist/dom.js +28 -0
  21. package/dist/effect-errors.test.d.ts +1 -0
  22. package/dist/effect-errors.test.js +163 -0
  23. package/dist/effects.d.ts +8 -0
  24. package/dist/effects.js +13 -0
  25. package/dist/error-overlay.js +4 -4
  26. package/dist/handler-html.d.ts +63 -0
  27. package/dist/handler-html.js +285 -0
  28. package/dist/handler-html.test.d.ts +1 -0
  29. package/dist/handler-html.test.js +256 -0
  30. package/dist/handler-routing.d.ts +83 -0
  31. package/dist/handler-routing.js +579 -0
  32. package/dist/handler-routing.test.d.ts +1 -0
  33. package/dist/handler-routing.test.js +99 -0
  34. package/dist/handler-segments.d.ts +43 -0
  35. package/dist/handler-segments.js +115 -0
  36. package/dist/handler-segments.test.d.ts +1 -0
  37. package/dist/handler-segments.test.js +217 -0
  38. package/dist/head-tags.d.ts +51 -0
  39. package/dist/head-tags.js +329 -0
  40. package/dist/head-tags.test.d.ts +1 -0
  41. package/dist/head-tags.test.js +131 -0
  42. package/dist/highlight-bind.d.ts +42 -0
  43. package/dist/highlight-bind.js +176 -0
  44. package/dist/highlight-bind.test.d.ts +1 -0
  45. package/dist/highlight-bind.test.js +124 -0
  46. package/dist/highlight.d.ts +93 -0
  47. package/dist/highlight.js +426 -0
  48. package/dist/highlight.test.d.ts +1 -0
  49. package/dist/highlight.test.js +56 -0
  50. package/dist/hints.d.ts +19 -0
  51. package/dist/hints.js +97 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/index.js +2 -0
  54. package/dist/jsx-types.d.ts +11 -0
  55. package/dist/krate-core.js +1 -1
  56. package/dist/krate-dev.js +10 -10
  57. package/dist/krate-f-actions.js +1 -1
  58. package/dist/krate-f-classes.js +5 -5
  59. package/dist/krate-f-highlight.js +2 -0
  60. package/dist/krate-f-list.js +1 -1
  61. package/dist/krate-f-navigation.js +2 -0
  62. package/dist/krate-f-router.js +1 -1
  63. package/dist/krate-features.json +254 -0
  64. package/dist/krate-hydrate-lite.js +5 -5
  65. package/dist/krate-hydrate.js +5 -5
  66. package/dist/krate-runtime.js +5 -5
  67. package/dist/list.js +4 -2
  68. package/dist/metadata-routes.d.ts +75 -0
  69. package/dist/metadata-routes.js +76 -0
  70. package/dist/metadata.d.ts +222 -0
  71. package/dist/metadata.js +452 -0
  72. package/dist/metadata.test.d.ts +1 -0
  73. package/dist/metadata.test.js +167 -0
  74. package/dist/navigation-server.d.ts +27 -0
  75. package/dist/navigation-server.js +90 -0
  76. package/dist/navigation.d.ts +37 -0
  77. package/dist/navigation.js +195 -0
  78. package/dist/navigation.test.d.ts +1 -0
  79. package/dist/navigation.test.js +130 -0
  80. package/dist/node-server.d.ts +22 -0
  81. package/dist/node-server.js +436 -0
  82. package/dist/node-server.test.d.ts +1 -0
  83. package/dist/node-server.test.js +492 -0
  84. package/dist/og-files.d.ts +2 -0
  85. package/dist/og-files.js +19 -0
  86. package/dist/og.d.ts +56 -0
  87. package/dist/og.js +156 -0
  88. package/dist/react.d.ts +47 -0
  89. package/dist/react.js +59 -1
  90. package/dist/react19.test.d.ts +1 -0
  91. package/dist/react19.test.js +176 -0
  92. package/dist/request-context.d.ts +23 -0
  93. package/dist/request-context.js +45 -0
  94. package/dist/resp.d.ts +55 -0
  95. package/dist/resp.js +239 -0
  96. package/dist/router-layout.test.js +70 -0
  97. package/dist/router-nav.test.js +27 -0
  98. package/dist/router.js +59 -4
  99. package/dist/segmented-lru.d.ts +19 -0
  100. package/dist/segmented-lru.js +87 -0
  101. package/dist/server-async.test.js +23 -1
  102. package/dist/server-handler.d.ts +165 -0
  103. package/dist/server-handler.js +1826 -0
  104. package/dist/server-handler.test.d.ts +1 -0
  105. package/dist/server-handler.test.js +522 -0
  106. package/dist/server-highlight.test.d.ts +1 -0
  107. package/dist/server-highlight.test.js +32 -0
  108. package/dist/server-renderer.js +146 -788
  109. package/dist/server-renderer.test.d.ts +1 -0
  110. package/dist/server-renderer.test.js +266 -0
  111. package/dist/server.d.ts +12 -1
  112. package/dist/server.js +42 -6
  113. package/dist/sha256.d.ts +1 -0
  114. package/dist/sha256.js +66 -0
  115. package/dist/sha256.test.d.ts +1 -0
  116. package/dist/sha256.test.js +13 -0
  117. package/dist/shared-isr.d.ts +31 -0
  118. package/dist/shared-isr.js +142 -0
  119. package/dist/signal.js +63 -8
  120. package/dist/ssr-core-behavior.test.d.ts +1 -0
  121. package/dist/ssr-core-behavior.test.js +620 -0
  122. package/dist/ssr-core.d.ts +175 -0
  123. package/dist/ssr-core.js +940 -0
  124. package/dist/ssr-core.test.d.ts +1 -0
  125. package/dist/ssr-core.test.js +324 -0
  126. package/dist/static-memory.d.ts +3 -0
  127. package/dist/static-memory.js +47 -0
  128. package/dist/static-memory.test.d.ts +1 -0
  129. package/dist/static-memory.test.js +26 -0
  130. package/dist/test-redis.d.ts +12 -0
  131. package/dist/test-redis.js +131 -0
  132. package/dist/use-id.d.ts +8 -0
  133. package/dist/use-id.js +40 -0
  134. package/package.json +29 -1
@@ -1,6 +1,6 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { createEffect, createSignal, disposeAll } from './signal.js';
3
- import { __krateOwn, __krateOwner, __krateCondPre, __krateCondPost, __krateOnError } from './boundary.js';
2
+ import { createEffect, createSignal, disposeAll, krateDisposeExcept, krateEnterScope, krateLeaveScope } from './signal.js';
3
+ import { __krateOwn, __krateOwner, __krateCondPre, __krateCondPost, __krateOnError, handleError } from './boundary.js';
4
4
  import { __krateClass } from './class-component.js';
5
5
  // Lets the effect flush, the render phase and the commit phase run.
6
6
  const settle = () => new Promise((r) => setTimeout(r, 0));
@@ -385,6 +385,31 @@ describe('error boundaries', () => {
385
385
  await settle();
386
386
  expect(log2.filter((l) => l.includes('gDSFE'))).toEqual(['O gDSFE fallback broke']);
387
387
  });
388
+ it('does not catch an error raised while the boundary already shows its fallback', async () => {
389
+ const log = [];
390
+ boundary('Outer', {}, log, 'Outer');
391
+ boundary('Inner', { p: 'Outer' }, log, 'Inner');
392
+ const [fail, setFail] = createSignal(false);
393
+ __krateOwn('Page', { p: 'Inner', n: 'Page' }, () => {
394
+ createEffect(() => {
395
+ if (fail())
396
+ throw new Error('page failed');
397
+ });
398
+ });
399
+ await settle();
400
+ setFail(true);
401
+ await settle();
402
+ // (An update-phase error runs getDerivedStateFromError twice, as in React 18.)
403
+ expect(new Set(log.filter((l) => l.includes('gDSFE')))).toEqual(new Set(['Inner gDSFE page failed']));
404
+ expect(__krateOwner('Inner').inError).toBe(true);
405
+ // The fallback is the boundary's own render output: what it throws is not
406
+ // the boundary's to catch.
407
+ handleError(new Error('fallback failed'), __krateOwner('Page'));
408
+ await settle();
409
+ const caught = log.filter((l) => l.includes('gDSFE'));
410
+ expect(caught).toContain('Outer gDSFE fallback failed');
411
+ expect(caught).not.toContain('Inner gDSFE fallback failed');
412
+ });
388
413
  it('reports uncaught errors and unmounts only the failing component', async () => {
389
414
  const spy = vi.spyOn(console, 'error').mockImplementation(() => { });
390
415
  let siblingRan = false;
@@ -409,3 +434,29 @@ describe('error boundaries', () => {
409
434
  expect(routed).toBe(false);
410
435
  });
411
436
  });
437
+ describe('owner teardown by route scope', () => {
438
+ it('keeps the owners of a kept layout and drops the page owners', async () => {
439
+ const log = [];
440
+ krateEnterScope('_lroot_');
441
+ __krateOwn('Layout', { n: 'Layout' }, () => {
442
+ classScope({}, {}, { componentWillUnmount: () => log.push('layout unmount') });
443
+ });
444
+ krateLeaveScope();
445
+ __krateOwn('Page', { p: 'Layout', n: 'Page' }, () => {
446
+ classScope({}, {}, { componentWillUnmount: () => log.push('page unmount') });
447
+ });
448
+ await settle();
449
+ expect(__krateOwner('Page').state).toBe('mounted');
450
+ // A soft navigation keeps the layout: only page-scope owners go.
451
+ krateDisposeExcept(['_lroot_']);
452
+ expect(log).toEqual(['page unmount']);
453
+ expect(__krateOwner('Page')).toBeNull();
454
+ const layout = __krateOwner('Layout');
455
+ expect(layout.state).toBe('mounted');
456
+ expect(layout.children).toHaveLength(0);
457
+ // A full teardown drops everything.
458
+ disposeAll();
459
+ expect(log).toEqual(['page unmount', 'layout unmount']);
460
+ expect(__krateOwner('Layout')).toBeNull();
461
+ });
462
+ });
@@ -194,11 +194,11 @@ const STYLE = `
194
194
  :host {
195
195
  --red: #f87171;
196
196
  --green: #34d399;
197
- --bg: #111114;
198
- --bg-2: #17171c;
199
- --line: #2a2a31;
200
- --fg: #e5e7eb;
201
- --muted: #9ca3af;
197
+ --bg: #111111;
198
+ --bg-2: #171717;
199
+ --line: #2a2a2a;
200
+ --fg: #e5e5e5;
201
+ --muted: #a3a3a3;
202
202
  }
203
203
 
204
204
  /* toolbar */
@@ -245,7 +245,7 @@ const STYLE = `
245
245
  /* overlay */
246
246
  .overlay {
247
247
  position: fixed; inset: 0; z-index: 2147483000;
248
- background: rgba(9, 9, 11, 0.72); backdrop-filter: blur(6px);
248
+ background: rgba(10, 10, 10, 0.72); backdrop-filter: blur(6px);
249
249
  display: flex; align-items: flex-start; justify-content: center;
250
250
  padding: 4vh 16px; overflow: auto;
251
251
  font: 13px/1.5 "SF Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
@@ -269,9 +269,9 @@ const STYLE = `
269
269
  border-radius: 9px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 12px;
270
270
  transition: color .15s ease, background .15s ease, border-color .15s ease;
271
271
  }
272
- .btn:hover { color: var(--fg); background: rgba(255,255,255,.06); border-color: #44444f; }
272
+ .btn:hover { color: var(--fg); background: rgba(255,255,255,.06); border-color: #444444; }
273
273
  .list { padding: 6px 0; }
274
- .diag { padding: 14px 18px; border-bottom: 1px solid #1f1f26; }
274
+ .diag { padding: 14px 18px; border-bottom: 1px solid #1f1f1f; }
275
275
  .diag:last-child { border-bottom: none; }
276
276
  .actions { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
277
277
  .loc {
@@ -282,10 +282,10 @@ const STYLE = `
282
282
  .loc:hover { text-decoration: underline; }
283
283
  .msg { color: #f3f4f6; white-space: pre-wrap; word-break: break-word; }
284
284
  .frame {
285
- margin-top: 10px; background: #0b0b0e; border: 1px solid #26262e;
285
+ margin-top: 10px; background: #0b0b0b; border: 1px solid #262626;
286
286
  border-radius: 7px; padding: 8px 10px; overflow-x: auto; white-space: pre;
287
287
  }
288
- .frame .src { color: #cbd5e1; }
288
+ .frame .src { color: #d4d4d4; }
289
289
  .frame .caret { color: var(--red); }
290
290
  .hint { margin-top: 8px; color: #a3e635; }
291
291
  .stack {
package/dist/dom.d.ts CHANGED
@@ -47,6 +47,14 @@ export declare function insert(parent: Node, value: unknown, startMarker: Node):
47
47
  * removed. Other inline styles are left alone.
48
48
  */
49
49
  export declare function krateApplyStyle(el: Element, style: Record<string, unknown>): void;
50
+ /**
51
+ * Sets a prop of a custom element the way React 19 does: objects, arrays and
52
+ * functions are properties, as is any value for a property the element
53
+ * already defines. Returns false when the prop is an attribute. An element
54
+ * that is not defined yet gets the property again once it is, so a class
55
+ * accessor is not shadowed by the early own property.
56
+ */
57
+ export declare function krateCustomProp(el: Element, key: string, value: unknown): boolean;
50
58
  /**
51
59
  * Applies a spread props object (`<input {...field} />`) to el and re-applies
52
60
  * it when the state `get` reads changes: attributes, form state, styles and
package/dist/dom.js CHANGED
@@ -189,7 +189,35 @@ export function krateApplyStyle(el, style) {
189
189
  }
190
190
  appliedStyles.set(el, next);
191
191
  }
192
+ /**
193
+ * Sets a prop of a custom element the way React 19 does: objects, arrays and
194
+ * functions are properties, as is any value for a property the element
195
+ * already defines. Returns false when the prop is an attribute. An element
196
+ * that is not defined yet gets the property again once it is, so a class
197
+ * accessor is not shadowed by the early own property.
198
+ */
199
+ export function krateCustomProp(el, key, value) {
200
+ if (el.localName.indexOf('-') < 1 || key.indexOf('-') >= 0)
201
+ return false;
202
+ const complex = (typeof value === 'object' && value !== null) || typeof value === 'function';
203
+ if (!complex && !(key in el))
204
+ return false;
205
+ el[key] = value;
206
+ const reg = typeof customElements !== 'undefined' ? customElements : null;
207
+ if (complex && reg && !reg.get(el.localName) && typeof reg.whenDefined === 'function') {
208
+ void reg.whenDefined(el.localName).then(() => {
209
+ const rec = el;
210
+ delete rec[key];
211
+ rec[key] = value;
212
+ });
213
+ }
214
+ return true;
215
+ }
192
216
  function setAttr(el, key, value) {
217
+ if (el.localName.indexOf('-') > 0 && key !== 'class' && key !== 'className' && key !== 'style' && key !== 'ref' && key !== 'key' && key !== 'children' && !key.startsWith('on')) {
218
+ if (krateCustomProp(el, key, value))
219
+ return;
220
+ }
193
221
  if (key === 'class' || key === 'className') {
194
222
  // Guard against false/null/undefined before String() conversion.
195
223
  const next = value === false || value === null || value === undefined ? '' : String(value);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,163 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
+ import { createSignal, createEffect, disposeAll, krateFlushSync, krateOnSettle, setOwnerHooks, } from './signal';
3
+ // Settle hooks cannot be unregistered; this one counts flushes for the whole file.
4
+ let settleRuns = 0;
5
+ let settleThrows = false;
6
+ let settleAfterThrow = 0;
7
+ krateOnSettle(() => {
8
+ settleRuns++;
9
+ });
10
+ krateOnSettle(() => {
11
+ if (settleThrows)
12
+ throw new Error('settle boom');
13
+ });
14
+ krateOnSettle(() => {
15
+ settleAfterThrow++;
16
+ });
17
+ describe('a throwing effect does not strand the others', () => {
18
+ beforeEach(() => {
19
+ disposeAll();
20
+ settleRuns = 0;
21
+ settleThrows = false;
22
+ settleAfterThrow = 0;
23
+ });
24
+ afterEach(() => {
25
+ setOwnerHooks(null);
26
+ vi.restoreAllMocks();
27
+ });
28
+ it('runs the effects queued behind it, now and on later updates', () => {
29
+ const [a, setA] = createSignal(0);
30
+ const seen = [];
31
+ createEffect(() => {
32
+ if (a() > 0)
33
+ throw new Error('boom ' + a());
34
+ });
35
+ createEffect(() => {
36
+ seen.push(a());
37
+ });
38
+ expect(seen).toEqual([0]);
39
+ setA(1);
40
+ expect(() => krateFlushSync()).toThrow('boom 1');
41
+ expect(seen).toEqual([0, 1]);
42
+ // The second effect was not left marked as queued: it still reacts.
43
+ setA(2);
44
+ expect(() => krateFlushSync()).toThrow('boom 2');
45
+ expect(seen).toEqual([0, 1, 2]);
46
+ });
47
+ it('keeps an effect before and after the thrower working', () => {
48
+ const [a, setA] = createSignal(0);
49
+ const log = [];
50
+ createEffect(() => log.push('first ' + a()));
51
+ createEffect(() => {
52
+ if (a() === 1)
53
+ throw new Error('middle');
54
+ });
55
+ createEffect(() => log.push('last ' + a()));
56
+ setA(1);
57
+ expect(() => krateFlushSync()).toThrow('middle');
58
+ setA(2);
59
+ krateFlushSync();
60
+ expect(log).toEqual(['first 0', 'last 0', 'first 1', 'last 1', 'first 2', 'last 2']);
61
+ });
62
+ it('rethrows the first error and logs the others', () => {
63
+ const logged = vi.spyOn(console, 'error').mockImplementation(() => { });
64
+ const [a, setA] = createSignal(0);
65
+ createEffect(() => {
66
+ if (a() > 0)
67
+ throw new Error('one');
68
+ });
69
+ createEffect(() => {
70
+ if (a() > 0)
71
+ throw new Error('two');
72
+ });
73
+ setA(1);
74
+ expect(() => krateFlushSync()).toThrow('one');
75
+ expect(logged).toHaveBeenCalledTimes(1);
76
+ expect(String(logged.mock.calls[0][0].message)).toBe('two');
77
+ });
78
+ it('still runs the settle hooks before rethrowing', () => {
79
+ const [a, setA] = createSignal(0);
80
+ createEffect(() => {
81
+ if (a() > 0)
82
+ throw new Error('boom');
83
+ });
84
+ setA(1);
85
+ const before = settleRuns;
86
+ expect(() => krateFlushSync()).toThrow('boom');
87
+ expect(settleRuns).toBe(before + 1);
88
+ });
89
+ it('reports a throw from a settle hook after running the others', () => {
90
+ settleThrows = true;
91
+ const [a, setA] = createSignal(0);
92
+ createEffect(() => void a());
93
+ setA(1);
94
+ expect(() => krateFlushSync()).toThrow('settle boom');
95
+ expect(settleAfterThrow).toBe(1);
96
+ });
97
+ it('hands owned errors to the boundary and does not throw', () => {
98
+ const handled = [];
99
+ setOwnerHooks({
100
+ current: () => 'boundary',
101
+ run: (_o, fn) => fn(),
102
+ cleanup: () => { },
103
+ error: (_o, err) => {
104
+ handled.push(err);
105
+ return true;
106
+ },
107
+ });
108
+ const [a, setA] = createSignal(0);
109
+ const seen = [];
110
+ createEffect(() => {
111
+ if (a() > 0)
112
+ throw new Error('owned');
113
+ });
114
+ createEffect(() => {
115
+ seen.push(a());
116
+ });
117
+ setA(1);
118
+ expect(() => krateFlushSync()).not.toThrow();
119
+ expect(handled).toHaveLength(1);
120
+ expect(seen).toEqual([0, 1]);
121
+ });
122
+ it('rethrows an owned error the boundary declines', () => {
123
+ setOwnerHooks({
124
+ current: () => 'boundary',
125
+ run: (_o, fn) => fn(),
126
+ cleanup: () => { },
127
+ error: () => false,
128
+ });
129
+ const [a, setA] = createSignal(0);
130
+ const seen = [];
131
+ createEffect(() => {
132
+ if (a() > 0)
133
+ throw new Error('declined');
134
+ });
135
+ createEffect(() => {
136
+ seen.push(a());
137
+ });
138
+ setA(1);
139
+ expect(() => krateFlushSync()).toThrow('declined');
140
+ expect(seen).toEqual([0, 1]);
141
+ });
142
+ it('reports the effect error first when an update loop aborts the same flush', () => {
143
+ vi.spyOn(console, 'error').mockImplementation(() => { });
144
+ const [a, setA] = createSignal(0);
145
+ const [b, setB] = createSignal(0);
146
+ createEffect(() => {
147
+ if (a() > 0)
148
+ throw new Error('thrower');
149
+ });
150
+ createEffect(() => setB(a() + 1));
151
+ createEffect(() => setA(b() + 1));
152
+ expect(() => krateFlushSync()).toThrow('thrower');
153
+ // The loop was dropped: the queue is empty and effects still react.
154
+ const seen = [];
155
+ const [c, setC] = createSignal(0);
156
+ createEffect(() => {
157
+ seen.push(c());
158
+ });
159
+ setC(5);
160
+ krateFlushSync();
161
+ expect(seen).toEqual([0, 5]);
162
+ });
163
+ });
package/dist/effects.d.ts CHANGED
@@ -75,6 +75,14 @@ export declare function flushPassive(): void;
75
75
  * tracked; only the dependencies are.
76
76
  */
77
77
  export declare function createMemoDeps<T>(fn: () => T, deps: () => unknown): () => T;
78
+ /**
79
+ * React 19.2's useEffectEvent: a function that always runs the latest closure
80
+ * and never subscribes its caller. Components run once and read props and
81
+ * state through live getters, so `fn` already sees the latest values; the
82
+ * wrapper only keeps the reads it makes from tracking, so calling the event
83
+ * from an effect does not make the effect depend on them.
84
+ */
85
+ export declare function createEffectEvent<T extends (...args: never[]) => unknown>(fn: T): T;
78
86
  /**
79
87
  * React's useCallback with a dependency array: a getter for the callback
80
88
  * whose identity only changes when the dependency array changes.
package/dist/effects.js CHANGED
@@ -640,6 +640,19 @@ export function createMemoDeps(fn, deps) {
640
640
  return value;
641
641
  };
642
642
  }
643
+ /**
644
+ * React 19.2's useEffectEvent: a function that always runs the latest closure
645
+ * and never subscribes its caller. Components run once and read props and
646
+ * state through live getters, so `fn` already sees the latest values; the
647
+ * wrapper only keeps the reads it makes from tracking, so calling the event
648
+ * from an effect does not make the effect depend on them.
649
+ */
650
+ export function createEffectEvent(fn) {
651
+ const event = function (...args) {
652
+ return untrack(() => fn.apply(this, args));
653
+ };
654
+ return event;
655
+ }
643
656
  /**
644
657
  * React's useCallback with a dependency array: a getter for the callback
645
658
  * whose identity only changes when the dependency array changes.
@@ -13,7 +13,7 @@ function getOverlayStyle() {
13
13
  }
14
14
  function getCardStyle() {
15
15
  return `
16
- background:#1a1a2e;border:1px solid #e74c3c;border-radius:8px;
16
+ background:#171717;border:1px solid #e74c3c;border-radius:8px;
17
17
  padding:24px 32px;max-width:800px;max-height:80vh;overflow:auto;
18
18
  box-shadow:0 8px 32px rgba(231,76,60,0.3);width:90%;
19
19
  `;
@@ -22,10 +22,10 @@ function getTitleStyle() {
22
22
  return `color:#e74c3c;font-size:18px;font-weight:bold;margin-bottom:12px;`;
23
23
  }
24
24
  function getMessageStyle() {
25
- return `color:#ecf0f1;font-size:14px;line-height:1.6;white-space:pre-wrap;word-break:break-word;`;
25
+ return `color:#e5e5e5;font-size:14px;line-height:1.6;white-space:pre-wrap;word-break:break-word;`;
26
26
  }
27
27
  function getStackStyle() {
28
- return `color:#95a5a6;font-size:12px;line-height:1.5;margin-top:12px;white-space:pre-wrap;`;
28
+ return `color:#a3a3a3;font-size:12px;line-height:1.5;margin-top:12px;white-space:pre-wrap;`;
29
29
  }
30
30
  function getCloseBtnStyle() {
31
31
  return `
@@ -69,7 +69,7 @@ function showError(title, message, stack) {
69
69
  <div style="${getMessageStyle()}">${escapeHTML(message)}</div>
70
70
  ${sourceLink}
71
71
  ${stack ? `<div style="${getStackStyle()}">${escapeHTML(stack)}</div>` : ''}
72
- <div style="color:#7f8c8d;font-size:11px;margin-top:16px;">Press Esc to dismiss - Edit the file to fix, then the page will auto-reload</div>
72
+ <div style="color:#8a8a8a;font-size:11px;margin-top:16px;">Press Esc to dismiss - Edit the file to fix, then the page will auto-reload</div>
73
73
  </div>
74
74
  `;
75
75
  document.body.appendChild(overlay);
@@ -0,0 +1,63 @@
1
+ /** One splice marker and its nested markers. */
2
+ export interface RegionBoundary {
3
+ openStart: number;
4
+ openEnd: number;
5
+ /** Start of the closing marker (end of the baked inner content). */
6
+ fbEnd: number;
7
+ id: string;
8
+ kind: "suspense" | "region";
9
+ children: RegionBoundary[];
10
+ }
11
+ export interface RegionShell {
12
+ shell: string;
13
+ roots: RegionBoundary[];
14
+ all: RegionBoundary[];
15
+ /** False when the file had no markers or a mismatched marker pair. */
16
+ ok: boolean;
17
+ }
18
+ /** Extracts the nested marker tree of a baked shell. */
19
+ export declare function parseRegionShell(shell: string): RegionShell;
20
+ /** Sibling regions only: a coarse page region or nested boundaries stay ordered. */
21
+ export declare function canStreamOutOfOrder(all: RegionBoundary[]): boolean;
22
+ export declare function allSuspense(all: RegionBoundary[]): boolean;
23
+ /** Keeps document markup in the streamed prefix and defers page scripts to the tail. */
24
+ export declare function splitBodyScripts(shell: string): [string, string];
25
+ /** Swaps the baked <title> content of a shell. */
26
+ export declare function replaceTitle(shell: string, title: string): string;
27
+ /**
28
+ * Inline script that inserts one region chunk at its marker pair. head and
29
+ * title are the region's <Head> content, applied to the document head.
30
+ */
31
+ export declare function regionReplaceScript(id: string, html: string, head?: string, title?: string): string;
32
+ /** Writes a shell, replacing each marker block's inner content with its region HTML. */
33
+ export declare function spliceShell(shell: string, roots: RegionBoundary[], regionHTML: ReadonlyMap<string, string>, emit: (chunk: string) => void): void;
34
+ export declare const FLASH_COOKIE = "krate_flash";
35
+ export interface FlashPayload {
36
+ a: string;
37
+ r: unknown;
38
+ }
39
+ /** The cookie value for a flash payload (already base64url): payload.signature. */
40
+ export declare function signFlash(secret: string, payload: string): Promise<string>;
41
+ /** The payload of a signed flash cookie value, or null when the signature does not verify. */
42
+ export declare function verifyFlash(secret: string, value: string): Promise<string | null>;
43
+ /** base64url of the flash JSON, the payload that gets signed. */
44
+ export declare function flashPayloadOf(action: string, result: unknown): string;
45
+ /**
46
+ * Whether a Cookie header carries a flash cookie, signed or not. A static layer
47
+ * uses it to serve the page uncompressed so the notice can be rendered into it;
48
+ * only requestFlash decides whether the cookie is believed.
49
+ */
50
+ export declare function hasFlashCookie(cookieHeader: string | null): boolean;
51
+ /**
52
+ * Decodes the flash cookie of a Cookie header. The cookie must carry a valid
53
+ * signature for secret: an unsigned or forged value (a sibling subdomain can
54
+ * set cookies for this host) is never trusted. Without a secret nothing is.
55
+ */
56
+ export declare function requestFlash(cookieHeader: string | null, secret: string | null): Promise<{
57
+ raw: string;
58
+ payload: FlashPayload;
59
+ } | null>;
60
+ /** The human-readable strings of an action's returned state, in a stable order. */
61
+ export declare function flashMessages(value: unknown): string[];
62
+ /** Inserts the notice after the opening tag of the form that produced the flash. */
63
+ export declare function injectFlashNotice(page: string, cookieValue: string, p: FlashPayload): string | null;