@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1060,8 +1060,9 @@ export class ElementNode {
1060
1060
  props: Partial<INodeAnimateProps<CoreShaderNode>>,
1061
1061
  animationSettings?: AnimationSettings,
1062
1062
  ): IAnimationController {
1063
- if (isDev) {
1064
- assertTruthy(this.rendered, 'Node must be rendered before animating');
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
- if (isDev && flexFitsWidth) {
1670
- const needsWidthForJustify = [
1671
- 'center',
1672
- 'flex-end',
1673
- 'space-between',
1674
- 'space-around',
1675
- 'space-evenly',
1676
- ].includes(node.justifyContent as string);
1677
-
1678
- if (needsWidthForJustify) {
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}' requires an explicit width on the flex container; without one it shrinks to fit its children and has no free space to distribute: `,
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
- // The chunk URL, as named in the failure message by either module system:
12
- // native ESM reports `Failed to fetch dynamically imported module: <url>`,
13
- // SystemJS reports `<url>, (SystemJS https://…/errors.md#3)`. The first
14
- // http(s) URL ending in `.js` is the chunk in both cases — SystemJS's trailing
15
- // docs link has no `.js` in it, so it cannot be matched by mistake.
16
- const CHUNK_URL = /https?:\/\/\S+?\.js/;
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 chunkUrlFromError = (error: unknown): string | undefined =>
23
- CHUNK_URL.exec(error instanceof Error ? error.message : String(error))?.[0];
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
- /** @internal Exported for tests — see `chunkUrlFromError`. */
26
- export const cacheBust = (url: string): string =>
27
- `${url}${url.indexOf('?') === -1 ? '?' : '&'}chunkRetry=1`;
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 exactly once before giving up. On a TV the chunk fetch is
37
- // the fragile part — a brief dropout as the viewer presses OK on a rail
38
- // rejects the import, and because `p` memoises the promise that single
39
- // rejection is replayed for the rest of the session: the route never renders
40
- // again, not even on a later navigation. One retry turns the common transient
41
- // failure into a marginally slower navigation.
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
- // The retry re-imports under a cache-busting URL rather than re-running `fn`,
44
- // because re-running only works on one of the two module systems we ship to.
45
- // Under SystemJS — the `@vitejs/plugin-legacy` output older TV browsers run —
46
- // the failed load is dropped from the registry, so calling `fn` again really
47
- // does re-fetch. Native ESM does the opposite: the module map memoises the
48
- // *failure*, so a second `import()` of the same specifier resolves straight to
49
- // the cached rejection without ever touching the network, and the retry is a
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 imports
54
- // are unaffected — they resolve to their normal, already-cached URLs — so the
55
- // duplication does not spread, and it only happens on a retry that would
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
- // `fn` is still the fallback when the message names no URL: no worse than not
59
- // retrying, and it keeps non-URL loaders (tests, custom resolvers) working.
60
- const load = (): Promise<{ default: T }> =>
61
- fn().catch((error: unknown) => {
62
- const url = chunkUrlFromError(error);
63
- if (url === undefined) return fn();
64
- return import(/* @vite-ignore */ cacheBust(url)) as Promise<{
65
- default: T;
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;