Skip to content

Commit 31642a7

Browse files
[Bugs] Expose scene data readiness separately from loading overlay (#1282)
* editor: expose scene data readiness separately from the loading overlay The loader's readiness fallback (#1281) can take [data-scene-loading] down while the editor's own scene load is still in flight, when the scene is read-only and autosave is paused, so specs and hosts that waited on the overlay had no signal for when edits are accepted. useSceneLoader now also reports the scene data state and mirrors it on <html data-scene-data="loading|ready|failed">, independent of the fallback; a host isLoading does not hold it. When the fallback has taken the loader down while data is still loading, the viewer area shows a small non-blocking status that editing is paused. * editor: drop scene data readiness as soon as a new onLoad arrives The render that receives a new onLoad still carried the previous load's flags, so data-scene-data stayed "ready" until the load effect re-rendered. Readiness is now tied to the onLoad the graph was loaded from, and the attribute is written in a layout effect. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 9dc41f5 commit 31642a7

10 files changed

Lines changed: 193 additions & 24 deletions

File tree

‎packages/editor/src/components/editor/index.tsx‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,26 @@ function PaintCursorLayer({
11891189
)
11901190
}
11911191

1192+
// The loader's fallback can take it down while the scene data is still
1193+
// loading; until then the scene is read-only, so say why edits are refused.
1194+
function SceneDataPendingNotice() {
1195+
const i18n = usePascalI18n()
1196+
return (
1197+
<div className="pointer-events-none absolute inset-x-0 top-3 z-40 flex justify-center">
1198+
<div
1199+
className="flex items-center gap-2 rounded-full border border-border bg-background/90 px-3 py-1.5 text-muted-foreground text-xs shadow-sm backdrop-blur-md"
1200+
role="status"
1201+
>
1202+
<span className="size-1.5 animate-pulse rounded-full bg-amber-500" />
1203+
{i18n._({
1204+
id: 'editor.sceneData.pending',
1205+
message: 'Still loading the project. Editing is paused until it finishes.',
1206+
})}
1207+
</div>
1208+
</div>
1209+
)
1210+
}
1211+
11921212
// ── Viewer canvas: memoized, subscribes to the view layout internally ──
11931213
// This prevents Editor from re-rendering when the layout changes.
11941214

@@ -1206,6 +1226,7 @@ const ViewerCanvas = memo(function ViewerCanvas({
12061226
onThumbnailCapture,
12071227
onViewerBreadcrumb,
12081228
presentationsReady,
1229+
sceneDataPending,
12091230
viewerSceneSlot,
12101231
floorplanSceneSlot,
12111232
disablePostFx = false,
@@ -1225,6 +1246,7 @@ const ViewerCanvas = memo(function ViewerCanvas({
12251246
onThumbnailCapture?: (blob: Blob, cameraData: SnapshotCameraData) => void
12261247
onViewerBreadcrumb?: ViewerBreadcrumbHandler
12271248
presentationsReady: boolean
1249+
sceneDataPending: boolean
12281250
viewerSceneSlot?: ReactNode
12291251
floorplanSceneSlot?: ReactNode
12301252
disablePostFx?: boolean
@@ -1323,6 +1345,7 @@ const ViewerCanvas = memo(function ViewerCanvas({
13231345
{/* `relative` so the floorplan compass (portaled here to stay visible in
13241346
every layout) can anchor to this container's bottom-left. */}
13251347
<div className="relative h-full" ref={setViewerAreaNode}>
1348+
{sceneDataPending ? <SceneDataPendingNotice /> : null}
13261349
<QuickMeasurementHud />
13271350
<DeleteConfirmationDialog />
13281351
<div
@@ -1618,6 +1641,9 @@ function EditorContent({
16181641

16191642
const [isSceneLoading, setIsSceneLoading] = useState(false)
16201643
const [hasLoadedInitialScene, setHasLoadedInitialScene] = useState(false)
1644+
// The `onLoad` the store's graph came from: a new one is pending from the
1645+
// render that receives it, before the load effect resets the flags above.
1646+
const [loadedFrom, setLoadedFrom] = useState<{ onLoad: typeof onLoad } | null>(null)
16211647
// A failed `onLoad` is shown as an error with a retry, never as an empty
16221648
// scene: an editor that renders the default scaffold after a failed load
16231649
// autosaves that scaffold over the real project.
@@ -1719,6 +1745,7 @@ function EditorContent({
17191745
// The store holds the loaded graph: autosave resumes now, not on a
17201746
// frame — a tab loaded while hidden never gets one.
17211747
completeSceneLoad()
1748+
setLoadedFrom({ onLoad })
17221749
// A new project gets its own opening camera frame.
17231750
useEditor.getState().setOpeningCameraSettled(false)
17241751
setIsViewerSceneReady(false)
@@ -1787,9 +1814,12 @@ function EditorContent({
17871814
setIsViewerSceneReady(ready)
17881815
}, [])
17891816

1790-
const isSceneDataLoading = isLoading || isSceneLoading || !hasLoadedInitialScene
1791-
const showLoader = useSceneLoader({
1792-
isSceneDataLoading,
1817+
const isEditorSceneLoading =
1818+
isSceneLoading || !hasLoadedInitialScene || loadedFrom === null || loadedFrom.onLoad !== onLoad
1819+
const isSceneDataLoading = isLoading || isEditorSceneLoading
1820+
const { showLoader, sceneData } = useSceneLoader({
1821+
isHostLoading: isLoading,
1822+
isSceneDataLoading: isEditorSceneLoading,
17931823
isViewerSceneReady,
17941824
hasLoadError: sceneLoadError != null,
17951825
loadKey: `${sceneLoadGeneration}:${sceneReadyKey}`,
@@ -1921,6 +1951,7 @@ function EditorContent({
19211951
onThumbnailCapture={onThumbnailCapture}
19221952
onViewerBreadcrumb={onViewerBreadcrumb}
19231953
presentationsReady={presentationsReady}
1954+
sceneDataPending={!showLoader && sceneData === 'loading'}
19241955
sceneReadyKey={sceneReadyKey}
19251956
showLoader={showLoader}
19261957
viewerSceneSlot={viewerSceneSlot}

‎packages/editor/src/hooks/use-scene-loader.test.tsx‎

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { afterEach, beforeEach, expect, spyOn, test } from 'bun:test'
22
import { act, create } from '@react-three/test-renderer'
3-
import { type SceneLoaderInput, useSceneLoader } from './use-scene-loader'
3+
import {
4+
SCENE_DATA_ATTRIBUTE,
5+
type SceneLoaderInput,
6+
type SceneLoaderState,
7+
useSceneLoader,
8+
} from './use-scene-loader'
49

510
const TIMEOUT_MS = 20
611
const originalWindow = globalThis.window
12+
const originalDocument = globalThis.document
13+
const rootAttributes = new Map<string, string>()
714
const actGlobal = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
815
const previousAct = actGlobal.IS_REACT_ACT_ENVIRONMENT
916
let renderer: Awaited<ReturnType<typeof create>> | undefined
@@ -12,13 +19,21 @@ let warn: ReturnType<typeof spyOn>
1219
beforeEach(() => {
1320
actGlobal.IS_REACT_ACT_ENVIRONMENT = true
1421
globalThis.window = globalThis as unknown as Window & typeof globalThis
22+
rootAttributes.clear()
23+
globalThis.document = {
24+
documentElement: {
25+
setAttribute: (name: string, value: string) => rootAttributes.set(name, value),
26+
removeAttribute: (name: string) => rootAttributes.delete(name),
27+
},
28+
} as unknown as Document
1529
warn = spyOn(console, 'warn').mockImplementation(() => {})
1630
})
1731

1832
afterEach(async () => {
1933
await renderer?.unmount()
2034
renderer = undefined
2135
globalThis.window = originalWindow
36+
globalThis.document = originalDocument
2237
actGlobal.IS_REACT_ACT_ENVIRONMENT = previousAct
2338
warn.mockRestore()
2439
})
@@ -29,9 +44,9 @@ const fallbackWarnings = () =>
2944
type Input = Omit<SceneLoaderInput, 'viewerReadyTimeoutMs' | 'dataLoadTimeoutMs'>
3045

3146
async function mount(input: Input) {
32-
const shown: boolean[] = []
47+
const states: SceneLoaderState[] = []
3348
function Host(props: Input) {
34-
shown.push(
49+
states.push(
3550
useSceneLoader({
3651
...props,
3752
viewerReadyTimeoutMs: TIMEOUT_MS,
@@ -42,7 +57,8 @@ async function mount(input: Input) {
4257
}
4358
renderer = await create(<Host {...input} />)
4459
return {
45-
showLoader: () => shown.at(-1),
60+
showLoader: () => states.at(-1)?.showLoader,
61+
sceneData: () => states.at(-1)?.sceneData,
4662
update: (next: Input) => renderer!.update(<Host {...next} />),
4763
}
4864
}
@@ -52,7 +68,10 @@ const elapse = (ms = TIMEOUT_MS * 3) =>
5268
await new Promise((resolve) => setTimeout(resolve, ms))
5369
})
5470

71+
const sceneDataAttribute = () => rootAttributes.get(SCENE_DATA_ATTRIBUTE)
72+
5573
const loading: Input = {
74+
isHostLoading: false,
5675
isSceneDataLoading: true,
5776
isViewerSceneReady: false,
5877
hasLoadError: false,
@@ -95,7 +114,7 @@ test('clears when isSceneLoading / hasLoadedInitialScene stay stuck', async () =
95114
})
96115

97116
test('clears when a host isLoading stays stuck after the scene loaded', async () => {
98-
const loader = await mount({ ...loaded, isSceneDataLoading: true, isViewerSceneReady: true })
117+
const loader = await mount({ ...loaded, isHostLoading: true, isViewerSceneReady: true })
99118
expect(loader.showLoader()).toBe(true)
100119
await elapse()
101120
expect(loader.showLoader()).toBe(false)
@@ -126,3 +145,47 @@ test('a load error keeps its surface up with no fallback', async () => {
126145
expect(loader.showLoader()).toBe(true)
127146
expect(fallbackWarnings()).toBe(0)
128147
})
148+
149+
test('scene data: loading, then ready once the load completes', async () => {
150+
const loader = await mount(loading)
151+
expect(sceneDataAttribute()).toBe('loading')
152+
153+
await loader.update(loaded)
154+
expect(sceneDataAttribute()).toBe('ready')
155+
await loader.update({ ...loaded, isViewerSceneReady: true })
156+
expect(loader.showLoader()).toBe(false)
157+
expect(sceneDataAttribute()).toBe('ready')
158+
159+
await renderer!.unmount()
160+
renderer = undefined
161+
expect(sceneDataAttribute()).toBeUndefined()
162+
})
163+
164+
test('scene data stays loading after the loader fallback, until the data arrives', async () => {
165+
const loader = await mount(loading)
166+
await elapse()
167+
expect(loader.showLoader()).toBe(false)
168+
expect(loader.sceneData()).toBe('loading')
169+
expect(sceneDataAttribute()).toBe('loading')
170+
171+
await loader.update({ ...loaded, isViewerSceneReady: true })
172+
expect(loader.sceneData()).toBe('ready')
173+
expect(sceneDataAttribute()).toBe('ready')
174+
})
175+
176+
test('a host isLoading does not hold the scene data state', async () => {
177+
const loader = await mount({ ...loaded, isHostLoading: true })
178+
expect(loader.showLoader()).toBe(true)
179+
expect(sceneDataAttribute()).toBe('ready')
180+
})
181+
182+
test('scene data: failed on a load error, loading again on retry', async () => {
183+
const loader = await mount(loading)
184+
await loader.update({ ...loading, hasLoadError: true })
185+
expect(sceneDataAttribute()).toBe('failed')
186+
187+
await loader.update({ ...loading, loadKey: '2:0' })
188+
expect(sceneDataAttribute()).toBe('loading')
189+
await loader.update({ ...loaded, loadKey: '2:1' })
190+
expect(sceneDataAttribute()).toBe('ready')
191+
})
Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
import { useEffect, useState } from 'react'
1+
import { useEffect, useLayoutEffect, useState } from 'react'
2+
3+
const useClientLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect
24

35
export const SCENE_READY_FALLBACK_MS = 8000
46
export const SCENE_DATA_FALLBACK_MS = 20_000
57

8+
/**
9+
* Set on `document.documentElement` while the editor is mounted. Unlike the
10+
* loader (`[data-scene-loading]`), which a fallback can take down early, this
11+
* tracks only the editor's own scene data load:
12+
* - `loading`: the load is in flight; the scene is read-only and autosave is paused.
13+
* - `ready`: the scene loaded; it is editable and autosave runs.
14+
* - `failed`: the load failed; the scene stays read-only until a retry loads it.
15+
*/
16+
export const SCENE_DATA_ATTRIBUTE = 'data-scene-data'
17+
18+
export type SceneDataState = 'loading' | 'ready' | 'failed'
19+
620
export interface SceneLoaderInput {
7-
/** Host `isLoading`, the editor's own load in flight, or no scene loaded yet. */
21+
/** The host's `isLoading`. */
22+
isHostLoading: boolean
23+
/** The editor's own load is in flight, or no scene has loaded yet. */
824
isSceneDataLoading: boolean
925
/** The viewer has reported the current scene built and rendered. */
1026
isViewerSceneReady: boolean
@@ -16,50 +32,73 @@ export interface SceneLoaderInput {
1632
dataLoadTimeoutMs?: number
1733
}
1834

35+
export interface SceneLoaderState {
36+
showLoader: boolean
37+
sceneData: SceneDataState
38+
}
39+
1940
/**
20-
* Whether the full-pane scene loader shows. It covers the panes and takes their
21-
* pointer events, so it must come down even when a readiness signal never
22-
* arrives: a fallback timer runs whenever the loader is up for anything but a
23-
* load error, and once it fires the loader stays down for that load — a viewer
24-
* that mounts late (its renderer resolving after the timeout under software
25-
* WebGL) reports "not ready" on mount, which must not put it back.
41+
* Whether the full-pane scene loader shows, and the state of the scene data
42+
* behind it. The loader covers the panes and takes their pointer events, so it
43+
* must come down even when a readiness signal never arrives: a fallback timer
44+
* runs whenever the loader is up for anything but a load error, and once it
45+
* fires the loader stays down for that load — a viewer that mounts late (its
46+
* renderer resolving after the timeout under software WebGL) reports "not
47+
* ready" on mount, which must not put it back. The scene data state is not
48+
* subject to that fallback.
2649
*/
2750
export function useSceneLoader({
51+
isHostLoading,
2852
isSceneDataLoading,
2953
isViewerSceneReady,
3054
hasLoadError,
3155
loadKey,
3256
viewerReadyTimeoutMs = SCENE_READY_FALLBACK_MS,
3357
dataLoadTimeoutMs = SCENE_DATA_FALLBACK_MS,
34-
}: SceneLoaderInput): boolean {
58+
}: SceneLoaderInput): SceneLoaderState {
3559
const [timedOutKey, setTimedOutKey] = useState<string | number | null>(null)
36-
const waiting = isSceneDataLoading || !isViewerSceneReady
60+
const isDataLoading = isHostLoading || isSceneDataLoading
61+
const waiting = isDataLoading || !isViewerSceneReady
3762
const timedOut = timedOutKey === loadKey
63+
const sceneData: SceneDataState = hasLoadError
64+
? 'failed'
65+
: isSceneDataLoading
66+
? 'loading'
67+
: 'ready'
3868

3969
useEffect(() => {
4070
if (!waiting || hasLoadError || timedOut) return
4171
const timer = window.setTimeout(
4272
() => {
4373
console.warn(
44-
isSceneDataLoading
74+
isDataLoading
4575
? '[editor] scene data loading timed out; showing editor shell anyway'
4676
: '[editor] viewer scene readiness timed out; showing editor shell anyway',
4777
{ loadKey },
4878
)
4979
setTimedOutKey(loadKey)
5080
},
51-
isSceneDataLoading ? dataLoadTimeoutMs : viewerReadyTimeoutMs,
81+
isDataLoading ? dataLoadTimeoutMs : viewerReadyTimeoutMs,
5282
)
5383
return () => window.clearTimeout(timer)
5484
}, [
5585
waiting,
5686
hasLoadError,
5787
timedOut,
58-
isSceneDataLoading,
88+
isDataLoading,
5989
loadKey,
6090
viewerReadyTimeoutMs,
6191
dataLoadTimeoutMs,
6292
])
6393

64-
return hasLoadError || (waiting && !timedOut)
94+
// Layout effects, so the attribute never lags the committed state by a paint.
95+
useClientLayoutEffect(() => {
96+
document.documentElement.setAttribute(SCENE_DATA_ATTRIBUTE, sceneData)
97+
}, [sceneData])
98+
useClientLayoutEffect(
99+
() => () => document.documentElement.removeAttribute(SCENE_DATA_ATTRIBUTE),
100+
[],
101+
)
102+
103+
return { showLoader: hasLoadError || (waiting && !timedOut), sceneData }
65104
}

‎packages/editor/src/i18n/locales/en-XA/messages.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎packages/editor/src/i18n/locales/en/messages.po‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5893,6 +5893,10 @@ msgstr "Walk-in closet"
58935893
msgid "editor.roomName.workshop"
58945894
msgstr "Workshop"
58955895

5896+
#: packages/editor/src/components/editor/index.tsx
5897+
msgid "editor.sceneData.pending"
5898+
msgstr "Still loading the project. Editing is paused until it finishes."
5899+
58965900
#: packages/editor/src/components/ui/sidebar/icon-rail.tsx
58975901
msgid "editor.sidebar.iconRail.settings"
58985902
msgstr "Settings"

‎packages/editor/src/i18n/locales/en/messages.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎packages/editor/src/i18n/locales/es/messages.po‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14653,6 +14653,14 @@ msgstr "Vestidor"
1465314653
msgid "editor.roomName.workshop"
1465414654
msgstr "Taller"
1465514655

14656+
# Source-Hash: 4323751093d4c560
14657+
# Review: required
14658+
# AI-Provider: claude-code
14659+
#: packages/editor/src/components/editor/index.tsx
14660+
#, fuzzy
14661+
msgid "editor.sceneData.pending"
14662+
msgstr "Todavía se está cargando el proyecto. La edición está en pausa hasta que termine."
14663+
1465614664
# Source-Hash: 83909f82446ee9c3
1465714665
# Review: required
1465814666
# AI-Provider: claude-code

‎packages/editor/src/i18n/locales/fr/messages.po‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14653,6 +14653,14 @@ msgstr "Dressing"
1465314653
msgid "editor.roomName.workshop"
1465414654
msgstr "Atelier"
1465514655

14656+
# Source-Hash: 4323751093d4c560
14657+
# Review: required
14658+
# AI-Provider: claude-code
14659+
#: packages/editor/src/components/editor/index.tsx
14660+
#, fuzzy
14661+
msgid "editor.sceneData.pending"
14662+
msgstr "Le projet est encore en cours de chargement. La modification est suspendue jusqu’à la fin."
14663+
1465614664
# Source-Hash: 83909f82446ee9c3
1465714665
# Review: required
1465814666
# AI-Provider: claude-code

‎packages/editor/src/i18n/locales/ja/messages.po‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14653,6 +14653,14 @@ msgstr "ウォークインクローゼット"
1465314653
msgid "editor.roomName.workshop"
1465414654
msgstr "作業場"
1465514655

14656+
# Source-Hash: 4323751093d4c560
14657+
# Review: required
14658+
# AI-Provider: claude-code
14659+
#: packages/editor/src/components/editor/index.tsx
14660+
#, fuzzy
14661+
msgid "editor.sceneData.pending"
14662+
msgstr "プロジェクトを読み込み中です。完了するまで編集は一時停止されます。"
14663+
1465614664
# Source-Hash: 83909f82446ee9c3
1465714665
# Review: required
1465814666
# AI-Provider: claude-code

0 commit comments

Comments
 (0)