Procházet zdrojové kódy

fixes migration bug?

main
Steve Ruiz před 3 roky
rodič
revize
25cd388ff3

+ 3
- 2
packages/tldraw/src/state/tlstate.ts Zobrazit soubor

@@ -103,7 +103,7 @@ export class TLDrawState extends StateManager<Data> {
103 103
     super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
104 104
       return {
105 105
         ...next,
106
-        document: { ...next.document, ...prev.document },
106
+        document: { ...next.document, ...prev.document, version: prev.document.version },
107 107
       }
108 108
     })
109 109
 
@@ -129,6 +129,7 @@ export class TLDrawState extends StateManager<Data> {
129 129
       })
130 130
     } catch (e) {
131 131
       console.error('The data appears to be corrupted. Resetting!', e)
132
+      localStorage.setItem(this.document.id + '_corrupted', JSON.stringify(this.document))
132 133
 
133 134
       this.patchState({
134 135
         ...TLDrawState.defaultState,
@@ -2457,7 +2458,7 @@ export class TLDrawState extends StateManager<Data> {
2457 2458
     }
2458 2459
   }
2459 2460
 
2460
-  static version = 12.5
2461
+  static version = 12.6
2461 2462
 
2462 2463
   static defaultDocument: TLDrawDocument = {
2463 2464
     id: 'doc',

+ 16
- 0
packages/tldraw/src/test/migration.spec.ts Zobrazit soubor

@@ -2,6 +2,7 @@
2 2
 import { TLDrawState } from '~state'
3 3
 import type { TLDrawDocument } from '~types'
4 4
 import oldDoc from './old-doc'
5
+import oldDoc2 from './old-doc-2'
5 6
 
6 7
 describe('When migrating bindings', () => {
7 8
   it('migrates', () => {
@@ -16,4 +17,19 @@ describe('When migrating bindings', () => {
16 17
 
17 18
     new TLDrawState().loadDocument(oldDoc as unknown as TLDrawDocument)
18 19
   })
20
+
21
+  it('migrates older document', () => {
22
+    // Object.values((oldDoc as unknown as TLDrawDocument).pages).forEach((page) => {
23
+    //   Object.values(page.bindings).forEach((binding) => {
24
+    //     if ('meta' in binding) {
25
+    //       // @ts-ignore
26
+    //       Object.assign(binding, binding.meta)
27
+    //     }
28
+    //   })
29
+    // })
30
+
31
+    const tlstate = new TLDrawState().loadDocument(oldDoc2 as unknown as TLDrawDocument)
32
+
33
+    expect(tlstate.getShape('d7ab0a49-3cb3-43ae-3d83-f5cf2f4a510a').style.color).toBe('black')
34
+  })
19 35
 })

+ 16758
- 0
packages/tldraw/src/test/old-doc-2.ts
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 1
- 1
packages/tldraw/tsconfig.json Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "extends": "../../tsconfig.base.json",
3
-  "include": ["src"],
3
+  "include": ["src", "src/test/*.json"],
4 4
   "exclude": ["node_modules", "dist", "docs"],
5 5
   "compilerOptions": {
6 6
     "resolveJsonModule": true,

Načítá se…
Zrušit
Uložit