solid-js 1.2.5 → 1.3.0-beta.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.
package/web/dist/web.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createMemo, createRoot, createRenderEffect, sharedConfig, createSignal, onCleanup, splitProps, untrack } from 'solid-js';
1
+ import { createMemo, createRoot, createRenderEffect, sharedConfig, enableHydration, createSignal, onCleanup, splitProps, untrack } from 'solid-js';
2
2
  export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, 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"];
@@ -95,7 +95,7 @@ function render(code, element, init) {
95
95
  let disposer;
96
96
  createRoot(dispose => {
97
97
  disposer = dispose;
98
- insert(element, code(), element.firstChild ? null : undefined, init);
98
+ element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init);
99
99
  });
100
100
  return () => {
101
101
  disposer();
@@ -214,28 +214,21 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
214
214
  prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
215
215
  }
216
216
  }
217
- function hydrate(code, element) {
218
- sharedConfig.resources = globalThis._$HYDRATION.resources;
219
- sharedConfig.completed = globalThis._$HYDRATION.completed;
220
- sharedConfig.events = globalThis._$HYDRATION.events;
217
+ function hydrate$1(code, element, options = {}) {
218
+ sharedConfig.completed = globalThis._$HY.completed;
219
+ sharedConfig.events = globalThis._$HY.events;
220
+ sharedConfig.load = globalThis._$HY.load;
221
+ sharedConfig.gather = root => gatherHydratable(element, root);
222
+ sharedConfig.registry = new Map();
221
223
  sharedConfig.context = {
222
- id: "",
223
- count: 0,
224
- loadResource: globalThis._$HYDRATION.loadResource
224
+ id: options.renderId || "",
225
+ count: 0
225
226
  };
226
- sharedConfig.registry = new Map();
227
- gatherHydratable(element);
227
+ gatherHydratable(element, options.renderId);
228
228
  const dispose = render(code, element, [...element.childNodes]);
229
229
  sharedConfig.context = null;
230
230
  return dispose;
231
231
  }
232
- function gatherHydratable(element) {
233
- const templates = element.querySelectorAll(`*[data-hk]`);
234
- for (let i = 0; i < templates.length; i++) {
235
- const node = templates[i];
236
- sharedConfig.registry.set(node.getAttribute("data-hk"), node);
237
- }
238
- }
239
232
  function getNextElement(template) {
240
233
  let node, key;
241
234
  if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -329,7 +322,7 @@ function eventHandler(e) {
329
322
  Object.defineProperty(e, "currentTarget", {
330
323
  configurable: true,
331
324
  get() {
332
- return node;
325
+ return node || document;
333
326
  }
334
327
  });
335
328
  while (node !== null) {
@@ -384,7 +377,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
384
377
  createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
385
378
  return () => current;
386
379
  }
387
- if (sharedConfig.context && current && current.length) return current;
380
+ if (sharedConfig.context && current && current.length) {
381
+ for (let i = 0; i < array.length; i++) {
382
+ if (array[i].parentNode) return current = array;
383
+ }
384
+ return current;
385
+ }
388
386
  if (array.length === 0) {
389
387
  current = cleanChildren(parent, current, marker);
390
388
  if (multi) return current;
@@ -401,6 +399,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
401
399
  }
402
400
  current = array;
403
401
  } else if (value instanceof Node) {
402
+ if (sharedConfig.context) return current = value.parentNode ? value : current;
404
403
  if (Array.isArray(current)) {
405
404
  if (multi) return current = cleanChildren(parent, current, marker, value);
406
405
  cleanChildren(parent, current, null, value);
@@ -452,6 +451,14 @@ function cleanChildren(parent, current, marker, replacement) {
452
451
  } else parent.insertBefore(node, marker);
453
452
  return [node];
454
453
  }
454
+ function gatherHydratable(element, root) {
455
+ const templates = element.querySelectorAll(`*[data-hk]`);
456
+ for (let i = 0; i < templates.length; i++) {
457
+ const node = templates[i];
458
+ const key = node.getAttribute("data-hk");
459
+ if (!root || key.startsWith(root)) sharedConfig.registry.set(key, node);
460
+ }
461
+ }
455
462
  function getHydrationKey() {
456
463
  const hydrate = sharedConfig.context;
457
464
  return `${hydrate.id}${hydrate.count++}`;
@@ -465,8 +472,7 @@ function NoHydration(props) {
465
472
 
466
473
  function renderToString(fn, options) {}
467
474
  function renderToStringAsync(fn, options) {}
468
- function pipeToNodeWritable(fn, writable, options) {}
469
- function pipeToWritable(fn, writable, options) {}
475
+ function renderToStream(fn, options) {}
470
476
  function ssr(template, ...nodes) {}
471
477
  function resolveSSRNode(node) {}
472
478
  function ssrClassList(value) {}
@@ -482,6 +488,10 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
482
488
  function createElement(tagName, isSVG = false) {
483
489
  return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
484
490
  }
491
+ const hydrate = (...args) => {
492
+ enableHydration();
493
+ return hydrate$1(...args);
494
+ };
485
495
  function Portal(props) {
486
496
  const {
487
497
  useShadow
@@ -535,4 +545,4 @@ function Dynamic(props) {
535
545
  });
536
546
  }
537
547
 
538
- export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, gatherHydratable, generateHydrationScript, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, insert, isServer, memo, pipeToNodeWritable, pipeToWritable, render, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
548
+ export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, generateHydrationScript, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, insert, isServer, memo, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
@@ -30,7 +30,12 @@ export function spread<T>(
30
30
  export function assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void;
31
31
  export function setAttribute(node: Element, name: string, value: string): void;
32
32
  export function setAttributeNS(node: Element, namespace: string, name: string, value: string): void;
33
- export function addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void;
33
+ export function addEventListener(
34
+ node: Element,
35
+ name: string,
36
+ handler: () => void,
37
+ delegate: boolean
38
+ ): void;
34
39
  export function classList(
35
40
  node: Element,
36
41
  value: { [k: string]: boolean },
@@ -45,8 +50,11 @@ export function getOwner(): unknown;
45
50
  export function mergeProps(...sources: unknown[]): unknown;
46
51
  export function dynamicProperty(props: unknown, key: string): unknown;
47
52
 
48
- export function hydrate(fn: () => JSX.Element, node: MountableElement): () => void;
49
- export function gatherHydratable(node: Element): void;
53
+ export function hydrate(
54
+ fn: () => JSX.Element,
55
+ node: MountableElement,
56
+ options: { renderId?: string }
57
+ ): () => void;
50
58
  export function getHydrationKey(): string;
51
59
  export function getNextElement(template?: HTMLTemplateElement): Element;
52
60
  export function getNextMatch(start: Node, elementName: string): Element;
@@ -1,3 +1,3 @@
1
- import { createRoot, createRenderEffect, createComponent, getOwner, sharedConfig, awaitSuspense } from "../..";
1
+ import { createRoot, createRenderEffect, createComponent, getOwner, sharedConfig } from "../..";
2
2
  declare function memo<T>(fn: () => T, equals: boolean): import("../..").Accessor<T>;
3
- export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, memo, sharedConfig, awaitSuspense as asyncWrap };
3
+ export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, memo, sharedConfig };
@@ -1,8 +1,10 @@
1
+ import { hydrate as hydrateCore } from "./client";
1
2
  import { Component, JSX, Accessor } from "../..";
2
3
  export * from "./client";
3
4
  export { For, Show, Suspense, SuspenseList, Switch, Match, Index, ErrorBoundary, mergeProps } from "../..";
4
5
  export * from "./server-mock";
5
6
  export declare const isServer = false;
7
+ export declare const hydrate: typeof hydrateCore;
6
8
  /**
7
9
  * renders components somewhere else in the DOM
8
10
  *
@@ -1,31 +1,23 @@
1
- export declare type PipeToWritableResults = {
2
- startWriting: () => void;
3
- write: (v: string) => void;
4
- abort: () => void;
5
- };
6
1
  export declare function renderToString<T>(fn: () => T, options?: {
7
- eventNames?: string[];
8
2
  nonce?: string;
3
+ renderId?: string;
9
4
  }): string;
10
5
  export declare function renderToStringAsync<T>(fn: () => T, options?: {
11
- eventNames?: string[];
12
6
  timeoutMs?: number;
13
7
  nonce?: string;
8
+ renderId?: string;
14
9
  }): Promise<string>;
15
- export declare function pipeToNodeWritable<T>(fn: () => T, writable: {
16
- write: (v: string) => void;
17
- }, options?: {
18
- eventNames?: string[];
10
+ export declare function renderToStream<T>(fn: () => T, options?: {
19
11
  nonce?: string;
20
- onReady?: (r: PipeToWritableResults) => void;
21
- onComplete?: (r: PipeToWritableResults) => void | Promise<void>;
22
- }): void;
23
- export declare function pipeToWritable<T>(fn: () => T, writable: WritableStream, options?: {
24
- eventNames?: string[];
25
- nonce?: string;
26
- onReady?: (r: PipeToWritableResults) => void;
27
- onComplete?: (r: PipeToWritableResults) => void | Promise<void>;
28
- }): void;
12
+ renderId?: string;
13
+ onCompleteShell?: () => void;
14
+ onCompleteAll?: () => void;
15
+ }): {
16
+ pipe: (writable: {
17
+ write: (v: string) => void;
18
+ }) => void;
19
+ pipeTo: (writable: WritableStream) => void;
20
+ };
29
21
  export declare function ssr(template: string[] | string, ...nodes: any[]): {
30
22
  t: string;
31
23
  };
@@ -41,3 +33,24 @@ export declare function ssrBoolean(key: string, value: boolean): string;
41
33
  export declare function ssrHydrationKey(): string;
42
34
  export declare function escape(html: string): string;
43
35
  export declare function generateHydrationScript(): string;
36
+ export declare type LegacyResults = {
37
+ startWriting: () => void;
38
+ };
39
+ /**
40
+ * @deprecated Replaced by renderToStream
41
+ */
42
+ export declare function pipeToWritable<T>(fn: () => T, writable: WritableStream, options?: {
43
+ nonce?: string;
44
+ onReady?: (res: LegacyResults) => void;
45
+ onCompleteAll?: () => void;
46
+ }): void;
47
+ /**
48
+ * @deprecated Replaced by renderToStream
49
+ */
50
+ export declare function pipeToNodeWritable<T>(fn: () => T, writable: {
51
+ write: (v: string) => void;
52
+ }, options?: {
53
+ nonce?: string;
54
+ onReady?: (res: LegacyResults) => void;
55
+ onCompleteAll?: () => void;
56
+ }): void;