@solidtv/solid 1.1.1 → 1.1.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 (99) hide show
  1. package/dist/src/core/clickInspector.d.ts +1 -0
  2. package/dist/src/core/clickInspector.js +69 -0
  3. package/dist/src/core/clickInspector.js.map +1 -0
  4. package/dist/src/core/config.d.ts +1 -13
  5. package/dist/src/core/config.js +10 -2
  6. package/dist/src/core/config.js.map +1 -1
  7. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -1
  8. package/dist/src/core/dom-renderer/domRenderer.js +254 -67
  9. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  10. package/dist/src/core/elementNode.d.ts +20 -7
  11. package/dist/src/core/elementNode.js +54 -14
  12. package/dist/src/core/elementNode.js.map +1 -1
  13. package/dist/src/core/focusManager.js +5 -3
  14. package/dist/src/core/focusManager.js.map +1 -1
  15. package/dist/src/core/intrinsicTypes.d.ts +2 -0
  16. package/dist/src/core/lightningInit.d.ts +1 -1
  17. package/dist/src/core/lightningInit.js +6 -6
  18. package/dist/src/core/lightningInit.js.map +1 -1
  19. package/dist/src/core/utils.js +4 -4
  20. package/dist/src/core/utils.js.map +1 -1
  21. package/dist/src/primitives/Column.jsx +1 -1
  22. package/dist/src/primitives/Column.jsx.map +1 -1
  23. package/dist/src/primitives/FPSCounter.jsx +5 -5
  24. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  25. package/dist/src/primitives/Image.jsx +6 -1
  26. package/dist/src/primitives/Image.jsx.map +1 -1
  27. package/dist/src/primitives/KeepAlive.d.ts +4 -3
  28. package/dist/src/primitives/KeepAlive.jsx +60 -23
  29. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  30. package/dist/src/primitives/LazyImport.js +4 -2
  31. package/dist/src/primitives/LazyImport.js.map +1 -1
  32. package/dist/src/primitives/Preserve.jsx +10 -4
  33. package/dist/src/primitives/Preserve.jsx.map +1 -1
  34. package/dist/src/primitives/Row.jsx +1 -1
  35. package/dist/src/primitives/Row.jsx.map +1 -1
  36. package/dist/src/primitives/Suspense.jsx +7 -7
  37. package/dist/src/primitives/Suspense.jsx.map +1 -1
  38. package/dist/src/primitives/Virtual.jsx +1 -1
  39. package/dist/src/primitives/Virtual.jsx.map +1 -1
  40. package/dist/src/primitives/announcer/announcer.js +3 -2
  41. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  42. package/dist/src/primitives/announcer/speech.js +2 -2
  43. package/dist/src/primitives/announcer/speech.js.map +1 -1
  44. package/dist/src/primitives/borderBox.jsx +2 -1
  45. package/dist/src/primitives/borderBox.jsx.map +1 -1
  46. package/dist/src/primitives/createTag.jsx +3 -3
  47. package/dist/src/primitives/createTag.jsx.map +1 -1
  48. package/dist/src/primitives/portal.jsx +4 -3
  49. package/dist/src/primitives/portal.jsx.map +1 -1
  50. package/dist/src/primitives/utils/chainFunctions.js +35 -9
  51. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  52. package/dist/src/primitives/utils/createBlurredImage.js +57 -37
  53. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -1
  54. package/dist/src/primitives/utils/handleNavigation.js +21 -16
  55. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  56. package/dist/src/primitives/utils/withScrolling.js +1 -3
  57. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  58. package/dist/src/render.d.ts +1 -1
  59. package/dist/src/render.js +2 -1
  60. package/dist/src/render.js.map +1 -1
  61. package/dist/src/solidOpts.d.ts +1 -1
  62. package/dist/src/solidOpts.js +4 -2
  63. package/dist/src/solidOpts.js.map +1 -1
  64. package/dist/src/utils.js +10 -5
  65. package/dist/src/utils.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/docs/README.md +2 -2
  68. package/package.json +28 -29
  69. package/src/core/clickInspector.ts +77 -0
  70. package/src/core/config.ts +6 -20
  71. package/src/core/dom-renderer/domRenderer.ts +307 -89
  72. package/src/core/dom-renderer/domRendererTypes.ts +9 -6
  73. package/src/core/elementNode.ts +80 -26
  74. package/src/core/focusManager.ts +16 -8
  75. package/src/core/intrinsicTypes.ts +19 -7
  76. package/src/core/lightningInit.ts +20 -18
  77. package/src/core/utils.ts +4 -4
  78. package/src/primitives/Column.tsx +0 -1
  79. package/src/primitives/FPSCounter.tsx +14 -10
  80. package/src/primitives/Image.tsx +18 -9
  81. package/src/primitives/KeepAlive.tsx +88 -44
  82. package/src/primitives/LazyImport.ts +8 -6
  83. package/src/primitives/Preserve.tsx +13 -8
  84. package/src/primitives/Row.tsx +0 -1
  85. package/src/primitives/Suspense.tsx +10 -9
  86. package/src/primitives/Virtual.tsx +1 -9
  87. package/src/primitives/announcer/announcer.ts +3 -2
  88. package/src/primitives/announcer/speech.ts +2 -2
  89. package/src/primitives/borderBox.tsx +7 -3
  90. package/src/primitives/createTag.tsx +23 -17
  91. package/src/primitives/portal.tsx +20 -10
  92. package/src/primitives/utils/chainFunctions.ts +31 -11
  93. package/src/primitives/utils/createBlurredImage.ts +58 -40
  94. package/src/primitives/utils/handleNavigation.ts +29 -18
  95. package/src/primitives/utils/withScrolling.ts +3 -5
  96. package/src/render.ts +4 -4
  97. package/src/solidOpts.ts +9 -7
  98. package/src/types.ts +0 -1
  99. package/src/utils.ts +12 -10
