Skip to content

Commit 48a19db

Browse files
Merge branch 'main' into bump-1.4.35
2 parents 34ac46d + a81bd77 commit 48a19db

File tree

6 files changed

+87
-3
lines changed

6 files changed

+87
-3
lines changed

CHANGELOG.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Changelog
2+
3+
## [1.4.33-1] - 2025-10-28
4+
5+
### Added
6+
7+
#### Custom Script URL Support
8+
9+
- **New `sdkUrl` prop**: Added ability to specify a custom URL for the Unicorn Studio SDK script
10+
- Allows loading the SDK from custom CDNs or self-hosted locations
11+
- Defaults to the official Unicorn Studio CDN URL if not specified
12+
- Available for both React and Next.js components
13+
14+
### Usage Example
15+
16+
```tsx
17+
<UnicornScene
18+
projectId="YOUR_PROJECT_EMBED_ID"
19+
sdkUrl="https://your-custom-cdn.com/unicornStudio.umd.js"
20+
width={800}
21+
height={600}
22+
/>
23+
```
24+
25+
### Technical Details
26+
27+
- Modified both React and Next.js components to accept the new `sdkUrl` prop
28+
- Updated TypeScript definitions to include the optional `sdkUrl` property
29+
- Maintains backward compatibility with existing implementations
30+
31+
### Contributors
32+
33+
- @schellenbergk - Added custom script URL support
34+
35+
### Note
36+
37+
Using a custom script URL may violate Unicorn.Studio's Terms of Service. Please consult their legal terms before implementing this feature.
38+
39+
## [1.4.29-1] - 2025-08-15
40+
41+
### Fixed
42+
43+
#### Next.js App Router Compatibility
44+
45+
- **Prevented duplicate script initialization**: Modified `useUnicornStudioScript` hook to check if UnicornStudio is already loaded before setting the loaded state, preventing duplicate triggers in Next.js App Router environments
46+
- **Added mount-time script detection**: Added `useEffect` hook to detect if UnicornStudio is already available when the component mounts, ensuring proper initialization in server-side rendered contexts
47+
- **Improved error handling**: Updated error handler to properly reset the `isLoaded` state when script loading fails
48+
49+
#### Scene Initialization Improvements
50+
51+
- **Prevented concurrent initializations**: Added `isInitializingRef` flag to prevent multiple simultaneous scene initialization attempts, which could occur during React's strict mode or rapid re-renders
52+
- **Optimized re-initialization logic**: Improved detection of already initialized scenes with the same configuration to avoid unnecessary re-initializations
53+
- **Better cleanup handling**: Separated cleanup logic into its own `useEffect` to ensure proper resource management on component unmount
54+
- **Fixed initialization key reset**: Added proper reset of initialization key when projectId or jsonFilePath changes, allowing fresh initialization with new parameters
55+
56+
### Internal
57+
58+
- Removed debug console.log statements
59+
- Updated package version to include hotfix suffix (-1)
60+
61+
### Technical Details
62+
63+
This hotfix addresses critical issues that were affecting the library's compatibility with Next.js App Router, particularly in scenarios involving:
64+
65+
- Server-side rendering (SSR)
66+
- React Strict Mode
67+
- Component remounting and hot module replacement (HMR)
68+
- Rapid prop changes
69+
70+
The changes ensure more robust initialization and cleanup processes, preventing memory leaks and duplicate scene instances.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ const constants = {
277277

278278
**Warning**: Using a custom script URL may violate Unicorn.Studio's Terms of Service. Consult their legal terms before implementing.
279279

280+
**React/Next.js Example usage:**
281+
282+
```tsx
283+
<UnicornScene
284+
projectId="YOUR_PROJECT_EMBED_ID"
285+
sdkUrl="https://your-custom-cdn.com/unicornStudio.umd.js"
286+
width={800}
287+
height={600}
288+
/>
289+
```
290+
280291
### Browser Support
281292

282293
- Chrome (latest)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@
8686
"engines": {
8787
"node": ">=16.0.0"
8888
}
89-
}
89+
}

src/next/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { isWebGLSupported } from "../shared/utils";
1111
function UnicornScene({
1212
projectId,
1313
jsonFilePath,
14+
sdkUrl = UNICORN_STUDIO_CDN_URL,
1415
width = DEFAULT_VALUES.width,
1516
height = DEFAULT_VALUES.height,
1617
scale = DEFAULT_VALUES.scale,
@@ -86,7 +87,7 @@ function UnicornScene({
8687
return (
8788
<>
8889
<Script
89-
src={UNICORN_STUDIO_CDN_URL}
90+
src={sdkUrl}
9091
strategy={lazyLoad ? "lazyOnload" : "afterInteractive"}
9192
onLoad={handleScriptLoad}
9293
onError={handleScriptError}

src/react/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isWebGLSupported } from "../shared/utils";
88
function UnicornScene({
99
projectId,
1010
jsonFilePath,
11+
sdkUrl = UNICORN_STUDIO_CDN_URL,
1112
width = DEFAULT_VALUES.width,
1213
height = DEFAULT_VALUES.height,
1314
scale = DEFAULT_VALUES.scale,
@@ -32,7 +33,7 @@ function UnicornScene({
3233
const {
3334
isLoaded,
3435
error: scriptError,
35-
} = useUnicornStudioScript(UNICORN_STUDIO_CDN_URL);
36+
} = useUnicornStudioScript(sdkUrl);
3637

3738
const { error: sceneError } = useUnicornScene({
3839
elementRef,

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ScaleRange = number;
66
export interface UnicornSceneProps {
77
projectId?: string;
88
jsonFilePath?: string;
9+
sdkUrl?: string;
910
altText?: string;
1011
width?: number | string;
1112
height?: number | string;

0 commit comments

Comments
 (0)