@solidtv/solid 1.6.0 → 1.6.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/core/elementNode.js +16 -12
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/primitives/LazyImport.d.ts +13 -4
- package/dist/src/primitives/LazyImport.js +135 -36
- package/dist/src/primitives/LazyImport.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/elementNode.ts +16 -13
- package/src/primitives/LazyImport.ts +148 -42
package/package.json
CHANGED
package/src/core/elementNode.ts
CHANGED
|
@@ -1060,8 +1060,9 @@ export class ElementNode {
|
|
|
1060
1060
|
props: Partial<INodeAnimateProps<CoreShaderNode>>,
|
|
1061
1061
|
animationSettings?: AnimationSettings,
|
|
1062
1062
|
): IAnimationController {
|
|
1063
|
-
if (
|
|
1064
|
-
|
|
1063
|
+
if (!this.rendered) {
|
|
1064
|
+
if (isDev) console.log('NOT RENDERED! CANNOT ANIMATE');
|
|
1065
|
+
return { start: () => {} } as IAnimationController;
|
|
1065
1066
|
}
|
|
1066
1067
|
return (this.lng as IRendererNode).animate(
|
|
1067
1068
|
props,
|
|
@@ -1666,18 +1667,20 @@ export class ElementNode {
|
|
|
1666
1667
|
flexDirection === 'row' || flexDirection === 'row-reverse';
|
|
1667
1668
|
flexFitsWidth = isFlexRow && node.flexBoundary !== 'fixed';
|
|
1668
1669
|
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
if (
|
|
1670
|
+
// Every justify mode except flexStart positions children out of the
|
|
1671
|
+
// container's free space. Shrinking to fit leaves none, so fall back
|
|
1672
|
+
// to filling the parent unless the developer explicitly asked to
|
|
1673
|
+
// contain — in which case honor it and warn about the contradiction.
|
|
1674
|
+
if (
|
|
1675
|
+
flexFitsWidth &&
|
|
1676
|
+
node.justifyContent !== undefined &&
|
|
1677
|
+
node.justifyContent !== 'flexStart'
|
|
1678
|
+
) {
|
|
1679
|
+
if (node.flexBoundary === undefined) {
|
|
1680
|
+
flexFitsWidth = false;
|
|
1681
|
+
} else if (isDev) {
|
|
1679
1682
|
console.warn(
|
|
1680
|
-
`justifyContent '${node.justifyContent}'
|
|
1683
|
+
`justifyContent '${node.justifyContent}' has no free space to distribute on a flexBoundary 'contain' container without an explicit width: `,
|
|
1681
1684
|
this,
|
|
1682
1685
|
);
|
|
1683
1686
|
}
|
|
@@ -3,28 +3,95 @@ import {
|
|
|
3
3
|
createResource,
|
|
4
4
|
createMemo,
|
|
5
5
|
untrack,
|
|
6
|
-
Component,
|
|
7
|
-
JSX,
|
|
6
|
+
type Component,
|
|
7
|
+
type JSX,
|
|
8
8
|
sharedConfig,
|
|
9
9
|
} from 'solid-js';
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
|
|
11
|
+
// Native ESM's failure message, and ONLY native ESM's. It names exactly one
|
|
12
|
+
// module, and that module is always the one handed to `import()` — never one of
|
|
13
|
+
// its dependencies. Chrome says `Failed to fetch dynamically imported module:
|
|
14
|
+
// <url>` and Firefox `error loading dynamically imported module: <url>`; both
|
|
15
|
+
// carry the phrase this matches on.
|
|
16
|
+
//
|
|
17
|
+
// SystemJS is deliberately NOT matched here. Its message is
|
|
18
|
+
// `<failedUrl>, <parentUrl> (SystemJS …)`, and when the failure is a dependency
|
|
19
|
+
// of the requested chunk the FIRST url is that dependency. Cache-busting it
|
|
20
|
+
// would re-import the wrong module, and `lazy` would then read `.default` off
|
|
21
|
+
// it — a blank route, or worse, someone else's component. SystemJS needs no
|
|
22
|
+
// cache-buster anyway: it drops the failed load from its registry, so simply
|
|
23
|
+
// calling `fn` again re-fetches.
|
|
24
|
+
const NATIVE_ESM_CHUNK =
|
|
25
|
+
/dynamically imported module:?\s*(https?:\/\/\S+?\.js)/i;
|
|
17
26
|
|
|
18
27
|
/**
|
|
28
|
+
* The chunk URL to retry under a cache-buster, or `undefined` when the failure
|
|
29
|
+
* is one where re-running the loader is the right move instead.
|
|
30
|
+
*
|
|
19
31
|
* @internal Exported for tests. The primitives barrel re-exports `lazy` by
|
|
20
32
|
* name, so this stays out of the package's public API.
|
|
21
33
|
*/
|
|
22
|
-
export const
|
|
23
|
-
|
|
34
|
+
export const cacheBustableUrl = (error: unknown): string | undefined => {
|
|
35
|
+
const match = NATIVE_ESM_CHUNK.exec(
|
|
36
|
+
error instanceof Error ? error.message : String(error),
|
|
37
|
+
);
|
|
38
|
+
return match ? match[1] : undefined;
|
|
39
|
+
};
|
|
24
40
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Retry backoff delays in milliseconds (500ms, 2s, 5s). Max of 3 retries.
|
|
43
|
+
*
|
|
44
|
+
* @internal Exported for tests — see `cacheBustableUrl`.
|
|
45
|
+
*/
|
|
46
|
+
export const RETRY_DELAYS = [500, 2000, 5000];
|
|
47
|
+
|
|
48
|
+
/** @internal Exported for tests — see `cacheBustableUrl`. */
|
|
49
|
+
export const cacheBust = (url: string, retry = 1): string => {
|
|
50
|
+
const cleanUrl = url
|
|
51
|
+
.replace(/([?&])chunkRetry=\d+(&|$)/, '$1')
|
|
52
|
+
.replace(/[?&]$/, '');
|
|
53
|
+
const separator = cleanUrl.indexOf('?') === -1 ? '?' : '&';
|
|
54
|
+
return cleanUrl + separator + 'chunkRetry=' + retry;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const wait = (ms: number): Promise<void> =>
|
|
58
|
+
new Promise((resolve) => setTimeout(resolve, ms));
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A dynamic `import()`, built at runtime instead of written inline.
|
|
62
|
+
*
|
|
63
|
+
* This is not a style choice, and it must not be "simplified" back to a literal
|
|
64
|
+
* `import(url)`. The token has to stay inside a string, because this file is
|
|
65
|
+
* bundled into apps that cannot parse it:
|
|
66
|
+
*
|
|
67
|
+
* A TV app targeting an old engine may build with no SystemJS transform at all
|
|
68
|
+
* — plain `iife` output plus a syntax-only `build.target`. Rollup cannot rewrite
|
|
69
|
+
* a dynamic import in that format, and a `\/* @vite-ignore *\/` one is invisible
|
|
70
|
+
* to Vite's analysis by design, so the literal survives into the bundle. Dynamic
|
|
71
|
+
* `import()` arrived in Chrome 63; on anything older the whole script fails to
|
|
72
|
+
* *parse*, and the app never boots. That is not hypothetical: it shipped, and it
|
|
73
|
+
* took every Samsung Tizen 4.0 set (Chrome 56) offline until it was rolled back.
|
|
74
|
+
*
|
|
75
|
+
* Inside a `Function` body the token is just text until it is compiled, and that
|
|
76
|
+
* compilation is what the `try` guards. Old engines throw a SyntaxError here and
|
|
77
|
+
* a CSP without `unsafe-eval` throws an EvalError; either way we return `null`
|
|
78
|
+
* and the caller re-runs the loader instead — the same fallback every SystemJS
|
|
79
|
+
* failure already takes. Resolved once and cached, including the `null`.
|
|
80
|
+
*/
|
|
81
|
+
let nativeImport: ((url: string) => Promise<unknown>) | null | undefined;
|
|
82
|
+
|
|
83
|
+
const getNativeImport = (): ((url: string) => Promise<unknown>) | null => {
|
|
84
|
+
if (nativeImport === undefined) {
|
|
85
|
+
try {
|
|
86
|
+
nativeImport = new Function('u', 'return import(u)') as (
|
|
87
|
+
url: string,
|
|
88
|
+
) => Promise<unknown>;
|
|
89
|
+
} catch {
|
|
90
|
+
nativeImport = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return nativeImport;
|
|
94
|
+
};
|
|
28
95
|
|
|
29
96
|
// lazy load a function component asynchronously
|
|
30
97
|
export function lazy<T extends Component<any>>(
|
|
@@ -33,38 +100,77 @@ export function lazy<T extends Component<any>>(
|
|
|
33
100
|
let comp: () => T | undefined;
|
|
34
101
|
let p: Promise<{ default: T }> | undefined;
|
|
35
102
|
|
|
36
|
-
// Retry the import
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// rejection is replayed for the rest of
|
|
40
|
-
// again, not even on a later navigation.
|
|
41
|
-
//
|
|
103
|
+
// Retry the import up to 3 times before giving up, with a backoff of 500ms, 2s,
|
|
104
|
+
// and 5s between retries. On a TV the chunk fetch is the fragile part — a brief
|
|
105
|
+
// dropout as the viewer presses OK on a rail rejects the import, and because
|
|
106
|
+
// `p` memoises the promise that single rejection is replayed for the rest of
|
|
107
|
+
// the session: the route never renders again, not even on a later navigation.
|
|
108
|
+
// Retries with backoff turn transient failures into a slightly delayed navigation.
|
|
109
|
+
//
|
|
110
|
+
// How it retries depends on which module system failed, because the two need
|
|
111
|
+
// opposite things.
|
|
112
|
+
//
|
|
113
|
+
// SystemJS — the `@vitejs/plugin-legacy` output older TV browsers run — drops
|
|
114
|
+
// the failed load from its registry, so re-running `fn` genuinely re-fetches.
|
|
115
|
+
// That is also the ONLY safe option there: its message names the failed
|
|
116
|
+
// dependency before the chunk that pulled it in, so a URL lifted out of it is
|
|
117
|
+
// frequently not the module we asked for.
|
|
42
118
|
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
// no-op precisely where it is needed. A distinct URL gets a fresh module-map
|
|
51
|
-
// entry and actually re-fetches.
|
|
119
|
+
// Native ESM does the opposite. The module map memoises the *failure*, so a
|
|
120
|
+
// second `import()` of the same specifier resolves straight to the cached
|
|
121
|
+
// rejection without ever touching the network — re-running `fn` is a no-op
|
|
122
|
+
// exactly where it is needed. It also names one module and only one, the one
|
|
123
|
+
// handed to `import()`, so a cache-busted re-import of it is both safe and
|
|
124
|
+
// necessary: each retry gets a distinct URL (`chunkRetry=1`, `chunkRetry=2`,
|
|
125
|
+
// `chunkRetry=3`), creating a fresh module-map entry that really re-fetches.
|
|
52
126
|
//
|
|
53
|
-
// The cost is a duplicate module record for this one chunk. Its own
|
|
54
|
-
// are unaffected — they resolve to their normal, already-cached URLs —
|
|
55
|
-
// duplication does not spread, and it only happens on a retry that
|
|
56
|
-
// otherwise have left the route dead.
|
|
127
|
+
// The cost there is a duplicate module record for this one chunk. Its own
|
|
128
|
+
// imports are unaffected — they resolve to their normal, already-cached URLs —
|
|
129
|
+
// so the duplication does not spread, and it only happens on a retry that
|
|
130
|
+
// would otherwise have left the route dead.
|
|
57
131
|
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
132
|
+
// Written using explicit Promise chaining instead of `async`/`await` so older
|
|
133
|
+
// engines (such as Chrome 38/53 on webOS) and ES5 downleveling do not require
|
|
134
|
+
// regeneratorRuntime or complex state-machine transpilation helpers.
|
|
135
|
+
const load = (): Promise<{ default: T }> => {
|
|
136
|
+
let url: string | undefined;
|
|
137
|
+
|
|
138
|
+
const attemptLoad = (attempt: number): Promise<{ default: T }> => {
|
|
139
|
+
let p: Promise<{ default: T }>;
|
|
140
|
+
try {
|
|
141
|
+
if (attempt === 0) {
|
|
142
|
+
p = fn();
|
|
143
|
+
} else if (url !== undefined) {
|
|
144
|
+
// Null when this engine cannot compile a dynamic import, or a CSP
|
|
145
|
+
// forbids compiling one — see `getNativeImport`. Re-running the
|
|
146
|
+
// loader is then the best available retry, exactly as it is for
|
|
147
|
+
// every SystemJS failure.
|
|
148
|
+
const importer = getNativeImport();
|
|
149
|
+
p = (
|
|
150
|
+
importer !== null ? importer(cacheBust(url, attempt)) : fn()
|
|
151
|
+
) as Promise<{ default: T }>;
|
|
152
|
+
} else {
|
|
153
|
+
p = fn();
|
|
154
|
+
}
|
|
155
|
+
} catch (syncError: unknown) {
|
|
156
|
+
p = Promise.reject(syncError);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return p.catch((error: unknown) => {
|
|
160
|
+
const nextUrl = cacheBustableUrl(error);
|
|
161
|
+
url = nextUrl !== undefined ? nextUrl : url;
|
|
162
|
+
if (attempt < RETRY_DELAYS.length) {
|
|
163
|
+
const delay = RETRY_DELAYS[attempt];
|
|
164
|
+
if (delay !== undefined) {
|
|
165
|
+
return wait(delay).then(() => attemptLoad(attempt + 1));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Promise.reject(error);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return attemptLoad(0);
|
|
173
|
+
};
|
|
68
174
|
|
|
69
175
|
const wrap: T & { preload?: () => void } = ((props: any) => {
|
|
70
176
|
const ctx = sharedConfig.context;
|