@@ -5,12 +5,15 @@ import { chainFunctions } from './utils/chainFunctions.js';
5
5
 
6
6
  export interface KeepAliveElement {
7
7
  id: string;
8
- owner: s.Owner | null;
9
- children: s.JSX.Element;
8
+ // owner / children / dispose are populated lazily — the preload path
9
+ // creates a partial entry holding only `id` + `isAlive` until the route
10
+ // mounts, so callers must null-check before use.
11
+ owner?: s.Owner | null;
12
+ children?: s.JSX.Element;
10
13
  routeSignal?: s.Signal<unknown>;
11
14
  isAlive?: s.Accessor<boolean>;
12
15
  setIsAlive?: (v: boolean) => void;
13
- dispose: () => void;
16
+ dispose?: () => void;
14
17
  }
15
18
 
16
19
  const keepAliveElements = new Map<string, KeepAliveElement>();
@@ -40,7 +43,7 @@ const _removeKeepAlive = (
40
43
  ): void => {
41
44
  const element = map.get(id);
42
45
  if (element) {
43
- (element.children as unknown as ElementNode)?.destroy();
46
+ (element.children as unknown as ElementNode | undefined)?.destroy();
44
47
  element.dispose?.();
45
48
  map.delete(id);
46
49
  }
@@ -53,7 +56,7 @@ export const removeKeepAliveRoute = (id: string): void =>
53
56
 
54
57
  const _clearKeepAlive = (map: Map<string, KeepAliveElement>): void => {
55
58
  map.forEach((element) => {
56
- (element.children as unknown as ElementNode)?.destroy();
59
+ (element.children as unknown as ElementNode | undefined)?.destroy();
57
60
  element.dispose?.();
58
61
  });
59
62
  map.clear();
@@ -109,13 +112,13 @@ const createKeepAliveComponent = (
109
112
  ) => {
110
113
  return (props: s.ParentProps<KeepAliveProps>) => {
111
114
  let existing = map.get(props.id);
115
+ const existingChild = existing?.children as ElementNode | undefined;
112
116
 
113
117
  if (
114
118
  existing &&
115
- (props.shouldDispose?.(props.id) ||
116
- (existing.children as unknown as ElementNode)?.destroyed)
119
+ (props.shouldDispose?.(props.id) || existingChild?.destroyed)
117
120
  ) {
118
- (existing.children as unknown as ElementNode).destroy();
121
+ existingChild?.destroy();
119
122
  existing.dispose?.();
120
123
  map.delete(props.id);
121
124
  existing = undefined;
@@ -138,8 +141,8 @@ const createKeepAliveComponent = (
138
141
  });
139
142
  return children;
140
143
  });
141
- } else if (existing && !existing.children) {
142
- existing.children = s.runWithOwner(existing.owner, () =>
144
+ } else if (!existing.children) {
145
+ existing.children = s.runWithOwner(existing.owner ?? null, () =>
143
146
  wrapChildren(props, existing.setIsAlive),
144
147
  );
145
148
  }
@@ -156,6 +159,23 @@ const KeepAliveRouteInternal = createKeepAliveComponent(
156
159
  storeKeepAliveRoute,
157
160
  );
158
161
 
162
+ // Cache the resolved <Route> JSX per key. Solid Router uses the routeDef
163
+ // object itself as the route key (see @solidjs/router index.js:455), so if
164
+ // KeepAliveRoute ever gets re-evaluated, a new routeDef would drift the key
165
+ // and force routeStates to dispose + recreate sibling contexts (which would
166
+ // re-invoke their components). Returning the same JSX reference keeps the
167
+ // route key stable across re-evaluations.
168
+ //
169
+ // Note: this captures `props` at first invocation. If you rely on dynamic
170
+ // changes to KeepAliveRoute props (e.g., a reactive `transition` or `preload`
171
+ // reference), use a stable wrapper around them or clear this cache when
172
+ // they change.
173
+ const keepAliveRouteCache = new Map<string, s.JSX.Element>();
174
+
175
+ export const clearKeepAliveRouteCache = (): void => {
176
+ keepAliveRouteCache.clear();
177
+ };
178
+
159
179
  export const KeepAliveRoute = <S extends string>(
160
180
  props: RouteProps<S> & {
161
181
  id?: string;
@@ -173,24 +193,26 @@ export const KeepAliveRoute = <S extends string>(
173
193
  },
174
194
  ) => {
175
195
  const key = props.id || props.path;
196
+
197
+ const cached = keepAliveRouteCache.get(key);
198
+ if (cached) {
199
+ return cached;
200
+ }
201
+
176
202
  let savedFocusedElement: ElementNode | undefined;
177
203
 
178
- const getExisting = () => {
204
+ const getExisting = (): KeepAliveElement => {
179
205
  let existing = keepAliveRouteElements.get(key);
180
206
  if (!existing) {
181
207
  const [isAlive, setIsAlive] = s.createSignal(true);
182
- existing = {
183
- id: key,
184
- isAlive,
185
- setIsAlive,
186
- } as any;
187
- keepAliveRouteElements.set(key, existing!);
208
+ existing = { id: key, isAlive, setIsAlive };
209
+ keepAliveRouteElements.set(key, existing);
188
210
  }
189
- return existing!;
211
+ return existing;
190
212
  };
191
213
 
192
214
  const onRemove = chainFunctions(props.onRemove, (elm: ElementNode) => {
193
- savedFocusedElement = activeElement() as ElementNode;
215
+ savedFocusedElement = activeElement();
194
216
  elm.alpha = 0;
195
217
  });
196
218
 
@@ -216,13 +238,15 @@ export const KeepAliveRoute = <S extends string>(
216
238
  const preload = props.preload
217
239
  ? (preloadProps: RoutePreloadFuncArgs) => {
218
240
  let existing = getExisting();
241
+ const existingChild = existing.children as unknown as
242
+ | ElementNode
243
+ | undefined;
219
244
 
220
245
  if (
221
- existing.children &&
222
- (props.shouldDispose?.(key) ||
223
- (existing.children as unknown as ElementNode)?.destroyed)
246
+ existingChild &&
247
+ (props.shouldDispose?.(key) || existingChild.destroyed)
224
248
  ) {
225
- (existing.children as unknown as ElementNode).destroy();
249
+ existingChild.destroy();
226
250
  existing.dispose?.();
227
251
  keepAliveRouteElements.delete(key);
228
252
  existing = getExisting();
@@ -232,11 +256,17 @@ export const KeepAliveRoute = <S extends string>(
232
256
  return s.createRoot((dispose) => {
233
257
  existing.owner = s.getOwner();
234
258
  existing.dispose = dispose;
235
- return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
259
+ return props.preload!({
260
+ ...preloadProps,
261
+ isAlive: existing.isAlive!,
262
+ });
236
263
  });
237
264
  } else if (existing.children) {
238
- (existing.children as unknown as ElementNode)?.setFocus();
239
- return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
265
+ (existing.children as unknown as ElementNode).setFocus();
266
+ return props.preload!({
267
+ ...preloadProps,
268
+ isAlive: existing.isAlive!,
269
+ });
240
270
  } else {
241
271
  return props.preload!({
242
272
  ...preloadProps,
@@ -246,23 +276,37 @@ export const KeepAliveRoute = <S extends string>(
246
276
  }
247
277
  : undefined;
248
278
 
249
- return (
250
- <Route
251
- {...props}
252
- preload={preload}
253
- component={(childProps) => {
254
- const existing = getExisting();
255
- return (
256
- <KeepAliveRouteInternal
257
- id={key}
258
- onRemove={onRemove}
259
- onRender={onRender}
260
- transition={props.transition}
261
- >
262
- {props.component({ ...childProps, isAlive: existing.isAlive! })}
263
- </KeepAliveRouteInternal>
264
- );
265
- }}
266
- />
279
+ const componentWrapper = (childProps: RouteProps<S>) => {
280
+ const existing = getExisting();
281
+ // Do NOT spread `childProps`: it has a `children` getter (the router's
282
+ // outlet) that would be invoked eagerly, creating a <Show> subscribed to
283
+ // the next routeStates index. That stale Show would then fire when the
284
+ // user navigates to a sibling route whose matches populate that index,
285
+ // causing the sibling's component to be created from the preserved
286
+ // KeepAlive subtree. Inherit via prototype so the getter is preserved.
287
+ const innerProps = Object.create(childProps, {
288
+ isAlive: {
289
+ value: existing.isAlive!,
290
+ enumerable: true,
291
+ configurable: true,
292
+ },
293
+ }) as RouteProps<S> & { isAlive: s.Accessor<boolean> };
294
+ return (
295
+ <KeepAliveRouteInternal
296
+ id={key}
297
+ onRemove={onRemove}
298
+ onRender={onRender}
299
+ transition={props.transition}
300
+ >
301
+ {props.component(innerProps)}
302
+ </KeepAliveRouteInternal>
303
+ );
304
+ };
305
+
306
+ const routeElement = (
307
+ <Route {...props} preload={preload} component={componentWrapper} />
267
308
  );
309
+
310
+ keepAliveRouteCache.set(key, routeElement);
311
+ return routeElement;
268
312
  };
@@ -20,12 +20,14 @@ export function lazy<T extends Component<any>>(
20
20
  const [s, set] = createSignal<T>();
21
21
  sharedConfig.count || (sharedConfig.count = 0);
22
22
  sharedConfig.count++;
23
- (p || (p = fn())).then((mod) => {
24
- !sharedConfig.done && (sharedConfig.context = ctx);
25
- sharedConfig.count!--;
26
- set(() => mod.default);
27
- sharedConfig.context = undefined;
28
- });
23
+ (p || (p = fn()))
24
+ .then((mod) => {
25
+ !sharedConfig.done && (sharedConfig.context = ctx);
26
+ sharedConfig.count!--;
27
+ set(() => mod.default);
28
+ sharedConfig.context = undefined;
29
+ })
30
+ .catch(() => {});
29
31
  comp = s;
30
32
  } else if (!comp) {
31
33
  const [s] = createResource<T>(() =>
@@ -1,18 +1,23 @@
1
- import * as s from 'solid-js'
2
- import * as lng from '@solidtv/solid'
1
+ import * as s from 'solid-js';
2
+ import * as lng from '@solidtv/solid';
3
3
 
4
4
  function Preserve(props: lng.NodeProps): s.JSX.Element {
5
-
6
- const view = <view {...props} /> as any as lng.ElementNode
5
+ const view = (<view {...props} />) as unknown as lng.ElementNode;
7
6
 
8
7
  view.preserve = true;
9
8
 
10
- view.onRender ??= () => {view.hidden = false}
11
- view.onRemove ??= () => {view.hidden = true}
9
+ view.onRender ??= () => {
10
+ view.hidden = false;
11
+ };
12
+ view.onRemove ??= () => {
13
+ view.hidden = true;
14
+ };
12
15
 
13
- s.onCleanup(() => {view.destroy()})
16
+ s.onCleanup(() => {
17
+ view.destroy();
18
+ });
14
19
 
15
- return view as any as s.JSX.Element
20
+ return view as unknown as s.JSX.Element;
16
21
  }
17
22
 
18
23
  export default Preserve;
@@ -33,7 +33,6 @@ export const Row: Component<RowProps> = (props) => {
33
33
  <view
34
34
  transitionLeft={defaultTransitionBack}
35
35
  transitionRight={defaultTransitionForward}
36
- transition={/* @once */ {}}
37
36
  {...props}
38
37
  selected={props.selected || 0}
39
38
  onLeft={/* @once */ chainFunctions(props.onLeft, onLeft)}
@@ -21,19 +21,20 @@ export function Suspense(props: {
21
21
  fallback?: s.JSX.Element;
22
22
  children: s.JSX.Element;
23
23
  }): s.JSX.Element {
24
-
25
24
  let children: s.JSX.Element;
26
25
 
27
26
  const suspense = s.Suspense({
28
27
  get children() {
29
- return [children = s.children(() => props.children) as any];
28
+ return [(children = s.children(() => props.children) as any)];
30
29
  },
31
- }) as any as () => s.JSX.Element;
30
+ }) as unknown as () => s.JSX.Element;
32
31
 
33
- return <>
34
- {suspense() ?? props.fallback}
35
- <view hidden forwardFocus={0}>
36
- {suspense() ? null : children}
37
- </view>
38
- </>
32
+ return (
33
+ <>
34
+ {suspense() ?? props.fallback}
35
+ <view hidden forwardFocus={0}>
36
+ {suspense() ? null : children}
37
+ </view>
38
+ </>
39
+ );
39
40
  }
@@ -317,7 +317,6 @@ function createVirtual<T>(
317
317
  }
318
318
  break;
319
319
  }
320
-
321
320
  case 'none':
322
321
  default:
323
322
  start = 0;
@@ -405,13 +404,7 @@ function createVirtual<T>(
405
404
  originalPosition = originalPosition ?? elm[axis];
406
405
 
407
406
  if (props.onSelectedChanged) {
408
- props.onSelectedChanged.call(
409
- this,
410
- idx,
411
- this,
412
- active,
413
- lastIdx,
414
- );
407
+ props.onSelectedChanged.call(this, idx, this, active, lastIdx);
415
408
  }
416
409
 
417
410
  if (noChange) return;
@@ -540,7 +533,6 @@ function createVirtual<T>(
540
533
 
541
534
  return (
542
535
  <view
543
- transition={/* @once */ {}}
544
536
  transitionLeft={isRow ? defaultTransitionBack : undefined}
545
537
  transitionRight={isRow ? defaultTransitionForward : undefined}
546
538
  transitionUp={!isRow ? defaultTransitionUp : undefined}
@@ -148,7 +148,7 @@ export const Announcer: Announcer = {
148
148
  lang: 'en-US',
149
149
  aria: false,
150
150
  cancel: function () {
151
- currentlySpeaking && currentlySpeaking.cancel();
151
+ currentlySpeaking?.cancel();
152
152
  },
153
153
  clearPrevFocus: function (depth = 0) {
154
154
  prevFocusPath = prevFocusPath.slice(0, depth);
@@ -178,8 +178,9 @@ export const Announcer: Announcer = {
178
178
  },
179
179
  refresh: function (depth = 0) {
180
180
  Announcer.clearPrevFocus(depth);
181
- Announcer.onFocusChange &&
181
+ if (Announcer.onFocusChange) {
182
182
  Announcer.onFocusChange(untrack(() => focusPath()));
183
+ }
183
184
  },
184
185
  setupTimers: function ({
185
186
  focusDebounce = 400,
@@ -154,7 +154,7 @@ function speak(
154
154
  resolve();
155
155
  };
156
156
  utterance.onerror = (e) => {
157
- reject(e);
157
+ reject(new Error(`Speech synthesis error: ${e.error}`));
158
158
  };
159
159
  utterances.push(utterance);
160
160
  synth.speak(utterance);
@@ -328,7 +328,7 @@ export default function (
328
328
  lang: string = 'en-US',
329
329
  voice?: string,
330
330
  ) {
331
- currentSeries && currentSeries.cancel();
331
+ currentSeries?.cancel();
332
332
  currentSeries = speakSeries(toSpeak, aria, lang, voice);
333
333
  return currentSeries;
334
334
  }
@@ -28,8 +28,12 @@ const borderComponent = (props: BorderProps) => {
28
28
  el.alpha = 1;
29
29
  }}
30
30
  onDestroy={(el) => {
31
+ const transition = el.transition;
31
32
  return el
32
- .animate({ alpha: 0 }, el.transition as any)
33
+ .animate(
34
+ { alpha: 0 },
35
+ typeof transition === 'object' ? transition : undefined,
36
+ )
33
37
  .start()
34
38
  .waitUntilStopped();
35
39
  }}
@@ -55,8 +59,8 @@ export function borderBox(
55
59
  runWithOwner(owner, () => {
56
60
  const props = accessor();
57
61
  border = borderComponent(
58
- props === true || props === undefined ? ({} as NodeProps) : props,
59
- ) as any as ElementNode;
62
+ props === true || props === undefined ? {} : props,
63
+ ) as unknown as ElementNode;
60
64
  insertNode(el, border);
61
65
  border.render();
62
66
  });
@@ -1,5 +1,5 @@
1
- import * as s from 'solid-js'
2
- import * as lng from '@solidtv/solid'
1
+ import * as s from 'solid-js';
2
+ import * as lng from '@solidtv/solid';
3
3
 
4
4
  interface Destroyable {
5
5
  (props: lng.NodeProps): s.JSX.Element;
@@ -7,21 +7,27 @@ interface Destroyable {
7
7
  }
8
8
 
9
9
  export function createTag(children: s.JSX.Element): Destroyable {
10
- const [texture, setTexture] = s.createSignal<lng.Texture | null | undefined>(null);
11
- const Tag = <view
12
- x={lng.rootNode.w - 1}
13
- y={lng.rootNode.h - 1}
14
- display='flex'
15
- onLayout={(n) => {
16
- if (n.preFlexwidth && n.width !== n.preFlexwidth) {
17
- n.rtt = true;
18
- setTimeout(() => setTexture(n.texture), 1);
19
- }
20
- }}
21
- parent={lng.rootNode} children={children}
22
- textureOptions={{
23
- preventCleanup: true
24
- }} /> as any as lng.ElementNode
10
+ const [texture, setTexture] = s.createSignal<lng.Texture | null | undefined>(
11
+ null,
12
+ );
13
+ const Tag = (
14
+ <view
15
+ x={lng.rootNode.w - 1}
16
+ y={lng.rootNode.h - 1}
17
+ display="flex"
18
+ onLayout={(n) => {
19
+ if (n.preFlexwidth && n.width !== n.preFlexwidth) {
20
+ n.rtt = true;
21
+ setTimeout(() => setTexture(n.texture), 1);
22
+ }
23
+ }}
24
+ parent={lng.rootNode}
25
+ children={children}
26
+ textureOptions={{
27
+ preventCleanup: true,
28
+ }}
29
+ />
30
+ ) as unknown as lng.ElementNode;
25
31
  Tag.render(false);
26
32
 
27
33
  const TagComponent = (props: lng.NodeProps) => {
@@ -1,5 +1,14 @@
1
1
  import { rootNode, type ElementNode, insert } from '@solidtv/solid';
2
- import { createEffect, createMemo, createRoot, createSignal, getOwner, JSX, onCleanup, runWithOwner } from 'solid-js';
2
+ import {
3
+ createEffect,
4
+ createMemo,
5
+ createRoot,
6
+ createSignal,
7
+ getOwner,
8
+ JSX,
9
+ onCleanup,
10
+ runWithOwner,
11
+ } from 'solid-js';
3
12
 
4
13
  export function Portal(props: { mount?: string; children: JSX.Element }) {
5
14
  let content: undefined | (() => JSX.Element);
@@ -11,15 +20,16 @@ export function Portal(props: { mount?: string; children: JSX.Element }) {
11
20
  return rootNode.searchChildrenById(mount) || rootNode;
12
21
  }
13
22
 
14
- createEffect(
15
- () => {
16
- const [clean, setClean] = createSignal(false);
17
- const cleanup = () => setClean(true);
18
- content || (content = runWithOwner(owner, () => createMemo(() => props.children)));
19
- createRoot(dispose => insert(mount(), () => (!clean() ? content!() : dispose()), null));
20
- onCleanup(cleanup);
21
- }
22
- );
23
+ createEffect(() => {
24
+ const [clean, setClean] = createSignal(false);
25
+ const cleanup = () => setClean(true);
26
+ content =
27
+ content || runWithOwner(owner, () => createMemo(() => props.children));
28
+ createRoot((dispose) =>
29
+ insert(mount(), () => (!clean() ? content!() : dispose()), null),
30
+ );
31
+ onCleanup(cleanup);
32
+ });
23
33
 
24
34
  return null;
25
35
  }
@@ -23,22 +23,42 @@ export function chainFunctions<T extends AnyFunction>(
23
23
  export function chainFunctions(
24
24
  ...fns: (AnyFunction | undefined | null | false)[]
25
25
  ): AnyFunction | undefined {
26
- const onlyFunctions = fns.filter((func) => typeof func === 'function');
27
- if (onlyFunctions.length === 0) {
28
- return undefined;
26
+ // Inline filter to avoid the intermediate array allocation when most
27
+ // callers pass 2 args and one or both happen to be falsy.
28
+ let first: AnyFunction | undefined;
29
+ let onlyFunctions: AnyFunction[] | undefined;
30
+ for (let i = 0; i < fns.length; i++) {
31
+ const fn = fns[i];
32
+ if (typeof fn !== 'function') continue;
33
+ if (first === undefined) {
34
+ first = fn;
35
+ } else {
36
+ if (onlyFunctions === undefined) onlyFunctions = [first];
37
+ onlyFunctions.push(fn);
38
+ }
29
39
  }
30
40
 
31
- if (onlyFunctions.length === 1) {
32
- return onlyFunctions[0];
41
+ if (first === undefined) return undefined;
42
+ if (onlyFunctions === undefined) return first;
43
+
44
+ // Fast path: exactly two functions — the common case for ref/handler
45
+ // forwarding (props.onX + local onX). Avoids the loop.
46
+ if (onlyFunctions.length === 2) {
47
+ const a = onlyFunctions[0]!;
48
+ const b = onlyFunctions[1]!;
49
+ return function (this: unknown, ...innerArgs) {
50
+ const result = a.apply(this, innerArgs);
51
+ if (result === true) return result;
52
+ return b.apply(this, innerArgs);
53
+ };
33
54
  }
34
55
 
35
- return function (...innerArgs) {
56
+ const chained = onlyFunctions;
57
+ return function (this: unknown, ...innerArgs) {
36
58
  let result;
37
- for (const func of onlyFunctions) {
38
- result = func.apply(this, innerArgs);
39
- if (result === true) {
40
- return result;
41
- }
59
+ for (let i = 0; i < chained.length; i++) {
60
+ result = chained[i]!.apply(this, innerArgs);
61
+ if (result === true) return result;
42
62
  }
43
63
  return result;
44
64
  };