From c016fe41e50ba1a2a16908d2820c27b291a96575 Mon Sep 17 00:00:00 2001 From: Samuel Stroschein <35429197+samuelstroschein@users.noreply.github.com> Date: Sat, 21 Dec 2024 14:50:30 -0500 Subject: [PATCH] improve: clears the OPFS in case the lix file can't be loaded. If the lix schema changed, loading existing lix'es breaks with no possibility for users to fix the situation. Auto clearing the OPFS ledas to the creation of a new lix file with the new schema. --- .changeset/calm-masks-argue.md | 7 +++++++ packages/lix-file-manager/src/state.ts | 23 +++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .changeset/calm-masks-argue.md diff --git a/.changeset/calm-masks-argue.md b/.changeset/calm-masks-argue.md new file mode 100644 index 0000000000..d281cd4da9 --- /dev/null +++ b/.changeset/calm-masks-argue.md @@ -0,0 +1,7 @@ +--- +"lix-file-manager": minor +--- + +improve: clears the OPFS in case the lix file can't be loaded. + +If the lix schema changed, loading existing lix'es breaks with no possibility for users to fix the situation. Auto clearing the OPFS ledas to the creation of a new lix file with the new schema. \ No newline at end of file diff --git a/packages/lix-file-manager/src/state.ts b/packages/lix-file-manager/src/state.ts index ab3d2b7b17..d47e6f13d0 100644 --- a/packages/lix-file-manager/src/state.ts +++ b/packages/lix-file-manager/src/state.ts @@ -109,10 +109,25 @@ export const lixAtom = atom(async (get) => { } } - const lix = await openLixInMemory({ - blob: lixBlob!, - providePlugins: [csvPlugin], - }); + let lix: Lix; + + try { + lix = await openLixInMemory({ + blob: lixBlob!, + providePlugins: [csvPlugin], + }); + } catch { + // https://linear.app/opral/issue/INBOX-199/fix-loading-lix-file-if-schema-changed + // CLEAR OPFS. The lix file is likely corrupted. + for await (const entry of rootHandle.values()) { + if (entry.kind === "file") { + await rootHandle.removeEntry(entry.name); + } + } + window.location.reload(); + // tricksing the TS typechecker. This will never be reached. + lix = {} as any; + } const lixId = await lix.db .selectFrom("key_value")