solid-js 1.6.12 → 1.6.14

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.
package/dist/server.cjs CHANGED
@@ -6,7 +6,6 @@ const $TRACK = Symbol("solid-track");
6
6
  const $DEVCOMP = Symbol("solid-dev-component");
7
7
  const DEV = {};
8
8
  const ERROR = Symbol("error");
9
- const BRANCH = Symbol("branch");
10
9
  function castError(err) {
11
10
  if (err instanceof Error || typeof err === "string") return err;
12
11
  return new Error("Unknown error");
@@ -19,19 +18,35 @@ function handleError(err) {
19
18
  }
20
19
  const UNOWNED = {
21
20
  context: null,
22
- owner: null
21
+ owner: null,
22
+ owned: null,
23
+ cleanups: null
23
24
  };
24
25
  let Owner = null;
26
+ function createOwner() {
27
+ const o = {
28
+ owner: Owner,
29
+ context: null,
30
+ owned: null,
31
+ cleanups: null
32
+ };
33
+ if (Owner) {
34
+ if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o);
35
+ }
36
+ return o;
37
+ }
25
38
  function createRoot(fn, detachedOwner) {
26
39
  const owner = Owner,
27
40
  root = fn.length === 0 ? UNOWNED : {
28
41
  context: null,
29
- owner: detachedOwner === undefined ? owner : detachedOwner
42
+ owner: detachedOwner === undefined ? owner : detachedOwner,
43
+ owned: null,
44
+ cleanups: null
30
45
  };
31
46
  Owner = root;
32
47
  let result;
33
48
  try {
34
- result = fn(() => {});
49
+ result = fn(fn.length === 0 ? () => {} : () => cleanNode(root));
35
50
  } catch (err) {
36
51
  handleError(err);
37
52
  } finally {
@@ -45,10 +60,7 @@ function createSignal(value, options) {
45
60
  }];
46
61
  }
47
62
  function createComputed(fn, value) {
48
- Owner = {
49
- owner: Owner,
50
- context: null
51
- };
63
+ Owner = createOwner();
52
64
  try {
53
65
  fn(value);
54
66
  } catch (err) {
@@ -65,10 +77,7 @@ function createReaction(fn) {
65
77
  };
66
78
  }
67
79
  function createMemo(fn, value) {
68
- Owner = {
69
- owner: Owner,
70
- context: null
71
- };
80
+ Owner = createOwner();
72
81
  let v;
73
82
  try {
74
83
  v = fn(value);
@@ -104,16 +113,19 @@ function on(deps, fn, options = {}) {
104
113
  }
105
114
  function onMount(fn) {}
106
115
  function onCleanup(fn) {
107
- let node;
108
- if (Owner && (node = lookup(Owner, BRANCH))) {
109
- if (!node.cleanups) node.cleanups = [fn];else node.cleanups.push(fn);
116
+ if (Owner) {
117
+ if (!Owner.cleanups) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
110
118
  }
111
119
  return fn;
112
120
  }
113
121
  function cleanNode(node) {
122
+ if (node.owned) {
123
+ for (let i = 0; i < node.owned.length; i++) cleanNode(node.owned[i]);
124
+ node.owned = null;
125
+ }
114
126
  if (node.cleanups) {
115
127
  for (let i = 0; i < node.cleanups.length; i++) node.cleanups[i]();
116
- node.cleanups = undefined;
128
+ node.cleanups = null;
117
129
  }
118
130
  }
119
131
  function onError(fn) {
@@ -383,11 +395,8 @@ function ErrorBoundary(props) {
383
395
  !sync && ctx.replace("e" + id, displayFallback);
384
396
  sync = true;
385
397
  });
386
- onCleanup(() => cleanNode(clean));
387
398
  createMemo(() => {
388
- Owner.context = {
389
- [BRANCH]: clean = {}
390
- };
399
+ clean = Owner;
391
400
  return res = props.children;
392
401
  });
393
402
  if (error) return displayFallback();
@@ -437,7 +446,7 @@ function createResource(source, fetcher, options = {}) {
437
446
  };
438
447
  read.loading = false;
439
448
  read.error = undefined;
440
- read.state = "initialValue" in options ? "resolved" : "unresolved";
449
+ read.state = "initialValue" in options ? "ready" : "unresolved";
441
450
  Object.defineProperty(read, "latest", {
442
451
  get() {
443
452
  return read();
@@ -470,7 +479,7 @@ function createResource(source, fetcher, options = {}) {
470
479
  if (ctx.writeResource) ctx.writeResource(id, p, undefined, options.deferStream);
471
480
  return p.then(res => {
472
481
  read.loading = false;
473
- read.state = "resolved";
482
+ read.state = "ready";
474
483
  ctx.resources[id].data = res;
475
484
  p = null;
476
485
  notifySuspense(contexts);
@@ -560,15 +569,9 @@ function SuspenseList(props) {
560
569
  }
561
570
  function Suspense(props) {
562
571
  let done;
563
- let clean;
564
572
  const ctx = sharedConfig.context;
565
573
  const id = ctx.id + ctx.count;
566
- const o = Owner;
567
- if (o) {
568
- if (o.context) o.context[BRANCH] = clean = {};else o.context = {
569
- [BRANCH]: clean = {}
570
- };
571
- }
574
+ const o = createOwner();
572
575
  const value = ctx.suspense[id] || (ctx.suspense[id] = {
573
576
  resources: new Map(),
574
577
  completed: () => {
@@ -583,11 +586,11 @@ function Suspense(props) {
583
586
  ...ctx,
584
587
  count: 0
585
588
  });
589
+ o && cleanNode(o);
586
590
  return runWithOwner(o, () => {
587
591
  return createComponent(SuspenseContext.Provider, {
588
592
  value,
589
593
  get children() {
590
- clean && cleanNode(clean);
591
594
  return props.children;
592
595
  }
593
596
  });
package/dist/server.js CHANGED
@@ -4,7 +4,6 @@ const $TRACK = Symbol("solid-track");
4
4
  const $DEVCOMP = Symbol("solid-dev-component");
5
5
  const DEV = {};
6
6
  const ERROR = Symbol("error");
7
- const BRANCH = Symbol("branch");
8
7
  function castError(err) {
9
8
  if (err instanceof Error || typeof err === "string") return err;
10
9
  return new Error("Unknown error");
@@ -17,19 +16,35 @@ function handleError(err) {
17
16
  }
18
17
  const UNOWNED = {
19
18
  context: null,
20
- owner: null
19
+ owner: null,
20
+ owned: null,
21
+ cleanups: null
21
22
  };
22
23
  let Owner = null;
24
+ function createOwner() {
25
+ const o = {
26
+ owner: Owner,
27
+ context: null,
28
+ owned: null,
29
+ cleanups: null
30
+ };
31
+ if (Owner) {
32
+ if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o);
33
+ }
34
+ return o;
35
+ }
23
36
  function createRoot(fn, detachedOwner) {
24
37
  const owner = Owner,
25
38
  root = fn.length === 0 ? UNOWNED : {
26
39
  context: null,
27
- owner: detachedOwner === undefined ? owner : detachedOwner
40
+ owner: detachedOwner === undefined ? owner : detachedOwner,
41
+ owned: null,
42
+ cleanups: null
28
43
  };
29
44
  Owner = root;
30
45
  let result;
31
46
  try {
32
- result = fn(() => {});
47
+ result = fn(fn.length === 0 ? () => {} : () => cleanNode(root));
33
48
  } catch (err) {
34
49
  handleError(err);
35
50
  } finally {
@@ -43,10 +58,7 @@ function createSignal(value, options) {
43
58
  }];
44
59
  }
45
60
  function createComputed(fn, value) {
46
- Owner = {
47
- owner: Owner,
48
- context: null
49
- };
61
+ Owner = createOwner();
50
62
  try {
51
63
  fn(value);
52
64
  } catch (err) {
@@ -63,10 +75,7 @@ function createReaction(fn) {
63
75
  };
64
76
  }
65
77
  function createMemo(fn, value) {
66
- Owner = {
67
- owner: Owner,
68
- context: null
69
- };
78
+ Owner = createOwner();
70
79
  let v;
71
80
  try {
72
81
  v = fn(value);
@@ -102,16 +111,19 @@ function on(deps, fn, options = {}) {
102
111
  }
103
112
  function onMount(fn) {}
104
113
  function onCleanup(fn) {
105
- let node;
106
- if (Owner && (node = lookup(Owner, BRANCH))) {
107
- if (!node.cleanups) node.cleanups = [fn];else node.cleanups.push(fn);
114
+ if (Owner) {
115
+ if (!Owner.cleanups) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
108
116
  }
109
117
  return fn;
110
118
  }
111
119
  function cleanNode(node) {
120
+ if (node.owned) {
121
+ for (let i = 0; i < node.owned.length; i++) cleanNode(node.owned[i]);
122
+ node.owned = null;
123
+ }
112
124
  if (node.cleanups) {
113
125
  for (let i = 0; i < node.cleanups.length; i++) node.cleanups[i]();
114
- node.cleanups = undefined;
126
+ node.cleanups = null;
115
127
  }
116
128
  }
117
129
  function onError(fn) {
@@ -381,11 +393,8 @@ function ErrorBoundary(props) {
381
393
  !sync && ctx.replace("e" + id, displayFallback);
382
394
  sync = true;
383
395
  });
384
- onCleanup(() => cleanNode(clean));
385
396
  createMemo(() => {
386
- Owner.context = {
387
- [BRANCH]: clean = {}
388
- };
397
+ clean = Owner;
389
398
  return res = props.children;
390
399
  });
391
400
  if (error) return displayFallback();
@@ -435,7 +444,7 @@ function createResource(source, fetcher, options = {}) {
435
444
  };
436
445
  read.loading = false;
437
446
  read.error = undefined;
438
- read.state = "initialValue" in options ? "resolved" : "unresolved";
447
+ read.state = "initialValue" in options ? "ready" : "unresolved";
439
448
  Object.defineProperty(read, "latest", {
440
449
  get() {
441
450
  return read();
@@ -468,7 +477,7 @@ function createResource(source, fetcher, options = {}) {
468
477
  if (ctx.writeResource) ctx.writeResource(id, p, undefined, options.deferStream);
469
478
  return p.then(res => {
470
479
  read.loading = false;
471
- read.state = "resolved";
480
+ read.state = "ready";
472
481
  ctx.resources[id].data = res;
473
482
  p = null;
474
483
  notifySuspense(contexts);
@@ -558,15 +567,9 @@ function SuspenseList(props) {
558
567
  }
559
568
  function Suspense(props) {
560
569
  let done;
561
- let clean;
562
570
  const ctx = sharedConfig.context;
563
571
  const id = ctx.id + ctx.count;
564
- const o = Owner;
565
- if (o) {
566
- if (o.context) o.context[BRANCH] = clean = {};else o.context = {
567
- [BRANCH]: clean = {}
568
- };
569
- }
572
+ const o = createOwner();
570
573
  const value = ctx.suspense[id] || (ctx.suspense[id] = {
571
574
  resources: new Map(),
572
575
  completed: () => {
@@ -581,11 +584,11 @@ function Suspense(props) {
581
584
  ...ctx,
582
585
  count: 0
583
586
  });
587
+ o && cleanNode(o);
584
588
  return runWithOwner(o, () => {
585
589
  return createComponent(SuspenseContext.Provider, {
586
590
  value,
587
591
  get children() {
588
- clean && cleanNode(clean);
589
592
  return props.children;
590
593
  }
591
594
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.6.12",
4
+ "version": "1.6.14",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -6,13 +6,15 @@ export declare const DEV: {};
6
6
  export type Accessor<T> = () => T;
7
7
  export type Setter<T> = undefined extends T ? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U;
8
8
  export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
9
- export declare const BRANCH: unique symbol;
10
9
  export declare function castError(err: any): string | Error;
11
10
  export declare let Owner: Owner | null;
12
11
  interface Owner {
13
12
  owner: Owner | null;
14
13
  context: any | null;
14
+ owned: Owner[] | null;
15
+ cleanups: (() => void)[] | null;
15
16
  }
17
+ export declare function createOwner(): Owner;
16
18
  export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: typeof Owner): T;
17
19
  export declare function createSignal<T>(value: T, options?: {
18
20
  equals?: false | ((prev: T, next: T) => boolean);
@@ -32,9 +34,7 @@ export declare function on<T, U>(deps: Array<() => T> | (() => T), fn: (value: A
32
34
  }): (prev?: U) => U | undefined;
33
35
  export declare function onMount(fn: () => void): void;
34
36
  export declare function onCleanup(fn: () => void): () => void;
35
- export declare function cleanNode(node: {
36
- cleanups?: Function[] | null;
37
- }): void;
37
+ export declare function cleanNode(node: Owner): void;
38
38
  export declare function onError(fn: (err: any) => void): void;
39
39
  export declare function getListener(): null;
40
40
  export interface Context<T> {
package/web/dist/dev.cjs CHANGED
@@ -460,7 +460,10 @@ function normalizeIncomingArray(normalized, array, current, unwrap) {
460
460
  }
461
461
  } else {
462
462
  const value = String(item);
463
- if (prev && prev.nodeType === 3 && prev.data === value) {
463
+ if (value === "<!>") {
464
+ if (prev && prev.nodeType === 8) normalized.push(prev);
465
+ } else if (prev && prev.nodeType === 3) {
466
+ prev.data = value;
464
467
  normalized.push(prev);
465
468
  } else normalized.push(document.createTextNode(value));
466
469
  }
package/web/dist/dev.js CHANGED
@@ -459,7 +459,10 @@ function normalizeIncomingArray(normalized, array, current, unwrap) {
459
459
  }
460
460
  } else {
461
461
  const value = String(item);
462
- if (prev && prev.nodeType === 3 && prev.data === value) {
462
+ if (value === "<!>") {
463
+ if (prev && prev.nodeType === 8) normalized.push(prev);
464
+ } else if (prev && prev.nodeType === 3) {
465
+ prev.data = value;
463
466
  normalized.push(prev);
464
467
  } else normalized.push(document.createTextNode(value));
465
468
  }
@@ -278,7 +278,11 @@ function renderToString(code, options = {}) {
278
278
  scripts += `_$HY.set("${id}", ${stringify(p)});`;
279
279
  }
280
280
  };
281
- let html = resolveSSRNode(escape(code()));
281
+ let html = solidJs.createRoot(d => {
282
+ const r = resolveSSRNode(escape(code()));
283
+ d();
284
+ return r;
285
+ });
282
286
  solidJs.sharedConfig.context.noHydrate = true;
283
287
  html = injectAssets(solidJs.sharedConfig.context.assets, html);
284
288
  if (scripts.length) html = injectScripts(html, scripts, options.nonce);
@@ -304,6 +308,7 @@ function renderToStream(code, options = {}) {
304
308
  onCompleteAll,
305
309
  renderId
306
310
  } = options;
311
+ let dispose;
307
312
  const blockingResources = [];
308
313
  const registry = new Map();
309
314
  const dedupe = new WeakMap();
@@ -317,6 +322,7 @@ function renderToStream(code, options = {}) {
317
322
  });
318
323
  writable && writable.end();
319
324
  completed = true;
325
+ dispose();
320
326
  }
321
327
  };
322
328
  const pushTask = task => {
@@ -404,7 +410,10 @@ function renderToStream(code, options = {}) {
404
410
  };
405
411
  }
406
412
  };
407
- let html = resolveSSRNode(escape(code()));
413
+ let html = solidJs.createRoot(d => {
414
+ dispose = d;
415
+ return resolveSSRNode(escape(code()));
416
+ });
408
417
  function doShell() {
409
418
  solidJs.sharedConfig.context = context;
410
419
  context.noHydrate = true;
@@ -1,4 +1,4 @@
1
- import { sharedConfig, splitProps } from 'solid-js';
1
+ import { sharedConfig, createRoot, splitProps } from 'solid-js';
2
2
  export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js';
3
3
 
4
4
  const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"];
@@ -277,7 +277,11 @@ function renderToString(code, options = {}) {
277
277
  scripts += `_$HY.set("${id}", ${stringify(p)});`;
278
278
  }
279
279
  };
280
- let html = resolveSSRNode(escape(code()));
280
+ let html = createRoot(d => {
281
+ const r = resolveSSRNode(escape(code()));
282
+ d();
283
+ return r;
284
+ });
281
285
  sharedConfig.context.noHydrate = true;
282
286
  html = injectAssets(sharedConfig.context.assets, html);
283
287
  if (scripts.length) html = injectScripts(html, scripts, options.nonce);
@@ -303,6 +307,7 @@ function renderToStream(code, options = {}) {
303
307
  onCompleteAll,
304
308
  renderId
305
309
  } = options;
310
+ let dispose;
306
311
  const blockingResources = [];
307
312
  const registry = new Map();
308
313
  const dedupe = new WeakMap();
@@ -316,6 +321,7 @@ function renderToStream(code, options = {}) {
316
321
  });
317
322
  writable && writable.end();
318
323
  completed = true;
324
+ dispose();
319
325
  }
320
326
  };
321
327
  const pushTask = task => {
@@ -403,7 +409,10 @@ function renderToStream(code, options = {}) {
403
409
  };
404
410
  }
405
411
  };
406
- let html = resolveSSRNode(escape(code()));
412
+ let html = createRoot(d => {
413
+ dispose = d;
414
+ return resolveSSRNode(escape(code()));
415
+ });
407
416
  function doShell() {
408
417
  sharedConfig.context = context;
409
418
  context.noHydrate = true;
package/web/dist/web.cjs CHANGED
@@ -460,7 +460,10 @@ function normalizeIncomingArray(normalized, array, current, unwrap) {
460
460
  }
461
461
  } else {
462
462
  const value = String(item);
463
- if (prev && prev.nodeType === 3 && prev.data === value) {
463
+ if (value === "<!>") {
464
+ if (prev && prev.nodeType === 8) normalized.push(prev);
465
+ } else if (prev && prev.nodeType === 3) {
466
+ prev.data = value;
464
467
  normalized.push(prev);
465
468
  } else normalized.push(document.createTextNode(value));
466
469
  }
package/web/dist/web.js CHANGED
@@ -459,7 +459,10 @@ function normalizeIncomingArray(normalized, array, current, unwrap) {
459
459
  }
460
460
  } else {
461
461
  const value = String(item);
462
- if (prev && prev.nodeType === 3 && prev.data === value) {
462
+ if (value === "<!>") {
463
+ if (prev && prev.nodeType === 8) normalized.push(prev);
464
+ } else if (prev && prev.nodeType === 3) {
465
+ prev.data = value;
463
466
  normalized.push(prev);
464
467
  } else normalized.push(document.createTextNode(value));
465
468
  }