0xMiden / 0xMiden/wallet-adapter

Wallet extension injects Dexie 4.0.8 into page scope, conflicting with SDK's Dexie 4.4.2

Ouverte
#83 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
2
Forks
9
Merge moyen
25 min
PR mergées (30 j)
1

Description

## Description

The MidenFi wallet extension registers Dexie 4.0.8 into the page's global scope via `Symbol.for("Dexie")`. When a dApp loads `@miden-sdk/miden-sdk@0.14.8+`, which bundles Dexie 4.4.2, the Dexie library detects the version mismatch and throws:

```
Error: Two different versions of Dexie loaded in the same app: 4.4.2 and 4.0.8
at Cargo-C35FdGuj.js:6588
```

This completely crashes React rendering — the root element stays empty and the app never loads.

## Root Cause

Dexie uses `Symbol.for("Dexie")` as a cross-realm global to detect duplicate loading:

```js
const DexieSymbol = Symbol.for("Dexie");
const Dexie = globalThis[DexieSymbol] || (globalThis[DexieSymbol] = _Dexie);
if (_Dexie.semVer !== Dexie.semVer) {
throw new Error(`Two different versions of Dexie loaded in the same app: ...`);
}
```

The wallet extension's content script (or injected page script via `addToWindow.js`) loads Dexie 4.0.8, which registers itself on the symbol. When the SDK's bundled Dexie 4.4.2 loads, it finds the 4.0.8 instance and throws.

## Environment

- `@miden-sdk/miden-sdk`: 0.14.8
- MidenFi wallet extension: latest (Chrome, extension ID `ablmompanofnodfdkgchkpmphailefpb`)
- Dexie in SDK bundle: 4.4.2
- Dexie from extension: 4.0.8

## Workaround

We use a Vite plugin that transforms the SDK's Dexie `throw` into a `console.warn` + global reassignment:

```ts
function dexieConflictSuppressor(): Plugin {
return {
name: "dexie-conflict-suppressor",
transform(code, id) {
if (!id.includes("@miden-sdk") && !id.includes("dexie")) return;
const pattern = 'throw new Error(`Two different versions of Dexie loaded';
if (!code.includes(pattern)) return;
return code.replace(
/throw new Error\(`Two different versions of Dexie loaded.*?\);/g,
'console.warn(`[Dexie] Version mismatch suppressed`); globalThis[Symbol.for("Dexie")] = _Dexie;',
);
},
};
}
```

## Suggested Fix

Either:
1. **Upgrade the extension's bundled Dexie** to match the SDK version (4.4.2+)
2. **Isolate the extension's Dexie** so it doesn't register on the page's `Symbol.for("Dexie")` — e.g., run IndexedDB operations in the extension's background script context rather than the page context
3. **Both the extension and SDK agree on a Dexie version** and keep them in sync

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.