Skip to content

Commit 16bb00e

Browse files
committed
fix: load snapshot files in parallel (#8145)
1 parent bffc294 commit 16bb00e

File tree

4 files changed

+85
-44
lines changed

4 files changed

+85
-44
lines changed

packages/frontend/core/src/components/affine/setting-modal/general-setting/editor/edgeless/docs/index.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,49 @@ export type DocName =
2727

2828
const docMap = new Map<DocName, Promise<Doc | undefined>>();
2929

30+
async function loadNote() {
31+
return (await import('./note.json')).default;
32+
}
33+
34+
async function loadPen() {
35+
return (await import('./pen.json')).default;
36+
}
37+
38+
async function loadShape() {
39+
return (await import('./shape.json')).default;
40+
}
41+
42+
async function loadFlow() {
43+
return (await import('./flow.json')).default;
44+
}
45+
46+
async function loadText() {
47+
return (await import('./text.json')).default;
48+
}
49+
50+
async function loadConnector() {
51+
return (await import('./connector.json')).default;
52+
}
53+
54+
async function loadMindmap() {
55+
return (await import('./mindmap.json')).default;
56+
}
57+
58+
const loaders = {
59+
note: loadNote,
60+
pen: loadPen,
61+
shape: loadShape,
62+
flow: loadFlow,
63+
text: loadText,
64+
connector: loadConnector,
65+
mindmap: loadMindmap,
66+
};
67+
3068
export async function getDocByName(name: DocName) {
31-
const rawData: Record<DocName, any> = {
32-
note: (await import('./note.json')).default,
33-
pen: (await import('./pen.json')).default,
34-
shape: (await import('./shape.json')).default,
35-
flow: (await import('./flow.json')).default,
36-
text: (await import('./text.json')).default,
37-
connector: (await import('./connector.json')).default,
38-
mindmap: (await import('./mindmap.json')).default,
39-
};
4069
if (docMap.get(name)) {
4170
return docMap.get(name);
4271
}
43-
const snapshot = rawData[name] as DocSnapshot;
72+
const snapshot = (await loaders[name]()) as DocSnapshot;
4473
const promiseDoc = initDocFromSnapshot(snapshot);
4574
docMap.set(name, promiseDoc);
4675
return promiseDoc;

packages/frontend/core/src/components/affine/setting-modal/general-setting/editor/edgeless/docs/shape.json

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"type": "page",
33
"meta": {
4-
"id": "H26C3mrHAO",
4+
"id": "UpLwaWKe8S9s8krsxi3A8",
55
"title": "BlockSuite Playground",
6-
"createDate": 1725457623442,
6+
"createDate": 1725435317986,
77
"tags": []
88
},
99
"blocks": {
1010
"type": "block",
11-
"id": "gMFM1yrveo",
11+
"id": "mUEhyeRfVdzFKHV3w897g",
1212
"flavour": "affine:page",
1313
"version": 2,
1414
"props": {
@@ -24,7 +24,7 @@
2424
"children": [
2525
{
2626
"type": "block",
27-
"id": "ICj50zYaZ-",
27+
"id": "oc5oq3DFWcqVjzyevWrx6",
2828
"flavour": "affine:surface",
2929
"version": 5,
3030
"props": {
@@ -49,7 +49,7 @@
4949
"strokeStyle": "solid",
5050
"strokeWidth": 2,
5151
"textResizing": 1,
52-
"xywh": "[-14.79056021743071,154.8369594850144,100.11936661988601,100.11932857954827]",
52+
"xywh": "[190.275413673033,378.1994245551321,100.11936661988601,100.11932857954827]",
5353
"type": "shape",
5454
"id": "e6t9tKz8Sy"
5555
},
@@ -73,7 +73,7 @@
7373
"strokeStyle": "solid",
7474
"strokeWidth": 2,
7575
"textResizing": 1,
76-
"xywh": "[145.85713815180185,171.45701762455542,131.14345570418993,66.87921230046624]",
76+
"xywh": "[717.3900484965246,378.29923435003775,100.25918467911882,99.76145851000166]",
7777
"type": "shape",
7878
"id": "F8qB_zDC5Q"
7979
},
@@ -97,7 +97,7 @@
9797
"strokeStyle": "solid",
9898
"strokeWidth": 2,
9999
"textResizing": 1,
100-
"xywh": "[337.5289256053383,154.8369594850144,105.1083470248982,101.65945505340866]",
100+
"xywh": "[364.3172984791928,376.3029173497159,105.1083470248982,104.78589902189475]",
101101
"type": "shape",
102102
"id": "mPR44JBpcd"
103103
},
@@ -121,7 +121,7 @@
121121
"strokeStyle": "solid",
122122
"strokeWidth": 2,
123123
"textResizing": 1,
124-
"xywh": "[503.16560437958293,165.36299989942228,99.95316838431143,80.60737422459296]",
124+
"xywh": "[543.3481636903648,382.77123494325747,99.95316838431143,93.33554571739376]",
125125
"type": "shape",
126126
"id": "cmtluc3FWR"
127127
},
@@ -145,7 +145,7 @@
145145
"strokeStyle": "solid",
146146
"strokeWidth": 2,
147147
"textResizing": 1,
148-
"xywh": "[663.6471045132407,172.22708086148566,131.14345570418993,66.87921230046624]",
148+
"xywh": "[16.1402039335359,378.4574848297732,100.2126915532233,99.60320803026627]",
149149
"type": "shape",
150150
"id": "knt_TKvACR"
151151
}
@@ -154,28 +154,21 @@
154154
"children": [
155155
{
156156
"type": "block",
157-
"id": "GuSXhkqpUl",
157+
"id": "NSlTmqVn2NsIJCDvzIoUF",
158158
"flavour": "affine:frame",
159159
"version": 1,
160160
"props": {
161161
"title": {
162162
"$blocksuite:internal:text$": true,
163163
"delta": [
164164
{
165-
"insert": "Frame 1"
165+
"insert": "Shapes"
166166
}
167167
]
168168
},
169169
"background": "--affine-palette-transparent",
170-
"xywh": "[-140.35546875000006,60.96746826171875,1079.28125,307.06640625]",
171-
"index": "a0",
172-
"childElementIds": {
173-
"e6t9tKz8Sy": true,
174-
"F8qB_zDC5Q": true,
175-
"mPR44JBpcd": true,
176-
"cmtluc3FWR": true,
177-
"knt_TKvACR": true
178-
}
170+
"xywh": "[-23.859796066464128,332.87664265400565,881.5090292421075,190.55181066780085]",
171+
"index": "a0"
179172
},
180173
"children": []
181174
}

packages/frontend/core/src/components/affine/setting-modal/general-setting/editor/edgeless/docs/text.json

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"type": "page",
33
"meta": {
4-
"id": "VKd9Ksg2BG",
4+
"id": "NJwLoscdk4",
55
"title": "BlockSuite Playground",
6-
"createDate": 1725454903728,
6+
"createDate": 1725610138401,
77
"tags": []
88
},
99
"blocks": {
1010
"type": "block",
11-
"id": "rhCCfuveZ8",
11+
"id": "W-A_1geJy3",
1212
"flavour": "affine:page",
1313
"version": 2,
1414
"props": {
@@ -24,7 +24,7 @@
2424
"children": [
2525
{
2626
"type": "block",
27-
"id": "1Gr7rOSQE0",
27+
"id": "KNi1ipoyX6",
2828
"flavour": "affine:surface",
2929
"version": 5,
3030
"props": {
@@ -33,25 +33,43 @@
3333
"children": [
3434
{
3535
"type": "block",
36-
"id": "wTA9OwLHan",
36+
"id": "bv-d4LA-Nr",
3737
"flavour": "affine:edgeless-text",
3838
"version": 1,
3939
"props": {
40-
"xywh": "[272.7708206176758,163.16667556762695,245.12498474121088,56]",
41-
"index": "a1",
40+
"xywh": "[18.221401559354234,201.98389611782602,800.6283921393511,489.15472412109375]",
41+
"index": "a0",
4242
"color": "--affine-palette-line-blue",
4343
"fontFamily": "blocksuite:surface:Inter",
4444
"fontStyle": "normal",
4545
"fontWeight": "400",
4646
"textAlign": "left",
47-
"scale": 1,
47+
"scale": 5.435052533564726,
4848
"rotate": 0,
4949
"hasMaxWidth": true
5050
},
5151
"children": [
5252
{
5353
"type": "block",
54-
"id": "ig8oN3BQrC",
54+
"id": "vkzwo90EHS",
55+
"flavour": "affine:paragraph",
56+
"version": 1,
57+
"props": {
58+
"type": "text",
59+
"text": {
60+
"$blocksuite:internal:text$": true,
61+
"delta": [
62+
{
63+
"insert": "To Shape,"
64+
}
65+
]
66+
}
67+
},
68+
"children": []
69+
},
70+
{
71+
"type": "block",
72+
"id": "0ugn1XiO-U",
5573
"flavour": "affine:paragraph",
5674
"version": 1,
5775
"props": {
@@ -60,7 +78,7 @@
6078
"$blocksuite:internal:text$": true,
6179
"delta": [
6280
{
63-
"insert": "To shape, Not to Adapt."
81+
"insert": "Not to Adopt."
6482
}
6583
]
6684
}
@@ -71,7 +89,7 @@
7189
},
7290
{
7391
"type": "block",
74-
"id": "d3qe5CuEDW",
92+
"id": "mkbmK_R1sC",
7593
"flavour": "affine:frame",
7694
"version": 1,
7795
"props": {
@@ -84,10 +102,10 @@
84102
]
85103
},
86104
"background": "--affine-palette-transparent",
87-
"xywh": "[207.38800048828125,138.71615600585938,328.28125,106.92578125]",
88-
"index": "a0",
105+
"xywh": "[-21.778598440645766,126.5612581783729,880.6283921393511,640]",
106+
"index": "a1",
89107
"childElementIds": {
90-
"wTA9OwLHan": true
108+
"bv-d4LA-Nr": true
91109
}
92110
},
93111
"children": []

packages/frontend/core/src/components/affine/setting-modal/general-setting/editor/edgeless/snapshot.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const EdgelessSnapshot = (props: Props) => {
9999
useEffect(() => {
100100
// eslint-disable-next-line @typescript-eslint/no-floating-promises
101101
renderEditor();
102+
return () => editorHostRef.current?.remove();
102103
}, [renderEditor]);
103104

104105
// observe editor settings change

0 commit comments

Comments
 (0)