Move: pure imperative via sceneRegistry (smooth, zero re-renders); drop dev logs
User feedback: updating the store per tick caused tons of React
re-renders → laggy drag. Switched to pure imperative.
MoveRegistryNodeTool now:
- Mutates `sceneRegistry.nodes.get(id).position` directly per
grid:move tick. No useScene.updateNode during drag. No store
change → no renderer re-render → R3F doesn't reapply
`position={node.position}` → the imperative mutation sticks.
- On commit: single tracked `useScene.updateNode(id, { position })`.
Undo replays one step (original → final), no per-tick spam.
- On cancel / unmount: imperatively snap the mesh back to original.
Store was never touched so no data revert needed.
Trade-off vs the items pattern (which does update the store per tick
and re-renders per tick): our approach is faster but assumes the
renderer doesn't re-render mid-drag. Items get away with constant
re-renders because their renderer is heavily optimized; for parametric
shelves (and future kinds) the imperative path is simpler and faster.
Cleanup: removed the dev `[shelf] rendered` and `[shelf] placed`
console.info logs from the shelf renderer and tool. They were Phase 2
verification scaffolding — no longer needed now that everything works.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
7bd34e5ff0
commit
166e860bfe
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useLiveTransforms, useRegistry } from '@pascal-app/core'
|
||||
import { useNodeEvents } from '@pascal-app/viewer'
|
||||
import { useEffect, useMemo, useRef } from 'react'
|
||||
import { useMemo, useRef } from 'react'
|
||||
import { Color, type Group } from 'three'
|
||||
import type { ShelfNode } from './schema'
|
||||
|
||||
@@ -40,11 +40,6 @@ const ShelfRenderer = ({ node }: { node: ShelfNode }) => {
|
||||
: Math.max(0.02, node.depth * 0.12)
|
||||
const bracketDepth = node.bracketStyle === 'industrial' ? node.depth * 0.95 : node.depth * 0.7
|
||||
|
||||
useEffect(() => {
|
||||
// biome-ignore lint/suspicious/noConsole: dev-only verification log
|
||||
console.info('[shelf] rendered', node.id, 'at', node.position)
|
||||
}, [node.id, node.position])
|
||||
|
||||
return (
|
||||
<group
|
||||
position={liveTransform?.position ?? node.position}
|
||||
|
||||
@@ -75,8 +75,6 @@ const ShelfTool = () => {
|
||||
useScene.getState().createNode(shelf, activeLevelId)
|
||||
useViewer.getState().setSelection({ selectedIds: [shelf.id] })
|
||||
triggerSFX('sfx:structure-build')
|
||||
// biome-ignore lint/suspicious/noConsole: dev-only verification log
|
||||
console.info('[shelf] placed', shelf.id, 'level-local', position, 'parent', activeLevelId)
|
||||
}
|
||||
|
||||
emitter.on('grid:move', onGridMove)
|
||||
|
||||
Reference in New Issue
Block a user