fix(dexie-cloud): fix 'Illegal invocation' in blobResolveMiddleware cursor proxy - #2291
fix(dexie-cloud): fix 'Illegal invocation' in blobResolveMiddleware cursor proxy#2291liz709 wants to merge 1 commit into
Conversation
…esolveMiddleware Without explicit key/primaryKey property descriptors in Object.create(), accessing these properties on the wrapped cursor falls through the prototype chain to the native IDBCursorWithValue getters, which require `this` to be the actual native IDB cursor object. When `this` is a plain proxy object, the browser throws 'TypeError: Illegal invocation'. This crash occurs specifically on primary-key-index queries because the observability middleware (level 0) only wraps cursors on secondary indexes, leaving primary-key cursors unwrapped — so blobResolve's Object.create() wraps the native IDB cursor directly. Fix: add `key` and `primaryKey` getters that close over the original cursor reference, matching the pattern used by Dexie's own proxy-cursor helpers and the observability/virtual-index middlewares. Reported in: https://github.com/dexie/Dexie.js/issues/...
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Fixed and merged in #2293 (released in dexie-cloud-addon@4.4.10) |
Problem
createBlobResolvingCursor()inblobResolveMiddlewarewraps the IDB cursor viaObject.create(cursor, { value, start })but did not overridekeyorprimaryKey. Accessing these properties on the wrapped cursor falls through the prototype chain to the nativeIDBCursorWithValuegetters, which requirethisto be the actual native IDB cursor object. Sincethisis a plain proxy object, the browser throws:Why does this happen? The
observabilityMiddleware(level 0) only wraps cursors for secondary index queries — not primary key queries. For primary key queries, blobResolve (level 2) receives the cursor with no intermediatekey/primaryKeygetter override, so property lookup hits the native IDB getter directly.This is a regression triggered by the level change in #2268 (moving blobResolve above the cache). At level
-2(below observability), blobResolve always received cursors already wrapped by observability. At level2(above observability), blobResolve can receive unwrapped native IDB cursors on primary key paths.Fix
Add explicit
keyandprimaryKeygetters to theObject.create()property descriptor map. They close over the original cursor reference, matching the pattern used by Dexie's ownProxyCursorhelper and theobservabilityMiddleware/virtual-index-middleware:What's NOT changed
level: 2is intentionally kept (set in Fix blob resolve issues (change level to be above cache-middleware) + make sure to resume blob downloader through syncComplete event #2268 so cached blob refs get resolved — reverting it would break cache invalidation for blob values).valueorstarthandling.Testing
Build passes (
pnpm build), unit tests pass (npm testin dexie-cloud-common), CodeRabbit: no findings.Fixes: bug reported in Discord where app crashed on load with 'Illegal invocation' on dexie-cloud-addon 4.4.6–4.4.9 in Chrome on primary-key cursor queries.
Summary by CodeRabbit