@krate/runtime 0.5.0-rc.1 → 0.5.0-rc.11

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 (214) 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 +470 -77
  22. package/dist/dom.js +18 -3
  23. package/dist/effects.js +2 -2
  24. package/dist/flight-props.d.ts +7 -0
  25. package/dist/flight-props.js +105 -0
  26. package/dist/handler-html.js +4 -4
  27. package/dist/handler-routing.d.ts +2 -23
  28. package/dist/handler-routing.js +9 -190
  29. package/dist/handler-segments.d.ts +6 -0
  30. package/dist/handler-segments.js +18 -4
  31. package/dist/head-tags.d.ts +9 -0
  32. package/dist/head-tags.js +93 -6
  33. package/dist/highlight-bind.js +1 -1
  34. package/dist/highlight.d.ts +3 -2
  35. package/dist/highlight.js +17 -12
  36. package/dist/hints.d.ts +25 -2
  37. package/dist/hints.js +147 -74
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +3 -0
  40. package/dist/island-swap.d.ts +47 -0
  41. package/dist/island-swap.js +635 -0
  42. package/dist/jsx-dev-runtime.d.ts +1 -1
  43. package/dist/jsx-types.d.ts +99 -3
  44. package/dist/krate-core.js +1 -1
  45. package/dist/krate-dev.js +385 -66
  46. package/dist/krate-f-actions.js +1 -1
  47. package/dist/krate-f-classes.js +1 -1
  48. package/dist/krate-f-highlight.js +1 -1
  49. package/dist/krate-f-list.js +1 -1
  50. package/dist/krate-f-navigation.js +1 -1
  51. package/dist/krate-f-router-lite.js +1 -1
  52. package/dist/krate-f-router.js +1 -1
  53. package/dist/krate-features.json +454 -0
  54. package/dist/krate-hydrate-lite.js +5 -5
  55. package/dist/krate-hydrate.js +5 -5
  56. package/dist/krate-island-swap.js +1 -0
  57. package/dist/krate-runtime.js +5 -5
  58. package/dist/list.d.ts +14 -4
  59. package/dist/list.js +4 -5
  60. package/dist/metadata.js +5 -2
  61. package/dist/navigation-react.d.ts +13 -0
  62. package/dist/navigation-react.js +86 -0
  63. package/dist/navigation.d.ts +19 -0
  64. package/dist/navigation.js +35 -0
  65. package/dist/node-server.js +3 -3
  66. package/dist/og.js +1 -1
  67. package/dist/platform.d.ts +52 -0
  68. package/dist/platform.js +57 -0
  69. package/dist/react-compat.d.ts +39 -0
  70. package/dist/react-compat.js +359 -0
  71. package/dist/react-server.d.ts +63 -0
  72. package/dist/react-server.js +125 -0
  73. package/dist/region-wire.d.ts +10 -0
  74. package/dist/region-wire.js +154 -0
  75. package/dist/request-context.js +1 -1
  76. package/dist/request-extras.d.ts +4 -0
  77. package/dist/request-extras.js +51 -0
  78. package/dist/resp.js +1 -1
  79. package/dist/route-source.d.ts +39 -0
  80. package/dist/route-source.js +532 -0
  81. package/dist/router-lite.js +3 -9
  82. package/dist/router.d.ts +1 -1
  83. package/dist/router.js +628 -98
  84. package/dist/server-handler.d.ts +69 -1
  85. package/dist/server-handler.js +515 -96
  86. package/dist/server-renderer.js +16 -7
  87. package/dist/server.d.ts +73 -16
  88. package/dist/server.js +619 -102
  89. package/dist/sha256.js +9 -9
  90. package/dist/signal.js +0 -6
  91. package/dist/site-config.d.ts +15 -0
  92. package/dist/site-config.js +28 -0
  93. package/dist/slot.d.ts +12 -0
  94. package/dist/slot.js +23 -0
  95. package/dist/ssr-core.d.ts +2 -0
  96. package/dist/ssr-core.js +12 -4
  97. package/dist/testing.d.ts +62 -0
  98. package/dist/testing.js +90 -0
  99. package/dist/use-id.js +1 -1
  100. package/package.json +28 -3
  101. package/dist/action-context.test.d.ts +0 -1
  102. package/dist/action-context.test.js +0 -72
  103. package/dist/actions.test.d.ts +0 -1
  104. package/dist/actions.test.js +0 -477
  105. package/dist/cache-adapter.test.d.ts +0 -1
  106. package/dist/cache-adapter.test.js +0 -244
  107. package/dist/cache.test.d.ts +0 -1
  108. package/dist/cache.test.js +0 -233
  109. package/dist/class-component.test.d.ts +0 -1
  110. package/dist/class-component.test.js +0 -462
  111. package/dist/class-helpers.test.d.ts +0 -1
  112. package/dist/class-helpers.test.js +0 -169
  113. package/dist/context.test.d.ts +0 -1
  114. package/dist/context.test.js +0 -57
  115. package/dist/derived.test.d.ts +0 -1
  116. package/dist/derived.test.js +0 -140
  117. package/dist/dev-overlay.test.d.ts +0 -1
  118. package/dist/dev-overlay.test.js +0 -165
  119. package/dist/discrete.test.d.ts +0 -1
  120. package/dist/discrete.test.js +0 -100
  121. package/dist/dom.test.d.ts +0 -1
  122. package/dist/dom.test.js +0 -39
  123. package/dist/effect-errors.test.d.ts +0 -1
  124. package/dist/effect-errors.test.js +0 -199
  125. package/dist/effects.test.d.ts +0 -1
  126. package/dist/effects.test.js +0 -485
  127. package/dist/events.test.d.ts +0 -1
  128. package/dist/events.test.js +0 -447
  129. package/dist/handler-html.test.d.ts +0 -1
  130. package/dist/handler-html.test.js +0 -256
  131. package/dist/handler-routing.test.d.ts +0 -1
  132. package/dist/handler-routing.test.js +0 -99
  133. package/dist/handler-segments.test.d.ts +0 -1
  134. package/dist/handler-segments.test.js +0 -217
  135. package/dist/head-tags.test.d.ts +0 -1
  136. package/dist/head-tags.test.js +0 -131
  137. package/dist/highlight-bind.test.d.ts +0 -1
  138. package/dist/highlight-bind.test.js +0 -124
  139. package/dist/highlight.test.d.ts +0 -1
  140. package/dist/highlight.test.js +0 -56
  141. package/dist/lanes.test.d.ts +0 -1
  142. package/dist/lanes.test.js +0 -59
  143. package/dist/list.test.d.ts +0 -1
  144. package/dist/list.test.js +0 -435
  145. package/dist/metadata.test.d.ts +0 -1
  146. package/dist/metadata.test.js +0 -167
  147. package/dist/navigation.test.d.ts +0 -1
  148. package/dist/navigation.test.js +0 -130
  149. package/dist/node-server.test.d.ts +0 -1
  150. package/dist/node-server.test.js +0 -492
  151. package/dist/optimistic-lanes.test.d.ts +0 -1
  152. package/dist/optimistic-lanes.test.js +0 -45
  153. package/dist/patterns.test.d.ts +0 -1
  154. package/dist/patterns.test.js +0 -125
  155. package/dist/portal.test.d.ts +0 -1
  156. package/dist/portal.test.js +0 -99
  157. package/dist/react-effects.test.d.ts +0 -1
  158. package/dist/react-effects.test.js +0 -133
  159. package/dist/react-suspense.test.d.ts +0 -1
  160. package/dist/react-suspense.test.js +0 -194
  161. package/dist/react.test.d.ts +0 -1
  162. package/dist/react.test.js +0 -60
  163. package/dist/react19.test.d.ts +0 -1
  164. package/dist/react19.test.js +0 -176
  165. package/dist/reactivity-core.test.d.ts +0 -1
  166. package/dist/reactivity-core.test.js +0 -152
  167. package/dist/reconcile.test.d.ts +0 -1
  168. package/dist/reconcile.test.js +0 -110
  169. package/dist/refs.test.d.ts +0 -1
  170. package/dist/refs.test.js +0 -257
  171. package/dist/router-layout.test.d.ts +0 -1
  172. package/dist/router-layout.test.js +0 -249
  173. package/dist/router-nav.test.d.ts +0 -1
  174. package/dist/router-nav.test.js +0 -559
  175. package/dist/router-slots.test.d.ts +0 -1
  176. package/dist/router-slots.test.js +0 -144
  177. package/dist/router-speculation.test.d.ts +0 -1
  178. package/dist/router-speculation.test.js +0 -25
  179. package/dist/router-styles.test.d.ts +0 -1
  180. package/dist/router-styles.test.js +0 -98
  181. package/dist/router.test.d.ts +0 -1
  182. package/dist/router.test.js +0 -36
  183. package/dist/server-async.test.d.ts +0 -1
  184. package/dist/server-async.test.js +0 -216
  185. package/dist/server-handler.test.d.ts +0 -1
  186. package/dist/server-handler.test.js +0 -535
  187. package/dist/server-highlight.test.d.ts +0 -1
  188. package/dist/server-highlight.test.js +0 -32
  189. package/dist/server-renderer.test.d.ts +0 -1
  190. package/dist/server-renderer.test.js +0 -266
  191. package/dist/server.test.d.ts +0 -1
  192. package/dist/server.test.js +0 -88
  193. package/dist/sha256.test.d.ts +0 -1
  194. package/dist/sha256.test.js +0 -13
  195. package/dist/signal-lanes.test.d.ts +0 -1
  196. package/dist/signal-lanes.test.js +0 -32
  197. package/dist/signal.test.d.ts +0 -1
  198. package/dist/signal.test.js +0 -68
  199. package/dist/slots.test.d.ts +0 -1
  200. package/dist/slots.test.js +0 -187
  201. package/dist/snapshots.test.d.ts +0 -1
  202. package/dist/snapshots.test.js +0 -208
  203. package/dist/ssr-core-behavior.test.d.ts +0 -1
  204. package/dist/ssr-core-behavior.test.js +0 -620
  205. package/dist/ssr-core.test.d.ts +0 -1
  206. package/dist/ssr-core.test.js +0 -324
  207. package/dist/static-memory.test.d.ts +0 -1
  208. package/dist/static-memory.test.js +0 -26
  209. package/dist/storage.test.d.ts +0 -1
  210. package/dist/storage.test.js +0 -46
  211. package/dist/suspense-actions.test.d.ts +0 -1
  212. package/dist/suspense-actions.test.js +0 -72
  213. package/dist/suspense.test.d.ts +0 -1
  214. package/dist/suspense.test.js +0 -556
