Skip to content

Commit 1037456

Browse files
committed
perf(studio): request the player chunk before the shell's first layout
The dynamic import of @hyperframes/player ran inside the preview's mount effect, which React schedules after the shell's first layout. On a cold open that layout stalls the main thread for seconds, so the chunk request waited behind it for no reason. The import is now kicked at module scope, behind a typeof window guard that preserves the documented SSR contract (the module registers a custom element at load), and the mount effect awaits the already-in-flight promise. Verified in the built bundle: the preload call sits at module top level, so the request goes out on bundle evaluation.
1 parent c9b4263 commit 1037456

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎packages/studio/src/player/components/Player.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { useMountEffect } from "../../hooks/useMountEffect";
55
import { applyPreviewVariablesToUrl } from "../../hooks/previewVariablesStore";
66
import { HyperframesLoader } from "../../components/ui";
77
// NOTE: importing "@hyperframes/player" registers a class extending HTMLElement
8-
// at module load, which throws under SSR. Defer the import to the mount effect
9-
// so it only runs in the browser.
8+
// at module load, which throws under SSR — hence the dynamic import behind a
9+
// `typeof window` guard. Kicking it at module scope rather than in the mount
10+
// effect puts the chunk request in flight before the shell's first layout.
11+
const playerModule = typeof window === "undefined" ? null : import("@hyperframes/player");
1012

1113
interface PlayerProps {
1214
projectId?: string;
@@ -166,8 +168,7 @@ export const Player = forwardRef<HTMLIFrameElement, PlayerProps>(
166168
let canceled = false;
167169
let cleanup: (() => void) | undefined;
168170

169-
// Dynamic import registers the custom element in the browser only.
170-
import("@hyperframes/player").then(() => {
171+
playerModule?.then(() => {
171172
if (canceled) return;
172173

173174
// Create the web component imperatively to avoid JSX custom-element typing.

0 commit comments

Comments
 (0)