Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error with server side rendering #9

Closed
wants to merge 1 commit into from

Conversation

tlaverdure
Copy link

I'm using idb-keyval in a project that does server side rendering and this was causing some issues server side when this file was imported.

I'm using `idb-keyval` in a project that does server side rendering and this was causing some issues server side when this file was imported.
@jakearchibald
Copy link
Owner

idb-keyval only calls idbReady() when creating a store, right before calling indexedDB.open(dbName). Wouldn't that indexedDB.open call also cause issues server side?

@tlaverdure
Copy link
Author

Yes that actually would cause issues as well.

@jakearchibald
Copy link
Owner

I think the solution here is to guard calls like this so they won't run on the server. I usually have a global like __SERVER__ that's true if it's being run on the server.

@dfahlander
Copy link
Contributor

Hi! It is not uncommon to use fakeIndexedDB to run it on unit tests in plain node.js. Could be argued that the unit tests wouldn't need this workaround anyway, but if they are put into a database layer used from both unit tests and application code, that database layer need to check typeof navigator === 'undefined' before invoking the fix. Not a hard thing to do, but maybe cleaner having the check in the workaround itself.

BTW: Amazing how many details in need to take care of :O
Thanks for providing the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants