solid-js 1.2.4 → 1.3.0-beta.2

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.
@@ -1,16 +1,14 @@
1
1
  import { requestCallback } from "./scheduler";
2
2
  import type { JSX } from "../jsx";
3
- export declare type Accessor<T> = () => T;
4
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: T) => U)) => U;
5
3
  export declare const equalFn: <T>(a: T, b: T) => boolean;
6
4
  export declare const $PROXY: unique symbol;
7
5
  export declare const NOTPENDING: {};
8
6
  export declare var Owner: Owner | null;
9
- export declare let Transition: Transition | null;
7
+ export declare let Transition: TransitionState | null;
10
8
  declare global {
11
9
  var _$afterUpdate: () => void;
12
10
  }
13
- interface Signal<T> {
11
+ export interface SignalState<T> {
14
12
  value?: T;
15
13
  observers: Computation<any>[] | null;
16
14
  observerSlots: number[] | null;
@@ -19,7 +17,7 @@ interface Signal<T> {
19
17
  comparator?: (prev: T, next: T) => boolean;
20
18
  name?: string;
21
19
  }
22
- interface Owner {
20
+ export interface Owner {
23
21
  owned: Computation<any>[] | null;
24
22
  cleanups: (() => void)[] | null;
25
23
  owner: Owner | null;
@@ -30,23 +28,20 @@ interface Owner {
30
28
  name?: string;
31
29
  componentName?: string;
32
30
  }
33
- interface Computation<T> extends Owner {
34
- fn: (v?: T) => T;
31
+ export interface Computation<Init, Next extends Init = Init> extends Owner {
32
+ fn: EffectFunction<Init, Next>;
35
33
  state: number;
36
34
  tState?: number;
37
- sources: Signal<T>[] | null;
35
+ sources: SignalState<Next>[] | null;
38
36
  sourceSlots: number[] | null;
39
- value?: T;
37
+ value?: Init;
40
38
  updatedAt: number | null;
41
39
  pure: boolean;
42
40
  user?: boolean;
43
41
  suspense?: SuspenseContextType;
44
42
  }
45
- interface Memo<T> extends Signal<T>, Computation<T> {
46
- tOwned?: Computation<any>[];
47
- }
48
- interface Transition {
49
- sources: Set<Signal<any>>;
43
+ export interface TransitionState {
44
+ sources: Set<SignalState<any>>;
50
45
  effects: Computation<any>[];
51
46
  promises: Set<Promise<any>>;
52
47
  disposed: Set<Computation<any>>;
@@ -55,6 +50,7 @@ interface Transition {
55
50
  running: boolean;
56
51
  cb: (() => void)[];
57
52
  }
53
+ export declare type RootFunction<T> = (dispose: () => void) => T;
58
54
  /**
59
55
  * Creates a new non-tracked reactive context that doesn't auto-dispose
60
56
  *
@@ -64,11 +60,13 @@ interface Transition {
64
60
  *
65
61
  * @description https://www.solidjs.com/docs/latest/api#createroot
66
62
  */
67
- export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Owner): T;
68
- export declare type SignalOptions<T> = {
69
- name?: string;
70
- equals?: false | ((prev: T, next: T) => boolean);
71
- };
63
+ export declare function createRoot<T>(fn: RootFunction<T>, detachedOwner?: Owner): T;
64
+ export declare type Accessor<T> = () => T;
65
+ export declare 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;
66
+ export declare type Signal<T> = [get: Accessor<T>, set: Setter<T>];
67
+ export interface SignalOptions<T> extends MemoOptions<T> {
68
+ internal?: boolean;
69
+ }
72
70
  /**
73
71
  * Creates a simple reactive state with a getter and setter
74
72
  * ```typescript
@@ -92,18 +90,21 @@ export declare type SignalOptions<T> = {
92
90
  *
93
91
  * @description https://www.solidjs.com/docs/latest/api#createsignal
94
92
  */
95
- export declare function createSignal<T>(): [get: Accessor<T | undefined>, set: Setter<T | undefined>];
96
- export declare function createSignal<T>(value: T, options?: {
97
- equals?: false | ((prev: T, next: T) => boolean);
93
+ export declare function createSignal<T>(): Signal<T | undefined>;
94
+ export declare function createSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
95
+ export interface BaseOptions {
98
96
  name?: string;
99
- internal?: boolean;
100
- }): [get: Accessor<T>, set: Setter<T>];
97
+ }
98
+ export declare type NoInfer<T extends any> = [T][T extends any ? 0 : never];
99
+ export interface EffectOptions extends BaseOptions {
100
+ }
101
+ export declare type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
101
102
  /**
102
103
  * Creates a reactive computation that runs immediately before render, mainly used to write to other reactive primitives
103
104
  * ```typescript
104
- * export function createComputed<T>(
105
- * fn: (v: T) => T,
106
- * value?: T,
105
+ * export function createComputed<Next, Init = Next>(
106
+ * fn: (v: Init | Next) => Next,
107
+ * value?: Init,
107
108
  * options?: { name?: string }
108
109
  * ): void;
109
110
  * ```
@@ -113,10 +114,8 @@ export declare function createSignal<T>(value: T, options?: {
113
114
  *
114
115
  * @description https://www.solidjs.com/docs/latest/api#createcomputed
115
116
  */
116
- export declare function createComputed<T>(fn: (v?: T) => T | undefined): void;
117
- export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
118
- name?: string;
119
- }): void;
117
+ export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
118
+ export declare function createComputed<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
120
119
  /**
121
120
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
122
121
  * ```typescript
@@ -132,10 +131,8 @@ export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
132
131
  *
133
132
  * @description https://www.solidjs.com/docs/latest/api#createrendereffect
134
133
  */
135
- export declare function createRenderEffect<T>(fn: (v?: T) => T | undefined): void;
136
- export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options?: {
137
- name?: string;
138
- }): void;
134
+ export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
135
+ export declare function createRenderEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
139
136
  /**
140
137
  * Creates a reactive computation that runs after the render phase
141
138
  * ```typescript
@@ -151,10 +148,14 @@ export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options
151
148
  *
152
149
  * @description https://www.solidjs.com/docs/latest/api#createeffect
153
150
  */
154
- export declare function createEffect<T>(fn: (v?: T) => T | undefined): void;
155
- export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
156
- name?: string;
157
- }): void;
151
+ export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
152
+ export declare function createEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
153
+ interface Memo<Prev, Next = Prev> extends SignalState<Next>, Computation<Next> {
154
+ tOwned?: Computation<Prev | Next, Next>[];
155
+ }
156
+ export interface MemoOptions<T> extends EffectOptions {
157
+ equals?: false | ((prev: T, next: T) => boolean);
158
+ }
158
159
  /**
159
160
  * Creates a readonly derived reactive memoized signal
160
161
  * ```typescript
@@ -170,14 +171,8 @@ export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
170
171
  *
171
172
  * @description https://www.solidjs.com/docs/latest/api#creatememo
172
173
  */
173
- export declare function createMemo<T>(fn: (v?: T) => T, value?: undefined, options?: {
174
- equals?: false | ((prev: T, next: T) => boolean);
175
- name?: string;
176
- }): Accessor<T>;
177
- export declare function createMemo<T>(fn: (v: T) => T, value: T, options?: {
178
- equals?: false | ((prev: T, next: T) => boolean);
179
- name?: string;
180
- }): Accessor<T>;
174
+ export declare function createMemo<Next extends _Next, Init = Next, _Next = Next>(fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
175
+ export declare function createMemo<Next extends _Next, Init = undefined, _Next = Next>(..._: undefined extends Init ? [fn: EffectFunction<Init | _Next, Next>, value?: Init, options?: MemoOptions<Next>] : [fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>]): Accessor<Next>;
181
176
  export interface Resource<T> extends Accessor<T> {
182
177
  loading: boolean;
183
178
  error: any;
@@ -221,30 +216,30 @@ export declare type ResourceOptions<T> = T extends undefined ? {
221
216
  *
222
217
  * @description https://www.solidjs.com/docs/latest/api#createresource
223
218
  */
224
- export declare function createResource<T extends any, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
225
- export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
226
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
227
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
219
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
220
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
221
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
222
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
223
+ export interface DeferredOptions<T> {
224
+ equals?: false | ((prev: T, next: T) => boolean);
225
+ name?: string;
226
+ timeoutMs?: number;
227
+ }
228
228
  /**
229
229
  * Creates a reactive computation that only runs and notifies the reactive context when the browser is idle
230
230
  * ```typescript
231
231
  * export function createDeferred<T>(
232
232
  * fn: (v: T) => T,
233
- * value?: T,
234
233
  * options?: { timeoutMs?: number, name?: string, equals?: false | ((prev: T, next: T) => boolean) }
235
234
  * ): () => T);
236
235
  * ```
237
236
  * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
238
- * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
239
237
  * @param options allows to set the timeout in milliseconds, use a custom comparison function and set a name in dev mode for debugging purposes
240
238
  *
241
239
  * @description https://www.solidjs.com/docs/latest/api#createdeferred
242
240
  */
243
- export declare function createDeferred<T>(source: Accessor<T>, options?: {
244
- equals?: false | ((prev: T, next: T) => boolean);
245
- name?: string;
246
- timeoutMs?: number;
247
- }): Accessor<T>;
241
+ export declare function createDeferred<T>(source: Accessor<T>, options?: DeferredOptions<T>): Accessor<T>;
242
+ export declare type EqualityCheckerFunction<T, U> = (a: U, b: T) => boolean;
248
243
  /**
249
244
  * Creates a conditional signal that only notifies subscribers when entering or exiting their key matching the value
250
245
  * ```typescript
@@ -269,9 +264,7 @@ export declare function createDeferred<T>(source: Accessor<T>, options?: {
269
264
  *
270
265
  * @description https://www.solidjs.com/docs/latest/api#createselector
271
266
  */
272
- export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b: T) => boolean, options?: {
273
- name?: string;
274
- }): (key: U) => boolean;
267
+ export declare function createSelector<T, U>(source: Accessor<T>, fn?: EqualityCheckerFunction<T, U>, options?: BaseOptions): (key: U) => boolean;
275
268
  /**
276
269
  * Holds changes inside the block before the reactive context is updated
277
270
  * @param fn wraps the reactive updates that should be batched
@@ -279,7 +272,7 @@ export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b:
279
272
  *
280
273
  * @description https://www.solidjs.com/docs/latest/api#batch
281
274
  */
282
- export declare function batch<T>(fn: () => T): T;
275
+ export declare function batch<T>(fn: Accessor<T>): T;
283
276
  /**
284
277
  * Ignores tracking context inside its scope
285
278
  * @param fn the scope that is out of the tracking context
@@ -291,6 +284,10 @@ export declare function untrack<T>(fn: Accessor<T>): T;
291
284
  export declare type ReturnTypes<T> = T extends (() => any)[] ? {
292
285
  [I in keyof T]: ReturnTypes<T[I]>;
293
286
  } : T extends () => any ? ReturnType<T> : never;
287
+ export declare type OnEffectFunction<S, Prev, Next extends Prev = Prev> = (input: ReturnTypes<S>, prevInput: ReturnTypes<S>, v: Prev) => Next;
288
+ export interface OnOptions {
289
+ defer?: boolean;
290
+ }
294
291
  /**
295
292
  * on - make dependencies of a computation explicit
296
293
  * ```typescript
@@ -303,6 +300,8 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
303
300
  * @param deps list of reactive dependencies or a single reactive dependency
304
301
  * @param fn computation on input; the current previous content(s) of input and the previous value are given as arguments and it returns a new value
305
302
  * @param options optional, allows deferred computation until at the end of the next change
303
+ * @returns an effect function that is passed into createEffect. For example:
304
+ *
306
305
  * ```typescript
307
306
  * createEffect(on(a, (v) => console.log(v, b())));
308
307
  *
@@ -315,12 +314,7 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
315
314
  *
316
315
  * @description https://www.solidjs.com/docs/latest/api#on
317
316
  */
318
- export declare function on<T extends (() => any)[], U>(deps: [...T], fn: (input: ReturnTypes<T>, prevInput: ReturnTypes<T>, prevValue?: U) => U, options?: {
319
- defer?: boolean;
320
- }): (prevValue?: U) => U;
321
- export declare function on<T extends () => any, U>(deps: T, fn: (input: ReturnType<T>, prevInput: ReturnType<T>, prevValue?: U) => U, options?: {
322
- defer?: boolean;
323
- }): (prevValue?: U) => U;
317
+ export declare function on<S extends Accessor<unknown> | Accessor<unknown>[] | [], Next, Init = unknown>(deps: S, fn: OnEffectFunction<S, Init | Next, Next>, options?: OnOptions): EffectFunction<NoInfer<Init> | NoInfer<Next>, NoInfer<Next>>;
324
318
  /**
325
319
  * onMount - run an effect only after initial render on mount
326
320
  * @param fn an effect that should run only once on mount
@@ -344,11 +338,12 @@ export declare function onCleanup(fn: () => void): () => void;
344
338
  * @description https://www.solidjs.com/docs/latest/api#onerror
345
339
  */
346
340
  export declare function onError(fn: (err: any) => void): void;
347
- export declare function getListener(): Computation<any> | null;
341
+ export declare function getListener(): Computation<any, any> | null;
348
342
  export declare function getOwner(): Owner | null;
349
343
  export declare function runWithOwner(o: Owner, fn: () => any): any;
350
344
  export declare function enableScheduling(scheduler?: typeof requestCallback): void;
351
345
  export declare function startTransition(fn: () => void, cb?: () => void): void;
346
+ export declare type Transition = [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
352
347
  /**
353
348
  * ```typescript
354
349
  * export function useTransition(): [
@@ -359,7 +354,7 @@ export declare function startTransition(fn: () => void, cb?: () => void): void;
359
354
  *
360
355
  * @description https://www.solidjs.com/docs/latest/api#usetransition
361
356
  */
362
- export declare function useTransition(): [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
357
+ export declare function useTransition(): Transition;
363
358
  export declare function resumeEffects(e: Computation<any>[]): void;
364
359
  export declare function devComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
365
360
  export declare function hashValue(v: any): string;
@@ -370,12 +365,13 @@ interface GraphRecord {
370
365
  [k: string]: GraphRecord | unknown;
371
366
  }
372
367
  export declare function serializeGraph(owner?: Owner | null): GraphRecord;
368
+ export declare type ContextProviderComponent<T> = (props: {
369
+ value: T;
370
+ children: any;
371
+ }) => any;
373
372
  export interface Context<T> {
374
373
  id: symbol;
375
- Provider: (props: {
376
- value: T;
377
- children: any;
378
- }) => any;
374
+ Provider: ContextProviderComponent<T>;
379
375
  defaultValue: T;
380
376
  }
381
377
  /**
@@ -413,18 +409,20 @@ export declare function useContext<T>(context: Context<T>): T;
413
409
  * @description https://www.solidjs.com/docs/latest/api#children
414
410
  */
415
411
  export declare function children(fn: Accessor<JSX.Element>): Accessor<JSX.Element>;
416
- declare type SuspenseContextType = {
412
+ export declare type SuspenseContextType = {
417
413
  increment?: () => void;
418
414
  decrement?: () => void;
419
415
  inFallback?: () => boolean;
420
416
  effects?: Computation<any>[];
421
417
  resolved?: boolean;
422
418
  };
423
- export declare function getSuspenseContext(): Context<SuspenseContextType> & {
419
+ declare type SuspenseContext = Context<SuspenseContextType> & {
424
420
  active?(): boolean;
425
421
  increment?(): void;
426
422
  decrement?(): void;
427
423
  };
428
- export declare function readSignal(this: Signal<any> | Memo<any>): any;
429
- export declare function writeSignal(node: Signal<any> | Memo<any>, value: any, isComp?: boolean): any;
424
+ declare let SuspenseContext: SuspenseContext;
425
+ export declare function getSuspenseContext(): SuspenseContext;
426
+ export declare function readSignal(this: SignalState<any> | Memo<any>): any;
427
+ export declare function writeSignal(node: SignalState<any> | Memo<any>, value: any, isComp?: boolean): any;
430
428
  export {};
@@ -1,13 +1,14 @@
1
- declare type HydrationContext = {
1
+ export declare type HydrationContext = {
2
2
  id: string;
3
3
  count: number;
4
- loadResource?: (id: string) => Promise<any>;
5
4
  };
6
5
  declare type SharedConfig = {
7
6
  context?: HydrationContext;
8
7
  resources?: {
9
8
  [key: string]: any;
10
9
  };
10
+ load?: (id: string) => Promise<any> | undefined;
11
+ gather?: (key: string) => void;
11
12
  registry?: Map<string, Element>;
12
13
  };
13
14
  export declare const sharedConfig: SharedConfig;
@@ -1,3 +1,3 @@
1
1
  export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV } from "./reactive";
2
- export { awaitSuspense, mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
2
+ export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
3
3
  export type { Component, Resource } from "./rendering";
@@ -1,9 +1,8 @@
1
+ import type { Accessor, Setter } from "../reactive/signal";
1
2
  export declare const equalFn: <T>(a: T, b: T) => boolean;
2
3
  export declare const $PROXY: unique symbol;
3
4
  export declare const DEV: {};
4
5
  export declare let Owner: Owner | null;
5
- export declare type Accessor<T> = () => T;
6
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: U) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: U) => U)) => U;
7
6
  interface Owner {
8
7
  owner: Owner | null;
9
8
  context: any | null;
@@ -94,8 +94,10 @@ declare type HydrationContext = {
94
94
  writeResource?: (id: string, v: Promise<any>) => void;
95
95
  resources: Record<string, any>;
96
96
  suspense: Record<string, SuspenseContextType>;
97
+ registerFragment: (v: string) => (v?: string) => void;
97
98
  async?: boolean;
98
99
  streaming?: boolean;
100
+ noHydrate: boolean;
99
101
  };
100
102
  export declare function SuspenseList(props: {
101
103
  children: string;
@@ -106,5 +108,4 @@ export declare function Suspense(props: {
106
108
  fallback: string;
107
109
  children: string;
108
110
  }): any;
109
- export declare function awaitSuspense(fn: () => any): Promise<unknown>;
110
111
  export {};
package/web/dist/dev.cjs CHANGED
@@ -215,32 +215,24 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
215
215
  continue;
216
216
  }
217
217
  const value = props[prop];
218
- assignProp(node, prop, value, prevProps[prop], isSVG);
219
- prevProps[prop] = value;
218
+ prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
220
219
  }
221
220
  }
222
221
  function hydrate(code, element) {
223
- solidJs.sharedConfig.resources = globalThis._$HYDRATION.resources;
224
- solidJs.sharedConfig.completed = globalThis._$HYDRATION.completed;
225
- solidJs.sharedConfig.events = globalThis._$HYDRATION.events;
222
+ solidJs.sharedConfig.completed = globalThis._$HY.completed;
223
+ solidJs.sharedConfig.events = globalThis._$HY.events;
224
+ solidJs.sharedConfig.load = globalThis._$HY.load;
225
+ solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
226
+ solidJs.sharedConfig.registry = new Map();
226
227
  solidJs.sharedConfig.context = {
227
228
  id: "",
228
- count: 0,
229
- loadResource: globalThis._$HYDRATION.loadResource
229
+ count: 0
230
230
  };
231
- solidJs.sharedConfig.registry = new Map();
232
231
  gatherHydratable(element);
233
232
  const dispose = render(code, element, [...element.childNodes]);
234
233
  solidJs.sharedConfig.context = null;
235
234
  return dispose;
236
235
  }
237
- function gatherHydratable(element) {
238
- const templates = element.querySelectorAll(`*[data-hk]`);
239
- for (let i = 0; i < templates.length; i++) {
240
- const node = templates[i];
241
- solidJs.sharedConfig.registry.set(node.getAttribute("data-hk"), node);
242
- }
243
- }
244
236
  function getNextElement(template) {
245
237
  let node, key;
246
238
  if (!solidJs.sharedConfig.context || !(node = solidJs.sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -302,7 +294,7 @@ function assignProp(node, prop, value, prev, isSVG) {
302
294
  let isCE, isProp, isChildProp;
303
295
  if (prop === "style") return style(node, value, prev);
304
296
  if (prop === "classList") return classList(node, value, prev);
305
- if (value === prev) return;
297
+ if (value === prev) return prev;
306
298
  if (prop === "ref") {
307
299
  value(node);
308
300
  } else if (prop.slice(0, 3) === "on:") {
@@ -320,6 +312,7 @@ function assignProp(node, prop, value, prev, isSVG) {
320
312
  const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
321
313
  if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
322
314
  }
315
+ return value;
323
316
  }
324
317
  function eventHandler(e) {
325
318
  const key = `$$${e.type}`;
@@ -333,7 +326,7 @@ function eventHandler(e) {
333
326
  Object.defineProperty(e, "currentTarget", {
334
327
  configurable: true,
335
328
  get() {
336
- return node;
329
+ return node || document;
337
330
  }
338
331
  });
339
332
  while (node !== null) {
@@ -388,7 +381,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
388
381
  solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
389
382
  return () => current;
390
383
  }
391
- if (solidJs.sharedConfig.context && current && current.length) return current;
384
+ if (solidJs.sharedConfig.context && current && current.length) {
385
+ for (let i; i < array.length; i++) {
386
+ if (array[i].parentNode) return array;
387
+ }
388
+ return current;
389
+ }
392
390
  if (array.length === 0) {
393
391
  current = cleanChildren(parent, current, marker);
394
392
  if (multi) return current;
@@ -456,6 +454,14 @@ function cleanChildren(parent, current, marker, replacement) {
456
454
  } else parent.insertBefore(node, marker);
457
455
  return [node];
458
456
  }
457
+ function gatherHydratable(element, root) {
458
+ const templates = element.querySelectorAll(`*[data-hk]`);
459
+ for (let i = 0; i < templates.length; i++) {
460
+ const node = templates[i];
461
+ const key = node.getAttribute("data-hk");
462
+ if (!root || key.startsWith(root)) solidJs.sharedConfig.registry.set(key, node);
463
+ }
464
+ }
459
465
  function getHydrationKey() {
460
466
  const hydrate = solidJs.sharedConfig.context;
461
467
  return `${hydrate.id}${hydrate.count++}`;
@@ -630,7 +636,6 @@ exports.clearDelegatedEvents = clearDelegatedEvents;
630
636
  exports.delegateEvents = delegateEvents;
631
637
  exports.dynamicProperty = dynamicProperty;
632
638
  exports.escape = escape;
633
- exports.gatherHydratable = gatherHydratable;
634
639
  exports.generateHydrationScript = generateHydrationScript;
635
640
  exports.getHydrationKey = getHydrationKey;
636
641
  exports.getNextElement = getNextElement;
package/web/dist/dev.js CHANGED
@@ -212,32 +212,24 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
212
212
  continue;
213
213
  }
214
214
  const value = props[prop];
215
- assignProp(node, prop, value, prevProps[prop], isSVG);
216
- prevProps[prop] = value;
215
+ prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
217
216
  }
218
217
  }
219
218
  function hydrate(code, element) {
220
- sharedConfig.resources = globalThis._$HYDRATION.resources;
221
- sharedConfig.completed = globalThis._$HYDRATION.completed;
222
- sharedConfig.events = globalThis._$HYDRATION.events;
219
+ sharedConfig.completed = globalThis._$HY.completed;
220
+ sharedConfig.events = globalThis._$HY.events;
221
+ sharedConfig.load = globalThis._$HY.load;
222
+ sharedConfig.gather = root => gatherHydratable(element, root);
223
+ sharedConfig.registry = new Map();
223
224
  sharedConfig.context = {
224
225
  id: "",
225
- count: 0,
226
- loadResource: globalThis._$HYDRATION.loadResource
226
+ count: 0
227
227
  };
228
- sharedConfig.registry = new Map();
229
228
  gatherHydratable(element);
230
229
  const dispose = render(code, element, [...element.childNodes]);
231
230
  sharedConfig.context = null;
232
231
  return dispose;
233
232
  }
234
- function gatherHydratable(element) {
235
- const templates = element.querySelectorAll(`*[data-hk]`);
236
- for (let i = 0; i < templates.length; i++) {
237
- const node = templates[i];
238
- sharedConfig.registry.set(node.getAttribute("data-hk"), node);
239
- }
240
- }
241
233
  function getNextElement(template) {
242
234
  let node, key;
243
235
  if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -299,7 +291,7 @@ function assignProp(node, prop, value, prev, isSVG) {
299
291
  let isCE, isProp, isChildProp;
300
292
  if (prop === "style") return style(node, value, prev);
301
293
  if (prop === "classList") return classList(node, value, prev);
302
- if (value === prev) return;
294
+ if (value === prev) return prev;
303
295
  if (prop === "ref") {
304
296
  value(node);
305
297
  } else if (prop.slice(0, 3) === "on:") {
@@ -317,6 +309,7 @@ function assignProp(node, prop, value, prev, isSVG) {
317
309
  const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
318
310
  if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
319
311
  }
312
+ return value;
320
313
  }
321
314
  function eventHandler(e) {
322
315
  const key = `$$${e.type}`;
@@ -330,7 +323,7 @@ function eventHandler(e) {
330
323
  Object.defineProperty(e, "currentTarget", {
331
324
  configurable: true,
332
325
  get() {
333
- return node;
326
+ return node || document;
334
327
  }
335
328
  });
336
329
  while (node !== null) {
@@ -385,7 +378,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
385
378
  createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
386
379
  return () => current;
387
380
  }
388
- if (sharedConfig.context && current && current.length) return current;
381
+ if (sharedConfig.context && current && current.length) {
382
+ for (let i; i < array.length; i++) {
383
+ if (array[i].parentNode) return array;
384
+ }
385
+ return current;
386
+ }
389
387
  if (array.length === 0) {
390
388
  current = cleanChildren(parent, current, marker);
391
389
  if (multi) return current;
@@ -453,6 +451,14 @@ function cleanChildren(parent, current, marker, replacement) {
453
451
  } else parent.insertBefore(node, marker);
454
452
  return [node];
455
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
+ }
456
462
  function getHydrationKey() {
457
463
  const hydrate = sharedConfig.context;
458
464
  return `${hydrate.id}${hydrate.count++}`;
@@ -536,4 +542,4 @@ function Dynamic(props) {
536
542
  });
537
543
  }
538
544
 
539
- 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 };
545
+ 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, pipeToNodeWritable, pipeToWritable, render, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };