@@ -115,9 +115,7 @@ function upgradePouchDbSchema(dbName, db, tx, pouchdbVersion) {
115115}
116116
117117function openDatabase ( openDatabases , api , opts , resolve , reject ) {
118- const openReq = opts . versionChangedWhileOpen ?
119- indexedDB . open ( opts . name ) :
120- indexedDB . open ( opts . name , createIdbVersion ( ) ) ;
118+ const openReq = indexedDB . open ( opts . name , createIdbVersion ( ) ) ;
121119
122120 openReq . onupgradeneeded = function ( e ) {
123121 if ( e . oldVersion > 0 && e . oldVersion < versionMultiplier ) {
@@ -185,23 +183,15 @@ function openDatabase(openDatabases, api, opts, resolve, reject) {
185183 idb . close ( ) ;
186184 } ;
187185
188- // In IndexedDB you can only change the version, and thus the schema, when you are opening the database.
189- // versionChangedWhileOpen means that something else outside of our control has likely updated the version.
190- // One way this could happen is if you open multiple tabs, as the version number changes each time the database is opened.
191- // If we suspect this we close the db and tag it, so that next time it's accessed it reopens the DB with the current version
192- // as opposed to upping the version again
193- // This avoids infinite loops of version updates if you have multiple tabs open
194186 idb . onversionchange = function ( ) {
195187 console . log ( 'Database was made stale, closing handle' ) ;
196- openDatabases [ opts . name ] . versionChangedWhileOpen = true ;
188+ delete openDatabases [ opts . name ] ;
197189 idb . close ( ) ;
198190 } ;
199191
200192 idb . onclose = function ( ) {
201193 console . log ( 'Database was made stale, closing handle' ) ;
202- if ( opts . name in openDatabases ) {
203- openDatabases [ opts . name ] . versionChangedWhileOpen = true ;
204- }
194+ delete openDatabases [ opts . name ] ;
205195 } ;
206196
207197 let metadata = { id : META_LOCAL_STORE } ;
@@ -257,10 +247,7 @@ function openDatabase(openDatabases, api, opts, resolve, reject) {
257247}
258248
259249export default function ( openDatabases , api , opts ) {
260- if ( ! openDatabases [ opts . name ] || openDatabases [ opts . name ] . versionChangedWhileOpen ) {
261- opts . versionChangedWhileOpen = openDatabases [ opts . name ] &&
262- openDatabases [ opts . name ] . versionChangedWhileOpen ;
263-
250+ if ( ! openDatabases [ opts . name ] ) {
264251 openDatabases [ opts . name ] = new Promise ( function ( resolve , reject ) {
265252 openDatabase ( openDatabases , api , opts , resolve , reject ) ;
266253 } ) ;
0 commit comments