@krate/runtime 0.5.0-beta.3 → 0.5.0-rc.10

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 (219) hide show
  1. package/dist/action-context.js +1 -1
  2. package/dist/actions.d.ts +7 -0
  3. package/dist/actions.js +34 -10
  4. package/dist/after.d.ts +28 -0
  5. package/dist/after.js +48 -0
  6. package/dist/assets-static.d.ts +10 -1
  7. package/dist/assets-static.js +10 -2
  8. package/dist/base-path.d.ts +7 -0
  9. package/dist/base-path.js +20 -0
  10. package/dist/boundary.js +1 -1
  11. package/dist/builtin-tags.d.ts +12 -0
  12. package/dist/builtin-tags.js +42 -0
  13. package/dist/cache-adapter.js +1 -1
  14. package/dist/cache-scope.d.ts +8 -0
  15. package/dist/cache-scope.js +14 -1
  16. package/dist/cloudflare-workers.d.ts +2 -0
  17. package/dist/cloudflare-workers.js +27 -0
  18. package/dist/context.d.ts +5 -0
  19. package/dist/context.js +28 -17
  20. package/dist/dev-overlay.d.ts +54 -3
  21. package/dist/dev-overlay.js +496 -91
  22. package/dist/dom.d.ts +4 -0
  23. package/dist/dom.js +62 -16
  24. package/dist/effects.js +43 -10
  25. package/dist/events.d.ts +2 -0
  26. package/dist/events.js +18 -0
  27. package/dist/flight-props.d.ts +7 -0
  28. package/dist/flight-props.js +105 -0
  29. package/dist/handler-html.js +4 -4
  30. package/dist/handler-routing.d.ts +2 -23
  31. package/dist/handler-routing.js +9 -190
  32. package/dist/handler-segments.d.ts +6 -0
  33. package/dist/handler-segments.js +18 -4
  34. package/dist/head-tags.d.ts +9 -0
  35. package/dist/head-tags.js +93 -6
  36. package/dist/highlight-bind.js +1 -1
  37. package/dist/highlight.d.ts +3 -2
  38. package/dist/highlight.js +17 -12
  39. package/dist/hints.d.ts +25 -2
  40. package/dist/hints.js +147 -74
  41. package/dist/index.d.ts +2 -0
  42. package/dist/index.js +3 -0
  43. package/dist/island-swap.d.ts +47 -0
  44. package/dist/island-swap.js +635 -0
  45. package/dist/jsx-dev-runtime.d.ts +1 -1
  46. package/dist/jsx-types.d.ts +99 -3
  47. package/dist/krate-core.js +1 -1
  48. package/dist/krate-dev.js +407 -80
  49. package/dist/krate-f-actions.js +1 -1
  50. package/dist/krate-f-classes.js +1 -1
  51. package/dist/krate-f-highlight.js +1 -1
  52. package/dist/krate-f-list.js +1 -1
  53. package/dist/krate-f-navigation.js +1 -1
  54. package/dist/krate-f-router-lite.js +1 -1
  55. package/dist/krate-f-router.js +1 -1
  56. package/dist/krate-features.json +455 -0
  57. package/dist/krate-hydrate-lite.js +5 -5
  58. package/dist/krate-hydrate.js +5 -5
  59. package/dist/krate-island-swap.js +1 -0
  60. package/dist/krate-runtime.js +5 -5
  61. package/dist/krate-suspense.js +1 -1
  62. package/dist/list.d.ts +14 -4
  63. package/dist/list.js +30 -23
  64. package/dist/metadata.js +5 -2
  65. package/dist/navigation-react.d.ts +13 -0
  66. package/dist/navigation-react.js +86 -0
  67. package/dist/navigation.d.ts +19 -0
  68. package/dist/navigation.js +35 -0
  69. package/dist/node-server.js +3 -3
  70. package/dist/og.js +1 -1
  71. package/dist/platform.d.ts +52 -0
  72. package/dist/platform.js +57 -0
  73. package/dist/react-compat.d.ts +39 -0
  74. package/dist/react-compat.js +359 -0
  75. package/dist/react-server.d.ts +63 -0
  76. package/dist/react-server.js +125 -0
  77. package/dist/region-wire.d.ts +10 -0
  78. package/dist/region-wire.js +154 -0
  79. package/dist/request-context.js +1 -1
  80. package/dist/request-extras.d.ts +4 -0
  81. package/dist/request-extras.js +51 -0
  82. package/dist/resp.js +1 -1
  83. package/dist/route-source.d.ts +39 -0
  84. package/dist/route-source.js +532 -0
  85. package/dist/router-lite.js +3 -9
  86. package/dist/router.d.ts +1 -1
  87. package/dist/router.js +675 -100
  88. package/dist/server-handler.d.ts +69 -1
  89. package/dist/server-handler.js +515 -96
  90. package/dist/server-renderer.js +16 -7
  91. package/dist/server.d.ts +73 -16
  92. package/dist/server.js +619 -102
  93. package/dist/sha256.js +9 -9
  94. package/dist/signal.js +47 -20
  95. package/dist/site-config.d.ts +15 -0
  96. package/dist/site-config.js +28 -0
  97. package/dist/slot.d.ts +12 -0
  98. package/dist/slot.js +23 -0
  99. package/dist/ssr-core.d.ts +2 -0
  100. package/dist/ssr-core.js +12 -4
  101. package/dist/suspense.js +34 -2
  102. package/dist/testing.d.ts +62 -0
  103. package/dist/testing.js +90 -0
  104. package/dist/use-id.js +1 -1
  105. package/package.json +28 -3
  106. package/dist/action-context.test.d.ts +0 -1
  107. package/dist/action-context.test.js +0 -72
  108. package/dist/actions.test.d.ts +0 -1
  109. package/dist/actions.test.js +0 -477
  110. package/dist/cache-adapter.test.d.ts +0 -1
  111. package/dist/cache-adapter.test.js +0 -244
  112. package/dist/cache.test.d.ts +0 -1
  113. package/dist/cache.test.js +0 -233
  114. package/dist/class-component.test.d.ts +0 -1
  115. package/dist/class-component.test.js +0 -462
  116. package/dist/class-helpers.test.d.ts +0 -1
  117. package/dist/class-helpers.test.js +0 -169
  118. package/dist/context.test.d.ts +0 -1
  119. package/dist/context.test.js +0 -57
  120. package/dist/derived.test.d.ts +0 -1
  121. package/dist/derived.test.js +0 -140
  122. package/dist/dev-overlay.test.d.ts +0 -1
  123. package/dist/dev-overlay.test.js +0 -152
  124. package/dist/discrete.test.d.ts +0 -1
  125. package/dist/discrete.test.js +0 -100
  126. package/dist/dom.test.d.ts +0 -1
  127. package/dist/dom.test.js +0 -31
  128. package/dist/effect-errors.test.d.ts +0 -1
  129. package/dist/effect-errors.test.js +0 -163
  130. package/dist/effects.test.d.ts +0 -1
  131. package/dist/effects.test.js +0 -485
  132. package/dist/events.test.d.ts +0 -1
  133. package/dist/events.test.js +0 -447
  134. package/dist/handler-html.test.d.ts +0 -1
  135. package/dist/handler-html.test.js +0 -256
  136. package/dist/handler-routing.test.d.ts +0 -1
  137. package/dist/handler-routing.test.js +0 -99
  138. package/dist/handler-segments.test.d.ts +0 -1
  139. package/dist/handler-segments.test.js +0 -217
  140. package/dist/head-tags.test.d.ts +0 -1
  141. package/dist/head-tags.test.js +0 -131
  142. package/dist/highlight-bind.test.d.ts +0 -1
  143. package/dist/highlight-bind.test.js +0 -124
  144. package/dist/highlight.test.d.ts +0 -1
  145. package/dist/highlight.test.js +0 -56
  146. package/dist/lanes.test.d.ts +0 -1
  147. package/dist/lanes.test.js +0 -59
  148. package/dist/list.test.d.ts +0 -1
  149. package/dist/list.test.js +0 -344
  150. package/dist/metadata.test.d.ts +0 -1
  151. package/dist/metadata.test.js +0 -167
  152. package/dist/navigation.test.d.ts +0 -1
  153. package/dist/navigation.test.js +0 -130
  154. package/dist/node-server.test.d.ts +0 -1
  155. package/dist/node-server.test.js +0 -492
  156. package/dist/optimistic-lanes.test.d.ts +0 -1
  157. package/dist/optimistic-lanes.test.js +0 -45
  158. package/dist/patterns.test.d.ts +0 -1
  159. package/dist/patterns.test.js +0 -98
  160. package/dist/portal.test.d.ts +0 -1
  161. package/dist/portal.test.js +0 -99
  162. package/dist/react-effects.test.d.ts +0 -1
  163. package/dist/react-effects.test.js +0 -96
  164. package/dist/react-suspense.test.d.ts +0 -1
  165. package/dist/react-suspense.test.js +0 -194
  166. package/dist/react.test.d.ts +0 -1
  167. package/dist/react.test.js +0 -60
  168. package/dist/react19.test.d.ts +0 -1
  169. package/dist/react19.test.js +0 -176
  170. package/dist/reactivity-core.test.d.ts +0 -1
  171. package/dist/reactivity-core.test.js +0 -152
  172. package/dist/reconcile.test.d.ts +0 -1
  173. package/dist/reconcile.test.js +0 -110
  174. package/dist/refs.test.d.ts +0 -1
  175. package/dist/refs.test.js +0 -257
  176. package/dist/router-layout.test.d.ts +0 -1
  177. package/dist/router-layout.test.js +0 -249
  178. package/dist/router-nav.test.d.ts +0 -1
  179. package/dist/router-nav.test.js +0 -464
  180. package/dist/router-slots.test.d.ts +0 -1
  181. package/dist/router-slots.test.js +0 -144
  182. package/dist/router-speculation.test.d.ts +0 -1
  183. package/dist/router-speculation.test.js +0 -25
  184. package/dist/router-styles.test.d.ts +0 -1
  185. package/dist/router-styles.test.js +0 -98
  186. package/dist/router.test.d.ts +0 -1
  187. package/dist/router.test.js +0 -36
  188. package/dist/server-async.test.d.ts +0 -1
  189. package/dist/server-async.test.js +0 -216
  190. package/dist/server-handler.test.d.ts +0 -1
  191. package/dist/server-handler.test.js +0 -535
  192. package/dist/server-highlight.test.d.ts +0 -1
  193. package/dist/server-highlight.test.js +0 -32
  194. package/dist/server-renderer.test.d.ts +0 -1
  195. package/dist/server-renderer.test.js +0 -266
  196. package/dist/server.test.d.ts +0 -1
  197. package/dist/server.test.js +0 -88
  198. package/dist/sha256.test.d.ts +0 -1
  199. package/dist/sha256.test.js +0 -13
  200. package/dist/signal-lanes.test.d.ts +0 -1
  201. package/dist/signal-lanes.test.js +0 -32
  202. package/dist/signal.test.d.ts +0 -1
  203. package/dist/signal.test.js +0 -68
  204. package/dist/slots.test.d.ts +0 -1
  205. package/dist/slots.test.js +0 -169
  206. package/dist/snapshots.test.d.ts +0 -1
  207. package/dist/snapshots.test.js +0 -208
  208. package/dist/ssr-core-behavior.test.d.ts +0 -1
  209. package/dist/ssr-core-behavior.test.js +0 -620
  210. package/dist/ssr-core.test.d.ts +0 -1
  211. package/dist/ssr-core.test.js +0 -324
  212. package/dist/static-memory.test.d.ts +0 -1
  213. package/dist/static-memory.test.js +0 -26
  214. package/dist/storage.test.d.ts +0 -1
  215. package/dist/storage.test.js +0 -46
  216. package/dist/suspense-actions.test.d.ts +0 -1
  217. package/dist/suspense-actions.test.js +0 -72
  218. package/dist/suspense.test.d.ts +0 -1
  219. package/dist/suspense.test.js +0 -518