@@ -1,187 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { readFileSync } from 'node:fs';
3
- import { fileURLToPath } from 'node:url';
4
- import { dirname, resolve } from 'node:path';
5
- import { krateCondSwap, krateCondDetached, krateCondReset, krateSanitizeAttr, BLOCKED_URL } from './slots';
6
- import { createSignal, createEffect } from './signal';
7
- import { reconcileTrees } from './reconcile';
8
- const tick = () => new Promise((r) => setTimeout(r, 0));
9
- function startMarker(root, id) {
10
- const w = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
11
- while (w.nextNode()) {
12
- if (w.currentNode.nodeValue === 'k:' + id)
13
- return w.currentNode;
14
- }
15
- throw new Error('marker not found: ' + id);
16
- }
17
- describe('krateCondSwap', () => {
18
- // happy-dom does not parse <tr> inside <template> per spec, so the
19
- // table-context case is covered by the Go emitter tests and the browser
20
- // conformance suite; the swap mechanics are identical for any element.
21
- it('swaps the active branch with the template branch', () => {
22
- document.body.innerHTML =
23
- '<ol><!--k:c1--><li>yes</li><!--/k:c1--></ol>' +
24
- '<template data-kc="c1" data-kb="a"><li>no</li></template>';
25
- const start = startMarker(document.body, 'c1');
26
- const tpl = document.querySelector('template[data-kc="c1"]');
27
- const tbody = document.querySelector('ol');
28
- const yesRow = tbody.querySelector('li');
29
- krateCondSwap(start, true, tpl);
30
- expect(tbody.textContent).toBe('yes');
31
- krateCondSwap(start, false, tpl);
32
- expect(tbody.querySelectorAll('li').length).toBe(1);
33
- expect(tbody.textContent).toBe('no');
34
- krateCondSwap(start, true, tpl);
35
- // The original (hydrated) node comes back, not a clone.
36
- expect(tbody.querySelector('li')).toBe(yesRow);
37
- });
38
- it('keeps bindings made on template content alive after the swap', async () => {
39
- document.body.innerHTML =
40
- '<ul><!--k:c2--><li>a</li><!--/k:c2--></ul><template data-kc="c2" data-kb="a"><li><button>b</button></li></template>';
41
- const tpl = document.querySelector('template');
42
- const btn = tpl.content.querySelector('button');
43
- let clicks = 0;
44
- btn.addEventListener('click', () => clicks++);
45
- const [on, setOn] = createSignal(true);
46
- const start = startMarker(document.body, 'c2');
47
- createEffect(() => krateCondSwap(start, !!on(), tpl));
48
- expect(document.querySelector('ul').textContent).toBe('a');
49
- setOn(false);
50
- await tick();
51
- const live = document.querySelector('ul button');
52
- expect(live).toBe(btn);
53
- live.click();
54
- expect(clicks).toBe(1);
55
- });
56
- it('starts from the consequent when the template holds it', () => {
57
- document.body.innerHTML = '<p><!--k:c3--><i>no</i><!--/k:c3--></p><template data-kc="c3" data-kb="c"><b>yes</b></template>';
58
- const start = startMarker(document.body, 'c3');
59
- const tpl = document.querySelector('template');
60
- krateCondSwap(start, false, tpl);
61
- expect(document.querySelector('p').innerHTML).toBe('<!--k:c3--><i>no</i><!--/k:c3-->');
62
- krateCondSwap(start, true, tpl);
63
- expect(document.querySelector('p').innerHTML).toBe('<!--k:c3--><b>yes</b><!--/k:c3-->');
64
- });
65
- it('treats a missing template as an empty branch', () => {
66
- document.body.innerHTML = '<div><!--k:c4--><b>x</b><!--/k:c4--></div>';
67
- const start = startMarker(document.body, 'c4');
68
- krateCondSwap(start, true, null);
69
- krateCondSwap(start, false, null);
70
- expect(document.querySelector('div').innerHTML).toBe('<!--k:c4--><!--/k:c4-->');
71
- krateCondSwap(start, true, null);
72
- expect(document.querySelector('div').textContent).toBe('x');
73
- });
74
- });
75
- describe('krateSanitizeAttr', () => {
76
- it('blocks javascript: URLs like React 19', () => {
77
- expect(krateSanitizeAttr('href', 'javascript:alert(1)')).toBe(BLOCKED_URL);
78
- expect(krateSanitizeAttr('src', ' \tJaVa\nScript:x')).toBe(BLOCKED_URL);
79
- expect(krateSanitizeAttr('xlink:href', 'javascript:x')).toBe(BLOCKED_URL);
80
- expect(krateSanitizeAttr('href', '/safe')).toBe('/safe');
81
- expect(krateSanitizeAttr('title', 'javascript:x')).toBe('javascript:x');
82
- });
83
- });
84
- describe('reconcile with conditional templates', () => {
85
- it('replaces a template whose content changed', () => {
86
- document.body.innerHTML = '<div id="root"><p>x</p><template data-kc="c1" data-kb="a"><b>old</b></template></div>';
87
- const root = document.getElementById('root');
88
- const next = document.createElement('div');
89
- next.id = 'root';
90
- next.innerHTML = '<p>x</p><template data-kc="c1" data-kb="a"><b>new</b></template>';
91
- reconcileTrees(root, next);
92
- const tpl = root.querySelector('template');
93
- expect(tpl.innerHTML).toBe('<b>new</b>');
94
- });
95
- });
96
- // The hydration bootstrap ships as a Go string constant appended to the
97
- // runtime chunk; run the real source against compiler-shaped markup.
98
- function loadBootstrap() {
99
- const here = dirname(fileURLToPath(import.meta.url));
100
- const src = readFileSync(resolve(here, '../../compiler/internal/renderer/newhydrate.go'), 'utf8');
101
- const start = src.indexOf('const HydrationBootstrapJS = `') + 'const HydrationBootstrapJS = `'.length;
102
- const end = src.indexOf('`\n', start);
103
- return src.slice(start, end);
104
- }
105
- describe('hydration bootstrap', () => {
106
- beforeEach(() => {
107
- const w = window;
108
- w.createEffect = createEffect;
109
- w.krateCondSwap = krateCondSwap;
110
- w.krateCondDetached = krateCondDetached;
111
- w.krateCondReset = krateCondReset;
112
- w.krateSanitizeAttr = krateSanitizeAttr;
113
- });
114
- it('binds handlers and text inside the inactive branch template, then toggles', async () => {
115
- document.body.innerHTML =
116
- '<div id="root"><ul><!--k:c--><li>on</li><!--/k:c--></ul>' +
117
- '<template data-kc="c" data-kb="a"><li><button data-k="k:btn">off</button><!--k:t-->0<!--/k:t--></li></template></div>';
118
- new Function(loadBootstrap())();
119
- const w = window;
120
- const [on, setOn] = createSignal(true);
121
- const [n, setN] = createSignal(0);
122
- let clicked = 0;
123
- w.kbindCond('c', () => on());
124
- w.kbindText('t', () => n());
125
- expect(w.findSlot('btn')).not.toBe(null);
126
- w.kbindEvent('btn', 'click', () => clicked++, false);
127
- expect(w.__krateErrs).toEqual([]);
128
- setN(5);
129
- setOn(false);
130
- await tick();
131
- const tbody = document.querySelector('ul');
132
- expect(tbody.textContent).toBe('off5');
133
- tbody.querySelector('button').click();
134
- expect(clicked).toBe(1);
135
- setOn(true);
136
- await tick();
137
- expect(tbody.textContent).toBe('on');
138
- setN(7);
139
- setOn(false);
140
- await tick();
141
- expect(tbody.textContent).toBe('off7');
142
- });
143
- it('renders bigint, and primitives inside arrays, as text in a content slot', async () => {
144
- document.body.innerHTML = '<div id="root"><p><!--k:v-->0<!--/k:v--></p></div>';
145
- new Function(loadBootstrap())();
146
- const w = window;
147
- const [val, setVal] = createSignal(5n / 2n);
148
- w.kbindContent('v', () => val());
149
- const p = document.querySelector('p');
150
- expect(w.__krateErrs).toEqual([]);
151
- await tick();
152
- expect(p.textContent).toBe('2');
153
- setVal(['a', 3, 7n, null, false]);
154
- await tick();
155
- expect(w.__krateErrs).toEqual([]);
156
- expect(p.textContent).toBe('a37');
157
- setVal(12345678901234567890n);
158
- await tick();
159
- expect(p.textContent).toBe('12345678901234567890');
160
- });
161
- it('finds nodes of a branch swapped out before its binding ran', async () => {
162
- document.body.innerHTML =
163
- '<div id="root"><p><!--k:c--><button data-k="k:b">ssr</button><!--/k:c--></p>' +
164
- '<template data-kc="c" data-kb="a"><i>client</i></template></div>';
165
- new Function(loadBootstrap())();
166
- const w = window;
167
- // The client state disagrees with the SSR state: the first run swaps.
168
- w.kbindCond('c', () => false);
169
- expect(document.querySelector('p').textContent).toBe('client');
170
- let clicks = 0;
171
- w.kbindEvent('b', 'click', () => clicks++, false);
172
- expect(w.findSlot('b')).not.toBe(null);
173
- w.findSlot('b').click();
174
- expect(clicks).toBe(1);
175
- });
176
- it('neutralizes javascript: URLs set by attribute bindings', async () => {
177
- document.body.innerHTML = '<div id="root"><a data-k="k:a">x</a></div>';
178
- new Function(loadBootstrap())();
179
- const [href, setHref] = createSignal('/ok');
180
- window.kbindAttr('a', 'href', () => href());
181
- const a = document.querySelector('a');
182
- expect(a.getAttribute('href')).toBe('/ok');
183
- setHref('javascript:alert(1)');
184
- await tick();
185
- expect(a.getAttribute('href')).toBe(BLOCKED_URL);
186
- });
187
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,208 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { createSignal, createReducer, createEffect, disposeAll, krateHookState, krateFlushSync } from './signal';
3
- import { createEffectDeps, krateOwner, krateMount, krateCondActivity, krateOnUnmount } from './effects';
4
- const tick = () => new Promise((r) => setTimeout(r, 0));
5
- async function settle() {
6
- for (let i = 0; i < 4; i++)
7
- await tick();
8
- }
9
- // Runs fn as if inside a native click listener (a discrete event).
10
- function inClick(fn) {
11
- const btn = document.createElement('button');
12
- document.body.appendChild(btn);
13
- // Browsers expose the event being dispatched as window.event; happy-dom
14
- // does not, so provide it the way a browser would.
15
- btn.addEventListener('click', (e) => {
16
- const w = window;
17
- const prev = w.event;
18
- w.event = e;
19
- try {
20
- fn();
21
- }
22
- finally {
23
- w.event = prev;
24
- }
25
- });
26
- btn.click();
27
- btn.remove();
28
- }
29
- describe('render snapshots for React state', () => {
30
- beforeEach(() => disposeAll());
31
- it('reads the committed value in handlers, so repeated setState(x + 1) adds one', async () => {
32
- const [count, setCount] = createSignal(0, krateHookState);
33
- inClick(() => {
34
- setCount(count() + 1);
35
- setCount(count() + 1);
36
- setCount(count() + 1);
37
- });
38
- await settle();
39
- expect(count()).toBe(1);
40
- });
41
- it('keeps functional updaters on the latest pending value', async () => {
42
- const [count, setCount] = createSignal(0, krateHookState);
43
- inClick(() => {
44
- setCount((c) => c + 1);
45
- setCount((c) => c + 1);
46
- expect(count()).toBe(0); // still the render's snapshot
47
- });
48
- await settle();
49
- expect(count()).toBe(2);
50
- });
51
- it('lets bindings (the render phase) see the latest value', async () => {
52
- const [count, setCount] = createSignal(0, krateHookState);
53
- const seen = [];
54
- createEffect(() => void seen.push(count()));
55
- inClick(() => setCount(5));
56
- await settle();
57
- expect(seen).toEqual([0, 5]);
58
- });
59
- it('runs cleanups with the values of the render their effect ran for', async () => {
60
- const [room, setRoom] = createSignal('general', krateHookState);
61
- const log = [];
62
- createEffectDeps(() => {
63
- log.push('connect ' + room());
64
- return () => log.push('disconnect ' + room());
65
- }, () => [room()]);
66
- await settle();
67
- inClick(() => setRoom('random'));
68
- await settle();
69
- inClick(() => setRoom('music'));
70
- await settle();
71
- expect(log).toEqual(['connect general', 'disconnect general', 'connect random', 'disconnect random', 'connect music']);
72
- });
73
- it('gives a second effect the committed value while the first sets state', async () => {
74
- const [text] = createSignal('hello', krateHookState);
75
- const [words, setWords] = createSignal(0, krateHookState);
76
- const log = [];
77
- createEffectDeps(() => {
78
- log.push('count ' + text());
79
- setWords(1);
80
- }, () => [text()]);
81
- createEffectDeps(() => void log.push('words ' + words()), () => [words()]);
82
- await settle();
83
- expect(log).toEqual(['count hello', 'words 0', 'words 1']);
84
- });
85
- it('does not change native signal semantics', () => {
86
- const [n, setN] = createSignal(0);
87
- setN(n() + 1);
88
- setN(n() + 1);
89
- expect(n()).toBe(2);
90
- });
91
- it('applies reducer options and the lazy initializer', async () => {
92
- const [s, dispatch] = createReducer((st, a) => st + a, 2, (x) => x * 10, krateHookState);
93
- expect(s()).toBe(20);
94
- inClick(() => {
95
- dispatch(1);
96
- expect(s()).toBe(20);
97
- });
98
- await settle();
99
- expect(s()).toBe(21);
100
- });
101
- });
102
- describe('update lanes', () => {
103
- beforeEach(() => disposeAll());
104
- it('flushes passive effects of a discrete update before the handler microtask', async () => {
105
- const [n, setN] = createSignal(0, krateHookState);
106
- const log = [];
107
- createEffectDeps(() => void log.push('passive ' + n()), () => [n()]);
108
- await settle();
109
- log.length = 0;
110
- inClick(() => {
111
- setN((v) => v + 1);
112
- queueMicrotask(() => log.push('microtask'));
113
- });
114
- await settle();
115
- expect(log).toEqual(['passive 1', 'microtask']);
116
- });
117
- it('commits a non-discrete update after the microtasks queued with it', async () => {
118
- const [n, setN] = createSignal(0, krateHookState);
119
- const log = [];
120
- createEffectDeps(() => void log.push('layout ' + n()), () => [n()], 'layout');
121
- await settle();
122
- log.length = 0;
123
- setTimeout(() => {
124
- setN(10);
125
- queueMicrotask(() => log.push('microtask'));
126
- }, 0);
127
- await settle();
128
- expect(log).toEqual(['microtask', 'layout 10']);
129
- });
130
- it('flushes synchronously on demand', () => {
131
- const [n, setN] = createSignal(0, krateHookState);
132
- const seen = [];
133
- createEffect(() => void seen.push(n()));
134
- setN(3);
135
- krateFlushSync();
136
- expect(seen).toEqual([0, 3]);
137
- expect(n()).toBe(3);
138
- });
139
- });
140
- describe('remountable conditional branches', () => {
141
- beforeEach(() => disposeAll());
142
- it('unmounts on hide and mounts a fresh instance on show', async () => {
143
- const log = [];
144
- const setters = [];
145
- const getters = [];
146
- const unmounted = [];
147
- krateOnUnmount((_owner, id) => unmounted.push(id));
148
- krateOwner('P', null);
149
- krateMount('C', 'P', [['5', 'c', 1]], null, () => {
150
- const [count, setCount] = createSignal(0, krateHookState);
151
- setters.push(setCount);
152
- getters.push(count);
153
- createEffectDeps(() => {
154
- log.push('mount ' + count());
155
- return () => log.push('unmount ' + count());
156
- }, () => []);
157
- });
158
- krateOwner(null);
159
- await settle();
160
- setters[0](2);
161
- await settle();
162
- expect(getters[0]()).toBe(2);
163
- krateCondActivity('5', 'a');
164
- await settle();
165
- krateCondActivity('5', 'c');
166
- await settle();
167
- expect(getters.length).toBe(2);
168
- expect(getters[1]()).toBe(0);
169
- expect(log).toEqual(['mount 0', 'unmount 0', 'mount 0']);
170
- expect(unmounted).toEqual(['C']);
171
- });
172
- it('defers a component in the initially hidden branch until it is shown', async () => {
173
- let runs = 0;
174
- krateOwner('P', null);
175
- krateCondActivity('9', 'c');
176
- krateMount('Alt', 'P', [['9', 'a', 0]], null, () => {
177
- runs++;
178
- });
179
- krateOwner(null);
180
- await settle();
181
- expect(runs).toBe(0);
182
- krateCondActivity('9', 'a');
183
- expect(runs).toBe(1);
184
- });
185
- it('remounts nested components under their fresh parent', async () => {
186
- const order = [];
187
- krateOwner('P', null);
188
- krateMount('C', 'P', [['5', 'c', 1]], null, () => void order.push('C'));
189
- krateMount('G', 'C', [['5', 'c', 1]], null, () => void order.push('G'));
190
- krateOwner(null);
191
- krateCondActivity('5', 'a');
192
- krateCondActivity('5', 'c');
193
- expect(order).toEqual(['C', 'G', 'C', 'G']);
194
- });
195
- it('disposes the bindings of an unmounted instance', async () => {
196
- const [n, setN] = createSignal(0);
197
- const seen = [];
198
- krateOwner('P', null);
199
- krateMount('C', 'P', [['5', 'c', 1]], null, () => {
200
- createEffect(() => void seen.push(n()));
201
- });
202
- krateOwner(null);
203
- krateCondActivity('5', 'a');
204
- setN(1);
205
- await settle();
206
- expect(seen).toEqual([0]);
207
- });
208
- });
@@ -1 +0,0 @@
1
- export {};