@solidtv/solid 1.1.1 → 1.1.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.
- package/dist/src/primitives/Column.jsx +1 -1
- package/dist/src/primitives/Column.jsx.map +1 -1
- package/dist/src/primitives/KeepAlive.d.ts +4 -3
- package/dist/src/primitives/KeepAlive.jsx +48 -21
- package/dist/src/primitives/KeepAlive.jsx.map +1 -1
- package/dist/src/primitives/Row.jsx +1 -1
- package/dist/src/primitives/Row.jsx.map +1 -1
- package/dist/src/primitives/Virtual.jsx +1 -1
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/utils/handleNavigation.js +13 -10
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/primitives/Column.tsx +0 -1
- package/src/primitives/KeepAlive.tsx +73 -37
- package/src/primitives/Row.tsx +0 -1
- package/src/primitives/Virtual.tsx +0 -1
- package/src/primitives/utils/handleNavigation.ts +20 -11
|
@@ -34,7 +34,6 @@ export const Column: Component<ColumnProps> = (props) => {
|
|
|
34
34
|
<view
|
|
35
35
|
transitionUp={defaultTransitionUp}
|
|
36
36
|
transitionDown={defaultTransitionDown}
|
|
37
|
-
transition={/* @once */ {}}
|
|
38
37
|
{...props}
|
|
39
38
|
onUp={/* @once */ chainFunctions(props.onUp, onUp)}
|
|
40
39
|
onDown={/* @once */ chainFunctions(props.onDown, onDown)}
|
|
@@ -5,12 +5,15 @@ import { chainFunctions } from './utils/chainFunctions.js';
|
|
|
5
5
|
|
|
6
6
|
export interface KeepAliveElement {
|
|
7
7
|
id: string;
|
|
8
|
-
owner
|
|
9
|
-
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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,20 +193,22 @@ 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
|
-
|
|
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) => {
|
|
@@ -216,13 +238,13 @@ 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 ElementNode | undefined;
|
|
219
242
|
|
|
220
243
|
if (
|
|
221
|
-
|
|
222
|
-
(props.shouldDispose?.(key) ||
|
|
223
|
-
(existing.children as unknown as ElementNode)?.destroyed)
|
|
244
|
+
existingChild &&
|
|
245
|
+
(props.shouldDispose?.(key) || existingChild.destroyed)
|
|
224
246
|
) {
|
|
225
|
-
|
|
247
|
+
existingChild.destroy();
|
|
226
248
|
existing.dispose?.();
|
|
227
249
|
keepAliveRouteElements.delete(key);
|
|
228
250
|
existing = getExisting();
|
|
@@ -235,7 +257,7 @@ export const KeepAliveRoute = <S extends string>(
|
|
|
235
257
|
return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
|
|
236
258
|
});
|
|
237
259
|
} else if (existing.children) {
|
|
238
|
-
(existing.children as unknown as ElementNode)
|
|
260
|
+
(existing.children as unknown as ElementNode).setFocus();
|
|
239
261
|
return props.preload!({ ...preloadProps, isAlive: existing.isAlive! });
|
|
240
262
|
} else {
|
|
241
263
|
return props.preload!({
|
|
@@ -246,23 +268,37 @@ export const KeepAliveRoute = <S extends string>(
|
|
|
246
268
|
}
|
|
247
269
|
: undefined;
|
|
248
270
|
|
|
249
|
-
|
|
271
|
+
const componentWrapper = (childProps: RouteProps<S>) => {
|
|
272
|
+
const existing = getExisting();
|
|
273
|
+
// Do NOT spread `childProps`: it has a `children` getter (the router's
|
|
274
|
+
// outlet) that would be invoked eagerly, creating a <Show> subscribed to
|
|
275
|
+
// the next routeStates index. That stale Show would then fire when the
|
|
276
|
+
// user navigates to a sibling route whose matches populate that index,
|
|
277
|
+
// causing the sibling's component to be created from the preserved
|
|
278
|
+
// KeepAlive subtree. Inherit via prototype so the getter is preserved.
|
|
279
|
+
const innerProps = Object.create(childProps, {
|
|
280
|
+
isAlive: { value: existing.isAlive!, enumerable: true, configurable: true },
|
|
281
|
+
}) as RouteProps<S> & { isAlive: s.Accessor<boolean> };
|
|
282
|
+
return (
|
|
283
|
+
<KeepAliveRouteInternal
|
|
284
|
+
id={key}
|
|
285
|
+
onRemove={onRemove}
|
|
286
|
+
onRender={onRender}
|
|
287
|
+
transition={props.transition}
|
|
288
|
+
>
|
|
289
|
+
{props.component(innerProps)}
|
|
290
|
+
</KeepAliveRouteInternal>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const routeElement = (
|
|
250
295
|
<Route
|
|
251
296
|
{...props}
|
|
252
297
|
preload={preload}
|
|
253
|
-
component={
|
|
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
|
-
}}
|
|
298
|
+
component={componentWrapper}
|
|
266
299
|
/>
|
|
267
300
|
);
|
|
301
|
+
|
|
302
|
+
keepAliveRouteCache.set(key, routeElement);
|
|
303
|
+
return routeElement;
|
|
268
304
|
};
|
package/src/primitives/Row.tsx
CHANGED
|
@@ -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)}
|
|
@@ -540,7 +540,6 @@ function createVirtual<T>(
|
|
|
540
540
|
|
|
541
541
|
return (
|
|
542
542
|
<view
|
|
543
|
-
transition={/* @once */ {}}
|
|
544
543
|
transitionLeft={isRow ? defaultTransitionBack : undefined}
|
|
545
544
|
transitionRight={isRow ? defaultTransitionForward : undefined}
|
|
546
545
|
transitionUp={!isRow ? defaultTransitionUp : undefined}
|
|
@@ -117,32 +117,41 @@ export const navigableForwardFocus: lng.ForwardFocusHandler = function () {
|
|
|
117
117
|
return selectChild(navigable, selected);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
type NavWithTransitionCache = lngp.NavigableElement & {
|
|
121
|
+
_navBaseTransition?: object;
|
|
122
|
+
_navLastMerged?: object;
|
|
123
|
+
};
|
|
124
|
+
|
|
120
125
|
export function handleNavigation(
|
|
121
126
|
direction: 'up' | 'right' | 'down' | 'left',
|
|
122
127
|
): lng.KeyHandler {
|
|
123
128
|
return function () {
|
|
124
|
-
const el = this as
|
|
125
|
-
const
|
|
129
|
+
const el = this as NavWithTransitionCache;
|
|
130
|
+
const directional =
|
|
126
131
|
direction === 'up'
|
|
127
132
|
? el.transitionUp
|
|
128
133
|
: direction === 'down'
|
|
129
134
|
? el.transitionDown
|
|
130
135
|
: direction === 'left'
|
|
131
136
|
? el.transitionLeft
|
|
132
|
-
:
|
|
133
|
-
? el.transitionRight
|
|
134
|
-
: undefined;
|
|
137
|
+
: el.transitionRight;
|
|
135
138
|
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
139
|
+
if (directional) {
|
|
140
|
+
const current =
|
|
138
141
|
typeof el.transition === 'object' && el.transition !== null
|
|
139
142
|
? el.transition
|
|
140
143
|
: {};
|
|
141
144
|
|
|
142
|
-
el.transition
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
// Re-snapshot the developer-supplied transition whenever el.transition
|
|
146
|
+
// doesn't match our last merge — that means it was set externally
|
|
147
|
+
// (initial render or a reactive update), not by this handler.
|
|
148
|
+
if (current !== el._navLastMerged) {
|
|
149
|
+
el._navBaseTransition = current;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const merged = { ...(directional as object), ...el._navBaseTransition };
|
|
153
|
+
el.transition = merged;
|
|
154
|
+
el._navLastMerged = merged;
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
return moveSelection(
|