0xMiden / 0xMiden/wallet-adapter

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

未关闭
#83 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
2
派生
9
平均合并
25 分钟
30 天内合并 PR
1

描述

## 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

贡献指南

打开贡献指南

调研方向

The issue is in the wallet extension's content script or addToWindow.js that injects Dexie. First, locate where the extension loads Dexie 4.0.8 and registers it via Symbol.for("Dexie"). Check if the extension can upgrade to Dexie 4.4.2 or isolate its Dexie instance. Test by building the extension and loading a dApp that uses the SDK to see if the error persists.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
frontend, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。