Skip to content

Commit 90fcc6f

Browse files
committed
Don't patch Promise.all, Promise.race, etc.
This commit fails for 2 tests representing apps that imports Promise from a promise polyfill instead of just using the global Promise. Many apps and libs are still importing Promise from a polyfill to make them work on IE11. If these apps are doing Promise.resolve() or similar using the imported Promise constructor, we will not be able to track the ongoing transaction or liveQuery context if this commit is released. Those apps will need to drag down the promise polyfill in a plain script tag instead of importing from the polyfill. The webpacked code must use the global Promise and not an imported one at any time within Dexie transactions and liveQuery querier functions. This commit should be released in a new major version of Dexie with clear instrutions of how to migrate Promise polyfill dependent code. We could also make an intermediate fix that is backward compliant but warns in console if they are using import polyfill-pattern (not part of this commit). The upsides with this commit are: * Optimization: We only switch self.Promise between zones. * Simplicity: Less code * Unobtrusiveness
1 parent a6554c9 commit 90fcc6f

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

src/helpers/promise.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,7 @@ export function newScope (fn, props, a1, a2) {
656656
var globalEnv = globalPSD.env;
657657
psd.env = patchGlobalPromise ? {
658658
Promise: DexiePromise, // Changing window.Promise could be omitted for Chrome and Edge, where IDB+Promise plays well!
659-
PromiseProp: {value: DexiePromise, configurable: true, writable: true},
660-
all: DexiePromise.all,
661-
race: DexiePromise.race,
662-
allSettled: DexiePromise.allSettled,
663-
any: DexiePromise.any,
664-
resolve: DexiePromise.resolve,
665-
reject: DexiePromise.reject,
659+
PromiseProp: {value: DexiePromise, configurable: true, writable: true}
666660
} : {};
667661
if (props) extend(psd, props);
668662

@@ -762,15 +756,6 @@ function switchToZone (targetZone, bEnteringZone) {
762756

763757
// Set this Promise to window.Promise so that transiled async functions will work on Firefox, Safari and IE, as well as with Zonejs and angular.
764758
Object.defineProperty(_global, 'Promise', targetEnv.PromiseProp);
765-
766-
// Support Promise.all() etc to work indexedDB-safe also when people are including es6-promise as a module (they might
767-
// not be accessing global.Promise but a local reference to it)
768-
GlobalPromise.all = targetEnv.all;
769-
GlobalPromise.race = targetEnv.race;
770-
GlobalPromise.resolve = targetEnv.resolve;
771-
GlobalPromise.reject = targetEnv.reject;
772-
if (targetEnv.allSettled) GlobalPromise.allSettled = targetEnv.allSettled;
773-
if (targetEnv.any) GlobalPromise.any = targetEnv.any;
774759
}
775760
}
776761
}
@@ -779,13 +764,7 @@ function snapShot () {
779764
var GlobalPromise = _global.Promise;
780765
return patchGlobalPromise ? {
781766
Promise: GlobalPromise,
782-
PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise"),
783-
all: GlobalPromise.all,
784-
race: GlobalPromise.race,
785-
allSettled: GlobalPromise.allSettled,
786-
any: GlobalPromise.any,
787-
resolve: GlobalPromise.resolve,
788-
reject: GlobalPromise.reject,
767+
PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise")
789768
} : {};
790769
}
791770

0 commit comments

Comments
 (0)