Skip to content

Conversation

@Shanzid01
Copy link

Serialize and deserialize key-value pairs before adding them into indexedDB. This prevents invalid values (like functions) from being added into indexedDB, and fixes Issue 6087.

You can test these changes live here [see code].

Serialize and deserialize key-value pairs before adding them into indexedDB. This prevents invalid values from being added into indexedDB, and fixes issue
firebase#6087
@changeset-bot
Copy link

changeset-bot bot commented Apr 22, 2022

⚠️ No Changeset found

Latest commit: 7f7e7bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@ehsannas ehsannas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @Shanzid01 . It's very much appreciated.

We'll need to take some time to understand the underlying issue and whether there's a way to address it without affecting all transactions.

try {
keyOrValue =
keyOrValue != null
? JSON.parse(JSON.stringify(keyOrValue))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mean we do this for every transaction we do. We need to think about implications (performance etc).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! You're correct, I'm concerned about the performance impact as well. And this definitely doesn't fix the underlying issue (functions being added into the indexedDB), it's only a band-aid for those who desperately need a solution.

The firebase team should definitely consider a better solution for the final patch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why a function is being written to indexed db or why it only happens to Vue, if you know the answers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't determine why functions were being added, and why that was happening only in Vue3. But I was able to see what functions/Objects were being added:
db-error-reason
The culprit here seems to be the document->fields->Proxy Object. Firestore is attempting to insert this Proxy object into the IndexedDB and that's causing the error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not added by our codebase (reference).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very likely. Would also explain why this is only happening on Vue3. Possibly in one of the shared libraries for reactivity. Will investigate more and see if I can find something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with Firestore db persistence on Vue3

4 participants