Create professional demos and 3D mockups in seconds, directly in your browser
feat: refactor theme cookie handling and improve effect dependencies in 3D viewer components
CristianOlivera1d52b4eb448cf
diff --git a/app/components/common/UserMenuDropdown.tsx b/app/components/common/UserMenuDropdown.tsxindex 1a0933d..cdc9eb1 100644--- a/app/components/common/UserMenuDropdown.tsx+++ b/app/components/common/UserMenuDropdown.tsx@@ -41,10 +41,6 @@ function applyThemeClass(theme: Theme, isEditorPage: boolean) {document.getElementById(EDITOR_ROOT_ID)?.classList.toggle("dark", dark);}-// Persiste el tema *efectivo* resuelto (nunca "system") para que el script inline-// del root layout pueda aplicarlo en SSR antes del primer paint (sin flash de tema).-// Además guarda la preferencia cruda para que el script pueda resolver "system"-// contra prefers-color-scheme cuando la cookie efectiva quedó desactualizada.function writeThemeCookie(theme: Theme) {const dark = isDarkResolved(theme);document.cookie = `${THEME_COOKIE}=${dark ? "dark" : "light"}; path=/; max-age=${THEME_COOKIE_MAX_AGE}; samesite=lax`;diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex b932671..945617a 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -261,7 +261,6 @@ function VideoCanvasInner({return getThumbnailForTime(scrubTime);}, [isScrubbing, scrubTime, getThumbnailForTime]);-const visibleCanvasElements = useMemo(() => {if (mediaType !== "video") return canvasElements;return filterVisibleElements(canvasElements, currentTime, videoDuration);diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsxindex 51a2669..9ac4b0f 100644--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx@@ -364,7 +364,11 @@ export function DoubleIPhoneScene({screenMatRef.current.dispose();}};- }, [gltf.scene, onLoaded]);+ }, [gltf.scene]);++ useEffect(() => {+ onLoaded?.();+ }, [onLoaded]);const prevRotationRef = useRef<{ x: number; y: number } | null>(null);diff --git a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsxindex e5ff927..291a446 100644--- a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx@@ -4,12 +4,12 @@ import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, Environment, OrbitControls, ContactShadows, useGLTF } from "@react-three/drei";import { useEffect, useRef, useState, Suspense, useCallback, useLayoutEffect } from "react";import * as THREE from "three";-import {- createCoverScreenCanvas,- applyCropToImage,- type ImageMaskConfigLike,- parseShadowColor,- applyTextureCover+import {+ createCoverScreenCanvas,+ applyCropToImage,+ type ImageMaskConfigLike,+ parseShadowColor,+ applyTextureCover} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";@@ -65,7 +65,7 @@ export function IPadMiniScene({}: Props & { rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; onLoaded?: () => void; }) {const { gl, scene, camera, invalidate, size } = useThree();const gltf = useGLTF(MODEL_URL, DRACO_URL);-+const orbitRef = useRef<OrbitControlsType | null>(null);const screenMatRef = useRef<THREE.MeshPhysicalMaterial | null>(null);const videoTextureRef = useRef<THREE.VideoTexture | null>(null);@@ -106,11 +106,11 @@ export function IPadMiniScene({const safeH = Math.max(1, Math.min(Math.round(h), maxDim));(cam as THREE.PerspectiveCamera).aspect = safeW / safeH;(cam as THREE.PerspectiveCamera).updateProjectionMatrix();-+gl.setPixelRatio(RENDER_PIXEL_RATIO);gl.setSize(safeW, safeH, false);if (videoTextureRef.current) videoTextureRef.current.needsUpdate = true;-+gl.render(scene, cam);},restorePreview: () => {@@ -330,10 +330,14 @@ export function IPadMiniScene({screenMatRef.current.dispose();}};- }, [gltf.scene, onLoaded]);+ }, [gltf.scene]);++ useEffect(() => {+ onLoaded?.();+ }, [onLoaded]);const prevRotationRef = useRef<{ x: number; y: number } | null>(null);-+useEffect(() => {if (isUserInteractingRef.current) return;@@ -517,13 +521,13 @@ function CanvasWithLoader(}export function IPadMini63DViewer(props: Props) {- const {- shadowIntensity = 0,- shadowColor = "#000000",- imageMaskConfig = null,+ const {+ shadowIntensity = 0,+ shadowColor = "#000000",+ imageMaskConfig = null,isSelected = false,onHoverChange,- onSelectChange+ onSelectChange} = props;const rootRef = useRef<THREE.Group | null>(null);@@ -646,12 +650,12 @@ export function IPadMini63DViewer(props: Props) {}}}>- <CanvasWithLoader- {...props}+ <CanvasWithLoader+ {...props}isSelected={isSelected}isHovered={modelHovered}- rootRef={rootRef}- cameraRef={cameraRef}+ rootRef={rootRef}+ cameraRef={cameraRef}onMount={handleCanvasMount}/></div>diff --git a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsxindex c89f96f..358d860 100644--- a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx+++ b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx@@ -1,6 +1,6 @@"use client";import { Canvas } from "@react-three/fiber";-import { Suspense, useEffect, useRef, useState } from "react";+import { Suspense, useCallback, useEffect, useRef, useState } from "react";import * as THREE from "three";import { IPhone13ProMax3DApi, IPhone13ProMaxScene } from "./IPhone13ProMax3DViewer";import { DoubleIPhone3DApi, DoubleIPhoneScene } from "./DoubleIPhone3DViewer";@@ -138,9 +138,6 @@ export function Mockup3DStage({ device, rootRef: externalRootRef, cameraRef: extconst cameraRef = externalCameraRef ?? internalCameraRef;const canvasElRef = useRef<HTMLCanvasElement | null>(null);- // When 3D motion is active we need a continuous render loop so the- // Motion3DApplicator's useFrame fires every tick. Without this, the- // "demand" frameloop would only re-render on user interaction.const hasMotion = props.motionTransform && props.motionTransform !== REST_MOCKUP_3D_MOTION;const [loaded, setLoaded] = useState(false);@@ -151,10 +148,10 @@ export function Mockup3DStage({ device, rootRef: externalRootRef, cameraRef: extonLoadedChange?.(false);}- const markLoaded = () => {+ const markLoaded = useCallback(() => {setLoaded(true);onLoadedChange?.(true);- };+ }, [onLoadedChange]);const handleMount = (canvas: HTMLCanvasElement) => {canvasElRef.current = canvas;