Skip to content

Commit e3e16ff

Browse files
committed
chore: warn on explicit loadCdn:true on the experimental backend
The experimental backend ignores `loadCdn` — its CommandQueue file-load API (`RiveFile.fromSource(source, worker)`) has no CDN asset resolution, so the `loadCdn` argument on `RiveFileFactory.from*` is silently a no-op there. `loadCdn` is now optional (the effective default of `true` is applied only at the native call via `?? true`), and a one-time `console.warn` is emitted only when a caller *explicitly* passes `loadCdn: true` while on the experimental backend — so the common case (not passing `loadCdn`, e.g. `useRiveFile`) is never warned. JSDoc updated to note the option is ignored on experimental.
1 parent ec3cc6a commit e3e16ff

1 file changed

Lines changed: 49 additions & 14 deletions

File tree

src/core/RiveFile.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@ import type { ResolvedReferencedAssets } from './ReferencedAssets';
1010
const RiveFileInternal =
1111
NitroModules.createHybridObject<RiveFileFactoryInternal>('RiveFileFactory');
1212

13+
let _warnedLoadCdnUnsupported = false;
14+
15+
/**
16+
* The experimental backend ignores `loadCdn` — its CommandQueue file-load API
17+
* has no CDN asset resolution. Warn once (per JS runtime) when a caller
18+
* *explicitly* opts into `loadCdn: true` there, so they know CDN-referenced
19+
* assets must be supplied via `referencedAssets` instead. Callers that don't
20+
* pass `loadCdn` (the common case) are not warned.
21+
*/
22+
function warnLoadCdnUnsupportedOnExperimental(
23+
loadCdn: boolean | undefined
24+
): void {
25+
if (
26+
loadCdn === true &&
27+
!_warnedLoadCdnUnsupported &&
28+
RiveFileInternal.backend === 'experimental'
29+
) {
30+
_warnedLoadCdnUnsupported = true;
31+
console.warn(
32+
'[Rive] `loadCdn: true` is not supported on the experimental backend and is ignored. ' +
33+
'CDN-referenced assets (fonts/images) are not fetched automatically — supply them ' +
34+
'via the `referencedAssets` option instead.'
35+
);
36+
}
37+
}
38+
1339
/**
1440
* Factory namespace for creating RiveFile instances from different sources.
1541
* Provides static methods to load Rive files from URLs, resources, or raw bytes.
@@ -23,79 +49,88 @@ export namespace RiveFileFactory {
2349
/**
2450
* Creates a RiveFile instance from a URL.
2551
* @param url - The URL of the Rive (.riv) file
26-
* @param loadCdn - Whether to load from CDN (default: true)
52+
* @param loadCdn - Whether to fetch CDN-referenced assets (default: true).
53+
* Ignored on the experimental backend — supply assets via `referencedAssets` instead.
2754
* @returns Promise that resolves to a RiveFile instance
2855
*/
2956
export async function fromURL(
3057
url: string,
3158
referencedAssets: ResolvedReferencedAssets | undefined,
32-
loadCdn: boolean = true
59+
loadCdn?: boolean
3360
): Promise<RiveFile> {
61+
warnLoadCdnUnsupportedOnExperimental(loadCdn);
3462
return RiveFileInternal.fromURL(
3563
url,
36-
loadCdn,
64+
loadCdn ?? true,
3765
referencedAssets ? { data: referencedAssets } : undefined
3866
);
3967
}
4068

4169
/**
4270
* Creates a RiveFile instance from a local file path URL.
4371
* @param pathURL - The local file path of the Rive (.riv) file
44-
* @param loadCdn - Whether to load from CDN (default: true)
72+
* @param loadCdn - Whether to fetch CDN-referenced assets (default: true).
73+
* Ignored on the experimental backend — supply assets via `referencedAssets` instead.
4574
* @returns Promise that resolves to a RiveFile instance
4675
*/
4776
export async function fromFileURL(
4877
fileURL: string,
4978
referencedAssets: ResolvedReferencedAssets | undefined = undefined,
50-
loadCdn: boolean = true
79+
loadCdn?: boolean
5180
): Promise<RiveFile> {
81+
warnLoadCdnUnsupportedOnExperimental(loadCdn);
5282
return RiveFileInternal.fromFileURL(
5383
fileURL,
54-
loadCdn,
84+
loadCdn ?? true,
5585
referencedAssets ? { data: referencedAssets } : undefined
5686
);
5787
}
5888

5989
/**
6090
* Creates a RiveFile instance from a local resource.
6191
* @param resource - The name of the local resource
62-
* @param loadCdn - Whether to load from CDN (default: true)
92+
* @param loadCdn - Whether to fetch CDN-referenced assets (default: true).
93+
* Ignored on the experimental backend — supply assets via `referencedAssets` instead.
6394
* @returns Promise that resolves to a RiveFile instance
6495
*/
6596
export async function fromResource(
6697
resource: string,
6798
referencedAssets: ResolvedReferencedAssets | undefined,
68-
loadCdn: boolean = true
99+
loadCdn?: boolean
69100
): Promise<RiveFile> {
101+
warnLoadCdnUnsupportedOnExperimental(loadCdn);
70102
return RiveFileInternal.fromResource(
71103
resource,
72-
loadCdn,
104+
loadCdn ?? true,
73105
referencedAssets ? { data: referencedAssets } : undefined
74106
);
75107
}
76108

77109
/**
78110
* Creates a RiveFile instance from raw bytes.
79111
* @param bytes - The raw bytes of the Rive (.riv) file
80-
* @param loadCdn - Whether to load from CDN (default: true)
112+
* @param loadCdn - Whether to fetch CDN-referenced assets (default: true).
113+
* Ignored on the experimental backend — supply assets via `referencedAssets` instead.
81114
* @returns Promise that resolves to a RiveFile instance
82115
*/
83116
export async function fromBytes(
84117
bytes: ArrayBuffer,
85118
referencedAssets: ResolvedReferencedAssets | undefined,
86-
loadCdn: boolean = true
119+
loadCdn?: boolean
87120
): Promise<RiveFile> {
121+
warnLoadCdnUnsupportedOnExperimental(loadCdn);
88122
return RiveFileInternal.fromBytes(
89123
bytes,
90-
loadCdn,
124+
loadCdn ?? true,
91125
referencedAssets ? { data: referencedAssets } : undefined
92126
);
93127
}
94128

95129
/**
96130
* Creates a RiveFile instance from a source that can be either a resource ID or a URI object.
97131
* @param source - Either a number representing a resource ID or an object with a uri property
98-
* @param loadCdn - Whether to load from CDN (default: true)
132+
* @param loadCdn - Whether to fetch CDN-referenced assets (default: true).
133+
* Ignored on the experimental backend — supply assets via `referencedAssets` instead.
99134
* @returns Promise that resolves to a RiveFile instance
100135
* @throws Error if the source is invalid or cannot be resolved
101136
* @example
@@ -117,7 +152,7 @@ export namespace RiveFileFactory {
117152
export async function fromSource(
118153
source: number | { uri: string },
119154
referencedAssets: ResolvedReferencedAssets | undefined,
120-
loadCdn: boolean = true
155+
loadCdn?: boolean
121156
): Promise<RiveFile> {
122157
const assetID = typeof source === 'number' ? source : null;
123158
const sourceURI = typeof source === 'object' ? source.uri : null;

0 commit comments

Comments
 (0)