Skip to content

Commit 87ccd15

Browse files
authored
Merge pull request #2162 from Contraboi/bugfix/dexie-not-found-react-hooks
fix: 'Dexie' Not Found in Production with Vite/Vinxi dexie-react-hooks
2 parents 8f63a21 + 46a3419 commit 87ccd15

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

libs/dexie-react-hooks/src/useDocument.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { DexieYProvider, YjsDoc } from 'dexie';
1+
import * as Dexie from 'dexie';
22
import React from 'react';
33

44
const gracePeriod = 100 // 100 ms = grace period to optimize for unload/reload scenarios
55

6-
const fr = typeof FinalizationRegistry !== 'undefined' && new FinalizationRegistry((doc: YjsDoc) => {
6+
const fr = typeof FinalizationRegistry !== 'undefined' && new FinalizationRegistry((doc: Dexie.YjsDoc) => {
77
// If coming here, react effect never ran. This is a fallback cleanup mechanism.
8-
DexieYProvider.release(doc);
8+
Dexie.DexieYProvider.release(doc);
99
});
1010

11-
export function useDocument<YDoc extends YjsDoc>(
11+
export function useDocument<YDoc extends Dexie.YjsDoc>(
1212
doc: YDoc | null | undefined
13-
): DexieYProvider<YDoc> | null {
13+
): Dexie.DexieYProvider<YDoc> | null {
1414
if (!fr) throw new TypeError('FinalizationRegistry not supported.');
15-
const providerRef = React.useRef<DexieYProvider | null>(null);
15+
const providerRef = React.useRef<Dexie.DexieYProvider | null>(null);
1616
let unregisterToken: object | undefined = undefined;
1717
if (doc) {
1818
if (doc !== providerRef.current?.doc) {
19-
providerRef.current = DexieYProvider.load(doc, { gracePeriod });
19+
providerRef.current = Dexie.DexieYProvider.load(doc, { gracePeriod });
2020
unregisterToken = Object.create(null);
2121
fr.register(providerRef, doc, unregisterToken);
2222
}
@@ -34,10 +34,10 @@ export function useDocument<YDoc extends YjsDoc>(
3434
// We cannot wait with loading the document until the effect happens, because the doc
3535
// could have been destroyed in the meantime.
3636
if (unregisterToken) fr.unregister(unregisterToken);
37-
let provider = DexieYProvider.for(doc);
37+
let provider = Dexie.DexieYProvider.for(doc);
3838
if (provider) {
3939
return () => {
40-
DexieYProvider.release(doc);
40+
Dexie.DexieYProvider.release(doc);
4141
}
4242
} else {
4343
// Maybe the doc was destroyed in the meantime.

libs/dexie-react-hooks/src/usePermissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dexie } from 'dexie';
1+
import Dexie from 'dexie';
22
import { useObservable } from './useObservable';
33
//import type { KeyPaths, TableProp } from 'dexie'; // Issue #1725 - not compatible with dexie@3.
44
// Workaround: provide these types inline for now. When dexie 4 stable is out, we can use the types from dexie@4.

0 commit comments

Comments
 (0)