@@ -1,57 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { createContext } from './context';
3
- import { h } from './dom';
4
- // Runtime providers push their value while their children are read; compiled
5
- // source components resolve context at build time instead. The tests pass
6
- // lazy children (getters) so the children render under the provider.
7
- describe('createContext (runtime)', () => {
8
- it('reads the default without a provider', () => {
9
- const Theme = createContext({ color: 'black' });
10
- expect(Theme.useContext()).toEqual({ color: 'black' });
11
- expect(Theme.use()).toEqual({ color: 'black' });
12
- });
13
- it('nested providers shadow outer ones and restore on exit', () => {
14
- const Depth = createContext(0);
15
- const seen = [];
16
- const read = () => {
17
- seen.push(Depth.useContext());
18
- return document.createTextNode(String(Depth.useContext()));
19
- };
20
- const outer = Depth.Provider({
21
- value: 1,
22
- get children() {
23
- const first = read();
24
- const inner = Depth.Provider({
25
- value: 2,
26
- get children() {
27
- return [read()];
28
- },
29
- });
30
- return [first, inner, read()];
31
- },
32
- });
33
- expect(seen).toEqual([1, 2, 1]);
34
- expect(outer.textContent).toBe('121');
35
- expect(Depth.useContext()).toBe(0);
36
- });
37
- it('works as a React 19 provider and with Consumer', () => {
38
- const Density = createContext('comfortable');
39
- let inside = '';
40
- const node = Density({
41
- value: 'compact',
42
- get children() {
43
- inside = Density.useContext();
44
- return [Density.Consumer({ children: (d) => h('span', null, d) })];
45
- },
46
- });
47
- expect(inside).toBe('compact');
48
- expect(node.querySelector('span').textContent).toBe('compact');
49
- expect(Density.useContext()).toBe('comfortable');
50
- });
51
- it('Consumer renders text, arrays and nothing', () => {
52
- const Name = createContext('ada');
53
- expect(Name.Consumer({ children: (n) => 'hi ' + n }).textContent).toBe('hi ada');
54
- expect(Name.Consumer({ children: [(n) => [n, '!']] }).textContent).toBe('ada!');
55
- expect(Name.Consumer({ children: () => null }).textContent).toBe('');
56
- });
57
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,140 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { createSignal, createEffect, disposeAll, krateDerived, krateHook, isDerivedGetter, isSignalGetter } from './signal';
3
- import { createEffectDeps } from './effects';
4
- const tick = () => new Promise((r) => setTimeout(r, 0));
5
- // Lets the signal flush, the commit microtask and the passive macrotask run.
6
- async function flush() {
7
- for (let i = 0; i < 3; i++)
8
- await tick();
9
- }
10
- describe('krateDerived', () => {
11
- beforeEach(() => disposeAll());
12
- it('is lazy and recomputes only after a source changed', () => {
13
- const [n, setN] = createSignal(2);
14
- let runs = 0;
15
- const doubled = krateDerived(() => {
16
- runs++;
17
- return n() * 2;
18
- });
19
- expect(runs).toBe(0);
20
- expect(doubled()).toBe(4);
21
- expect(doubled()).toBe(4);
22
- expect(runs).toBe(1);
23
- setN(5);
24
- expect(runs).toBe(1);
25
- expect(doubled()).toBe(10);
26
- expect(runs).toBe(2);
27
- });
28
- it('is current synchronously after a write, before any flush', () => {
29
- const [raw, setRaw] = createSignal('12');
30
- const value = krateDerived(() => Number(raw()));
31
- expect(value()).toBe(12);
32
- setRaw('7');
33
- expect(value()).toBe(7);
34
- });
35
- it('chains derived values without glitches', async () => {
36
- const [items, setItems] = createSignal(['a', 'b']);
37
- const n = krateDerived(() => items().length);
38
- const label = krateDerived(() => (n() > 1 ? 'items' : 'item'));
39
- const seen = [];
40
- createEffect(() => {
41
- // Reads both the source and the derived chain: never an inconsistent pair.
42
- seen.push(`${items().length}:${n()} ${label()}`);
43
- });
44
- setItems(['a']);
45
- await flush();
46
- setItems(['a', 'b', 'c']);
47
- await flush();
48
- expect(seen).toEqual(['2:2 items', '1:1 item', '3:3 items']);
49
- });
50
- it('notifies readers when a source changes', async () => {
51
- const [q, setQ] = createSignal('');
52
- const shown = krateDerived(() => ['ada', 'grace'].filter((x) => x.includes(q())));
53
- const lengths = [];
54
- createEffect(() => {
55
- lengths.push(shown().length);
56
- });
57
- setQ('gr');
58
- await flush();
59
- setQ('zz');
60
- await flush();
61
- expect(lengths).toEqual([2, 1, 0]);
62
- });
63
- it('feeds effect dependency arrays with plain values (Object.is)', async () => {
64
- const [raw, setRaw] = createSignal('12');
65
- const value = krateDerived(() => Number(raw()));
66
- const log = [];
67
- createEffectDeps(() => {
68
- log.push(String(value()));
69
- }, () => [value()]);
70
- await flush();
71
- setRaw('abc');
72
- await flush();
73
- setRaw('xyz'); // NaN again: Object.is(NaN, NaN), no re-run
74
- await flush();
75
- setRaw('7');
76
- await flush();
77
- expect(log).toEqual(['12', 'NaN', '7']);
78
- });
79
- it('is recognized as a reactive getter', () => {
80
- const d = krateDerived(() => 1);
81
- expect(isDerivedGetter(d)).toBe(true);
82
- expect(isSignalGetter(d)).toBe(true);
83
- expect(isDerivedGetter(() => 1)).toBe(false);
84
- });
85
- it('still answers after disposal (untracked)', () => {
86
- const [n, setN] = createSignal(1);
87
- const d = krateDerived(() => n() + 1);
88
- expect(d()).toBe(2);
89
- disposeAll();
90
- setN(4);
91
- expect(d()).toBe(5);
92
- });
93
- });
94
- describe('krateDerived render identity', () => {
95
- beforeEach(() => disposeAll());
96
- it('recomputes a render literal when any trigger changes', () => {
97
- const [page] = createSignal(1);
98
- const [theme, setTheme] = createSignal('light');
99
- const inline = krateDerived(() => ({ page: page() }), () => [page(), theme()]);
100
- const first = inline();
101
- expect(inline()).toBe(first);
102
- setTheme('dark');
103
- const second = inline();
104
- expect(second).not.toBe(first);
105
- expect(second).toEqual({ page: 1 });
106
- });
107
- });
108
- describe('krateDerived with React state snapshots', () => {
109
- beforeEach(() => disposeAll());
110
- it('reads the committed value in a handler and the latest value in render', async () => {
111
- const [raw, setRaw] = createSignal('12', { react: true });
112
- const value = krateDerived(() => Number(raw()));
113
- const seen = [];
114
- createEffect(() => {
115
- seen.push(value());
116
- });
117
- setRaw('7');
118
- // Like a React event handler: state set in this handler is not visible yet.
119
- expect(value()).toBe(12);
120
- await flush();
121
- expect(seen).toEqual([12, 7]);
122
- expect(value()).toBe(7);
123
- });
124
- });
125
- describe('krateHook', () => {
126
- beforeEach(() => disposeAll());
127
- it('passes a derived getter through', () => {
128
- const [n, setN] = createSignal(0);
129
- const result = krateDerived(() => ({ n: n() }));
130
- const h = krateHook(result);
131
- expect(h).toBe(result);
132
- setN(3);
133
- expect(h().n).toBe(3);
134
- });
135
- it('wraps a plain value (including a plain function)', () => {
136
- const fn = () => 42;
137
- expect(krateHook(fn)()).toBe(fn);
138
- expect(krateHook([1, 2])()).toEqual([1, 2]);
139
- });
140
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,152 +0,0 @@
1
- import { describe, it, expect, beforeAll } from 'vitest';
2
- class FakeEventSource {
3
- constructor(url) {
4
- this.url = url;
5
- this.listeners = {};
6
- FakeEventSource.last = this;
7
- }
8
- addEventListener(type, fn) {
9
- var _a;
10
- ((_a = this.listeners)[type] || (_a[type] = [])).push(fn);
11
- }
12
- emit(type, data) {
13
- for (const fn of this.listeners[type] || [])
14
- fn({ data: JSON.stringify(data) });
15
- }
16
- }
17
- FakeEventSource.last = null;
18
- let overlay;
19
- // File-level setup: globals must exist BEFORE the overlay module auto-inits on
20
- // import, and the export is captured from the same module instance.
21
- beforeAll(async () => {
22
- globalThis.EventSource = FakeEventSource;
23
- // Error reports must not reach the (absent) dev server from the test.
24
- navigator.sendBeacon = () => true;
25
- window.__KRATE_DEV__ = {
26
- sse: '/__krate/hotreload',
27
- errors: '/__krate/client-error',
28
- open: '/__krate/open',
29
- overlay: true,
30
- toolbar: true,
31
- };
32
- overlay = await import('./dev-overlay');
33
- });
34
- function devRoot() {
35
- const host = document.getElementById('krate-dev-root');
36
- return host ? host.shadowRoot : null;
37
- }
38
- describe('dev-overlay', () => {
39
- it('mounts a shadow-root host with a toolbar', () => {
40
- const shadow = devRoot();
41
- expect(shadow).toBeTruthy();
42
- expect(shadow.querySelector('.toolbar')).toBeTruthy();
43
- expect(shadow.querySelector('.overlay')).toBeTruthy();
44
- });
45
- it('renders structured build diagnostics with location, frame and hint', () => {
46
- FakeEventSource.last.emit('build-error', {
47
- diagnostics: [
48
- {
49
- file: 'a.tsx',
50
- line: 3,
51
- col: 5,
52
- message: 'boom',
53
- hint: 'fix it',
54
- source: 'const x = 1;',
55
- },
56
- ],
57
- buildOk: false,
58
- });
59
- const overlay = devRoot().querySelector('.overlay');
60
- expect(overlay.hidden).toBe(false);
61
- const text = devRoot().querySelector('.list').textContent || '';
62
- expect(text).toContain('boom');
63
- expect(text).toContain('a.tsx:3:5');
64
- expect(text).toContain('fix it');
65
- expect(text).toContain('^');
66
- const open = devRoot().querySelector('.open');
67
- expect(open).toBeTruthy();
68
- expect(open.textContent).toContain('Open in editor');
69
- });
70
- it('updates the toolbar route on SPA (history) navigation', () => {
71
- history.pushState({}, '', '/some/other/route');
72
- const route = devRoot().querySelector('.route');
73
- expect(route.textContent).toBe('/some/other/route');
74
- });
75
- it('shows runtime errors from client-error events', () => {
76
- FakeEventSource.last.emit('client-error', {
77
- clientError: { message: 'kaboom', stack: 'at foo (a.tsx:1:1)' },
78
- });
79
- const text = devRoot().querySelector('.list').textContent || '';
80
- expect(text).toContain('kaboom');
81
- });
82
- it('hides the overlay on Escape', () => {
83
- document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
84
- const overlay = devRoot().querySelector('.overlay');
85
- expect(overlay.hidden).toBe(true);
86
- });
87
- });
88
- describe('dev-overlay rebuild handling', () => {
89
- it('clears a build error when a rebuild of another route succeeds', () => {
90
- history.pushState({}, '', '/current');
91
- FakeEventSource.last.emit('build-error', { diagnostics: [{ file: 'b.tsx', message: 'stale-build-error' }], buildOk: false });
92
- const overlayEl = devRoot().querySelector('.overlay');
93
- expect(overlayEl.hidden).toBe(false);
94
- expect(devRoot().querySelector('.list').textContent).toContain('stale-build-error');
95
- // The fix landed on a different route: no reload here, but the error goes.
96
- FakeEventSource.last.emit('reload', { pages: ['/elsewhere'] });
97
- const text = devRoot().querySelector('.list').textContent || '';
98
- expect(text).not.toContain('stale-build-error');
99
- });
100
- it('shows a runtime error once when the server echoes it back', () => {
101
- const before = (devRoot().querySelector('.list').textContent || '').split('echo-dup-error').length - 1;
102
- window.dispatchEvent(new ErrorEvent('error', { message: 'echo-dup-error', filename: 'x.js', lineno: 1, colno: 1 }));
103
- FakeEventSource.last.emit('client-error', { clientError: { message: 'echo-dup-error', stack: '' } });
104
- const text = devRoot().querySelector('.list').textContent || '';
105
- expect(text.split('echo-dup-error').length - 1 - before).toBe(1);
106
- });
107
- });
108
- describe('routeMatches', () => {
109
- it('matches unprefixed patterns against a base-path URL', () => {
110
- expect(overlay.routeMatches('/about', '/docs/about', '/docs')).toBe(true);
111
- expect(overlay.routeMatches('/about', '/docs/other', '/docs')).toBe(false);
112
- expect(overlay.routeMatches('/', '/docs/', '/docs')).toBe(true);
113
- });
114
- it('matches root deployment and dynamic segments', () => {
115
- expect(overlay.routeMatches('/about', '/about', '')).toBe(true);
116
- expect(overlay.routeMatches('/blog/[slug]', '/blog/hello', '')).toBe(true);
117
- expect(overlay.routeMatches('/blog/[slug]', '/blog/hello/x', '')).toBe(false);
118
- expect(overlay.routeMatches('/docs/[...rest]', '/docs/a/b/c', '')).toBe(true);
119
- });
120
- });
121
- describe('source-map symbolication', () => {
122
- it('decodes Base64 VLQ deltas', () => {
123
- expect(overlay.decodeVLQ('AAAA')).toEqual([0, 0, 0, 0]);
124
- expect(overlay.decodeVLQ('CAAA')).toEqual([1, 0, 0, 0]);
125
- });
126
- it('decodes mappings with cumulative source line deltas', () => {
127
- const lines = overlay.decodeMappings('AAAA;AACA');
128
- expect(lines).toHaveLength(2);
129
- expect(lines[0][0]).toMatchObject({ genCol: 0, src: 0, srcLine: 0, srcCol: 0 });
130
- expect(lines[1][0]).toMatchObject({ genCol: 0, src: 0, srcLine: 1, srcCol: 0 });
131
- });
132
- it('parses V8 and path-only stack frames', () => {
133
- const a = overlay.parseStackFrame(' at foo (http://localhost:3000/index.abc.js:12:34)');
134
- expect(a).toMatchObject({ url: 'http://localhost:3000/index.abc.js', line: 12, col: 34 });
135
- const b = overlay.parseStackFrame(' at bar (/index.abc.js:5:6)');
136
- expect(b).toMatchObject({ url: '/index.abc.js', line: 5, col: 6 });
137
- expect(overlay.parseStackFrame('plain message')).toBeNull();
138
- });
139
- it('remaps a frame using a fetched map', async () => {
140
- globalThis.fetch = async () => ({
141
- ok: true,
142
- json: async () => ({ version: 3, sources: ['src/foo.ts'], mappings: 'AAAA;AACA' }),
143
- });
144
- const out = await overlay.symbolicateStack('Error: x\n at foo (http://localhost:3000/index.abc.js:2:1)');
145
- expect(out).toContain('src/foo.ts:2:1');
146
- });
147
- it('leaves the stack unchanged when no map is available', async () => {
148
- globalThis.fetch = async () => ({ ok: false, json: async () => ({}) });
149
- const stack = ' at foo (http://localhost:3000/missing.js:1:1)';
150
- expect(await overlay.symbolicateStack(stack)).toBe(stack);
151
- });
152
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,100 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { krateOn } from './events';
3
- import { createSignal, createEffect, disposeAll, krateHookState, krateFlushSync, krateRunEvent, krateTransitionWrites } from './signal';
4
- import { createEffectDeps } from './effects';
5
- const tick = () => new Promise((r) => setTimeout(r, 0));
6
- function mount(html) {
7
- document.body.innerHTML = '<div id="root">' + html + '</div>';
8
- return document.getElementById('root');
9
- }
10
- describe('discrete events flush synchronously', () => {
11
- beforeEach(() => disposeAll());
12
- it('commits render, layout and passive effects before the native event returns', async () => {
13
- mount('<button id="b">go</button><p id="p"></p>');
14
- const p = document.getElementById('p');
15
- const [n, setN] = createSignal(0, krateHookState);
16
- const log = [];
17
- createEffect(() => {
18
- p.textContent = String(n());
19
- });
20
- createEffectDeps(() => void log.push('layout ' + n()), () => [n()], 'layout');
21
- createEffectDeps(() => void log.push('passive ' + n()), () => [n()]);
22
- await tick();
23
- await tick();
24
- log.length = 0;
25
- krateOn(document.getElementById('b'), 'onClick', () => {
26
- setN(1);
27
- setN(2);
28
- queueMicrotask(() => log.push('microtask'));
29
- });
30
- document.getElementById('b').click();
31
- // One flush after all handlers ran: the batched value, effects included.
32
- expect(p.textContent).toBe('2');
33
- expect(log).toEqual(['layout 2', 'passive 2']);
34
- await tick();
35
- expect(log).toEqual(['layout 2', 'passive 2', 'microtask']);
36
- });
37
- it('flushes once per native event after capture and bubble handlers', () => {
38
- mount('<div id="outer"><button id="b">go</button></div>');
39
- const [n, setN] = createSignal(0, krateHookState);
40
- const renders = [];
41
- createEffect(() => void renders.push(n()));
42
- krateOn(document.getElementById('outer'), 'onClickCapture', () => setN((v) => v + 1));
43
- krateOn(document.getElementById('b'), 'onClick', () => setN((v) => v + 1));
44
- krateOn(document.getElementById('outer'), 'onClick', () => setN((v) => v + 1));
45
- document.getElementById('b').click();
46
- expect(renders).toEqual([0, 3]);
47
- });
48
- it('folds an event fired during the flush (blur of a removed node) into the same commit', () => {
49
- mount('<button id="b">go</button><input id="i">');
50
- const input = document.getElementById('i');
51
- const [a, setA] = createSignal(0, krateHookState);
52
- const [blurs, setBlurs] = createSignal(0, krateHookState);
53
- const commits = [];
54
- krateOn(input, 'onBlur', () => setBlurs((v) => v + 1));
55
- createEffect(() => {
56
- // A binding that, like removing a focused node, fires a native blur.
57
- if (a() === 1)
58
- input.dispatchEvent(new FocusEvent('focusout', { bubbles: true }));
59
- });
60
- createEffectDeps(() => void commits.push(a() + ':' + blurs()), () => [a(), blurs()], 'layout');
61
- krateOn(document.getElementById('b'), 'onClick', () => setA(1));
62
- krateFlushSync();
63
- commits.length = 0;
64
- document.getElementById('b').click();
65
- expect(commits).toEqual(['1:1']);
66
- });
67
- it('keeps continuous events batched', async () => {
68
- mount('<div id="area"></div>');
69
- const area = document.getElementById('area');
70
- const [n, setN] = createSignal(0, krateHookState);
71
- const seen = [];
72
- createEffect(() => void seen.push(n()));
73
- krateOn(area, 'onMouseMove', () => setN(5));
74
- area.dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
75
- expect(seen).toEqual([0]);
76
- await tick();
77
- await tick();
78
- expect(seen).toEqual([0, 5]);
79
- });
80
- });
81
- describe('transition writes', () => {
82
- beforeEach(() => disposeAll());
83
- it('keeps a pending render committed by a submit until a later task', async () => {
84
- const [pending, setPending] = createSignal(false);
85
- const seen = [];
86
- createEffect(() => void seen.push('pending=' + pending()));
87
- krateRunEvent('submit', true, () => {
88
- setPending(true);
89
- // The action settles a microtask later; its updates are transitions.
90
- void Promise.resolve().then(() => krateTransitionWrites(() => setPending(false)));
91
- });
92
- seen.push('event returned');
93
- for (let i = 0; i < 3; i++)
94
- await Promise.resolve();
95
- seen.push('microtasks done');
96
- await tick();
97
- await tick();
98
- expect(seen).toEqual(['pending=false', 'pending=true', 'event returned', 'microtasks done', 'pending=false']);
99
- });
100
- });
@@ -1 +0,0 @@
1
- export {};
package/dist/dom.test.js DELETED
@@ -1,31 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { h, insert } from './dom';
3
- describe('h', () => {
4
- it('creates an element with attributes and text', () => {
5
- const el = h('div', { class: 'box', id: 'x' }, 'hello');
6
- expect(el.tagName).toBe('DIV');
7
- expect(el.getAttribute('class')).toBe('box');
8
- expect(el.id).toBe('x');
9
- expect(el.textContent).toBe('hello');
10
- });
11
- it('sets DOM properties for form controls', () => {
12
- const input = h('input', { value: 'abc' });
13
- expect(input.value).toBe('abc');
14
- });
15
- it('nests child nodes', () => {
16
- const child = h('span', null, 'hi');
17
- const parent = h('div', null, child);
18
- expect(parent.firstChild).toBe(child);
19
- });
20
- });
21
- describe('insert', () => {
22
- it('replaces content between comment markers', () => {
23
- const parent = document.createElement('div');
24
- const start = document.createComment('k');
25
- const end = document.createComment('k');
26
- parent.append(start, document.createTextNode('old'), end);
27
- insert(parent, 'new', start);
28
- expect(parent.textContent).toBe('new');
29
- expect(parent.textContent.includes('old')).toBe(false);
30
- });
31
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,163 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};