Skip to content

Commit

Permalink
Remove Safari workaround (bug has been fixed for over a year)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Jun 20, 2022
1 parent 494ee77 commit 1c01e45
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

This is a super-simple promise-based keyval store implemented with IndexedDB, originally based on [async-storage by Mozilla](https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js).

It's small and tree-shakeable. If you only use get/set, the library is ~370 bytes (brotli'd), if you use all methods it's ~650 bytes.

Although this is tiny, it's a little larger than previous versions due to a [massive bug in Safari](https://bugs.webkit.org/show_bug.cgi?id=226547). Hopefully this fix can be removed in the not-too-distant future, when a version of Safari without the bug reaches enough users.
It's small and tree-shakeable. If you only use get/set, the library is ~250 bytes (brotli'd), if you use all methods it's ~534 bytes.

[localForage](https://github.com/localForage/localForage) offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's orders of magnitude bigger (~7k).

Expand Down
3 changes: 0 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default async function ({ watch }) {
{
input: 'src/index.ts',
plugins: [simpleTS('src'), commonjs(), resolve()],
external: ['safari-14-idb-fix'],
output: [
{
file: 'dist/index.js',
Expand All @@ -103,7 +102,6 @@ export default async function ({ watch }) {
{
input: 'src/index.ts',
external: (id) => {
if (id === 'safari-14-idb-fix') return true;
if (id.startsWith('@babel/runtime')) return true;
},
plugins: [simpleTS('src', { noBuild: true }), commonjs(), resolve()],
Expand All @@ -118,7 +116,6 @@ export default async function ({ watch }) {
{
input: 'src/index.ts',
external: (id) => {
if (id === 'safari-14-idb-fix') return true;
if (id.startsWith('@babel/runtime')) return true;
},
plugins: [simpleTS('src', { noBuild: true }), commonjs(), resolve()],
Expand Down
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import safariFix from 'safari-14-idb-fix';

export function promisifyRequest<T = undefined>(
request: IDBRequest<T> | IDBTransaction,
): Promise<T> {
Expand All @@ -12,11 +10,9 @@ export function promisifyRequest<T = undefined>(
}

export function createStore(dbName: string, storeName: string): UseStore {
const dbp = safariFix().then(() => {
const request = indexedDB.open(dbName);
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
return promisifyRequest(request);
});
const request = indexedDB.open(dbName);
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
const dbp = promisifyRequest(request);

return (txMode, callback) =>
dbp.then((db) =>
Expand Down

0 comments on commit 1c01e45

Please sign in to comment.