Move the loading of assets to the TldrawEditorWithReadyStore so that all code paths load the assets. (#1561)
Move the preloading of assets to `TldrawEditorWithReadyStore` which makes it sure that all codepaths preload assets. Before that didn't happen for cases where we passed in an existing store - snapshots. ### Change Type - [x] `patch` — Bug Fix ### Release notes - Fix a problem where assets were not loading in some cases (snapshots).
This commit is contained in:
parent
34a880dcbd
commit
439a2ed3bc
1 changed files with 12 additions and 12 deletions
|
@ -175,12 +175,8 @@ function TldrawEditorWithOwnStore(
|
|||
|
||||
const TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({
|
||||
store,
|
||||
assetUrls,
|
||||
...rest
|
||||
}: Required<TldrawEditorProps & { store: TLStoreWithStatus }, 'shapes' | 'tools'>) {
|
||||
const assets = useDefaultEditorAssetsWithOverrides(assetUrls)
|
||||
const { done: preloadingComplete, error: preloadingError } = usePreloadAssets(assets)
|
||||
|
||||
switch (store.status) {
|
||||
case 'error': {
|
||||
// for error handling, we fall back to the default error boundary.
|
||||
|
@ -202,14 +198,6 @@ const TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({
|
|||
}
|
||||
}
|
||||
|
||||
if (preloadingError) {
|
||||
return <ErrorScreen>Could not load assets. Please refresh the page.</ErrorScreen>
|
||||
}
|
||||
|
||||
if (!preloadingComplete) {
|
||||
return <LoadingScreen>Loading assets...</LoadingScreen>
|
||||
}
|
||||
|
||||
return <TldrawEditorWithReadyStore {...rest} store={store.store} />
|
||||
})
|
||||
|
||||
|
@ -220,6 +208,7 @@ function TldrawEditorWithReadyStore({
|
|||
tools,
|
||||
shapes,
|
||||
autoFocus,
|
||||
assetUrls,
|
||||
}: Required<
|
||||
TldrawEditorProps & {
|
||||
store: TLStore
|
||||
|
@ -277,6 +266,17 @@ function TldrawEditorWithReadyStore({
|
|||
() => editor?.crashingError ?? null
|
||||
)
|
||||
|
||||
const assets = useDefaultEditorAssetsWithOverrides(assetUrls)
|
||||
const { done: preloadingComplete, error: preloadingError } = usePreloadAssets(assets)
|
||||
|
||||
if (preloadingError) {
|
||||
return <ErrorScreen>Could not load assets. Please refresh the page.</ErrorScreen>
|
||||
}
|
||||
|
||||
if (!preloadingComplete) {
|
||||
return <LoadingScreen>Loading assets...</LoadingScreen>
|
||||
}
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue