Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: clears the OPFS in case the lix file can't be loaded. #3296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/calm-masks-argue.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 19 additions & 4 deletions packages/lix-file-manager/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading