Skip to content

Commit b3a5596

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 fb4ae47 commit b3a5596

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

src/helpers/promise.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,7 @@ export function newScope (fn, props, a1, a2) {
677677
var globalEnv = globalPSD.env;
678678
psd.env = patchGlobalPromise ? {
679679
Promise: DexiePromise, // Changing window.Promise could be omitted for Chrome and Edge, where IDB+Promise plays well!
680-
PromiseProp: {value: DexiePromise, configurable: true, writable: true},
681-
all: DexiePromise.all,
682-
race: DexiePromise.race,
683-
allSettled: DexiePromise.allSettled,
684-
any: DexiePromise.any,
685-
resolve: DexiePromise.resolve,
686-
reject: DexiePromise.reject
680+
PromiseProp: {value: DexiePromise, configurable: true, writable: true}
687681
} : {};
688682
if (props) extend(psd, props);
689683

@@ -782,15 +776,6 @@ function switchToZone (targetZone, bEnteringZone) {
782776

783777
// 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.
784778
Object.defineProperty(_global, 'Promise', targetEnv.PromiseProp);
785-
786-
// Support Promise.all() etc to work indexedDB-safe also when people are including es6-promise as a module (they might
787-
// not be accessing global.Promise but a local reference to it)
788-
GlobalPromise.all = targetEnv.all;
789-
GlobalPromise.race = targetEnv.race;
790-
GlobalPromise.resolve = targetEnv.resolve;
791-
GlobalPromise.reject = targetEnv.reject;
792-
if (targetEnv.allSettled) GlobalPromise.allSettled = targetEnv.allSettled;
793-
if (targetEnv.any) GlobalPromise.any = targetEnv.any;
794779
}
795780
}
796781
}
@@ -799,13 +784,7 @@ function snapShot () {
799784
var GlobalPromise = _global.Promise;
800785
return patchGlobalPromise ? {
801786
Promise: GlobalPromise,
802-
PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise"),
803-
all: GlobalPromise.all,
804-
race: GlobalPromise.race,
805-
allSettled: GlobalPromise.allSettled,
806-
any: GlobalPromise.any,
807-
resolve: GlobalPromise.resolve,
808-
reject: GlobalPromise.reject
787+
PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise")
809788
} : {};
810789
}
811790

0 commit comments

Comments
 (0)