ui-pagescene: hoist useViewportSize above early return in ControlPanelSceneObject

The hook was called below the `if (!currentSceneObject) return null`
guard, so renders where `currentSceneObject` was null skipped the hook
entirely. When it flipped to non-null on a later render, React saw a
new hook appear and threw "rendered more hooks than during the previous
render".

Move `useViewportSize()` (and the `getScale` helper that consumes it)
above the early return so the hook order is stable across renders.
This commit is contained in:
Tanish Manku committed 2026-05-08 20:10:38 -07:00
1 parent 32a7eb67dd
commit 1ea94e4b42
1 file changed
+9 -6
@@ -212,6 +212,15 @@ export const ControlPanelSceneObject = () => {
};
}, [isShowing]);
// Must come before the early return below — hooks have to run in
// the same order every render or React errors with "rendered more
// hooks than during the previous render".
const viewport = useViewportSize();
const getScale = () => {
const height = viewport.height - 56;
return height < 620 ? height / 620 : 1;
};
if (!currentSceneObject) {
return null;
}
@@ -276,12 +285,6 @@ export const ControlPanelSceneObject = () => {
editorEngine?.deleteObject(currentSceneObject.object_uuid);
};
const viewport = useViewportSize();
const getScale = () => {
const height = viewport.height - 56;
return height < 620 ? height / 620 : 1;
};
return (
<Transition
as="div"