dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.69k stars 641 forks source link

Simplify shimming #717

Open dfahlander opened 6 years ago

dfahlander commented 6 years ago

There was an issue in the early days named Just make it work on Safari issued by myself. This was a response to several Safari-related issues filed by Dexie users and resulted in a feature of Dexie 1.x, and a recommended way of including IndexedDBShim.

Seems we're there again. I haven't really realized how bad it has become until I finally tried to shim IndexedDB for various iOS versions (in response to the following stackoverflow question. Basically that question has resulted in the followin recommendation

Current Recommendation

Full recommendation in this stack overflow answer

Basically, that recommendation means:

  1. Include a script tag on your HTLM page with ~12 lines of JS code (don't webpack the shim in!)
  2. Include a script somewhere in your application code, that connects Dexie.dependencies with shimIndexedDB.

This recommendation (as of now), has some key features:

Future improvements

I would like to simplify for Dexie users even more by officially including a "shim.js" script in the npm package root that does what the script tag does + automagically incorporates the shim with Dexie in case browser is Safari 8 (shim cannot change indexedDB property on window on Safari 8).

Comments appreciated :)

StabbarN commented 6 years ago

How we use indexeddbshim v3 and dexie v1 bundled with webpack:

import Dexie from "dexie"
...
// in an init function for our app
require("indexeddbshim")
window.shimIndexedDB.__useShim()
const db = new Dexie("appName", {
    indexedDB: window.shimIndexedDB,
    IDBKeyRange: window.IDBKeyRange,
})

We use the shim in UIWebView on ios9 and ios10. We will soon migrate to Dexie v2 and then also skip indexeddbshim on ios10.1 - ios10.3. In our initial tests Dexie v2 seems to work on ios9 (despite https://github.com/axemclion/IndexedDBShim/issues/327). I upgraded an app from Dexie v1 to Dexie v2 without any loss of data.

dfahlander commented 6 years ago

From my own tests of the shim, version 3 does not work properly on Safari 8.x or 9.x. Need to use version 2 of IndexedDBShim until it has improved https://stackoverflow.com/questions/50808469/notfounderror-dom-idvdatabase-exception-8-while-using-dexie-on-ipad-working/50855488#50855488