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

IndexedDB premium storage does not allow storing array properties #5046

Closed
leandrogehlen opened this issue Sep 28, 2023 · 9 comments
Closed

Comments

@leandrogehlen
Copy link
Contributor

leandrogehlen commented Sep 28, 2023

Using getRxStorageIndexedDB when the schema has array properties on insert/update a document the error bellow is raised:

indexeddb-storage-instance.js:1 Uncaught (in promise) DOMException: Failed to execute 'put' on 'IDBObjectStore': [object Array] could not be cloned. at l.bulkWrite (webpack-internal:///./node_modules/rxdb-premium/dist/es/plugins/storage-indexeddb/indexeddb-storage-instance.js:19:1349) at async RxCollectionBase.bulkInsert (webpack-internal:///./node_modules/rxdb/dist/es/rx-collection.js:180:19) at async RxCollectionBase.insert (webpack-internal:///./node_modules/rxdb/dist/es/rx-collection.js:145:23) at async onSaveClick (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js??clonedRuleSet-41.use[1]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/PageForm.vue?vue&type=script&setup=true&lang=ts:46:11)

Using getRxStorageDexie() works fine

Example repo:
https://github.com/leandrogehlen/ionic-vue-rxdb/tree/storage-indexeddb

@pubkey
Copy link
Owner

pubkey commented Sep 29, 2023

Related: localForage/localForage#610

You can only store plain JSON data in RxDB. RxDB does not json-parse because the performance would decrease.
I will add a dev-mode check to give a better error message.

@leandrogehlen
Copy link
Contributor Author

leandrogehlen commented Sep 30, 2023

I don't understand
The the object bellow is not considered a plain object?:

database.collections.contacts.insert({
  id:  'abacdef'
  name: 'Leandro',
  emails: [
    'leandrogehlen@gmail.com'
  ]
})

Following the reference Plain Objects the object above is a plain object.

@pubkey
Copy link
Owner

pubkey commented Sep 30, 2023

Can you make a PR with a test case?

@leandrogehlen
Copy link
Contributor Author

I found this test in the RxDB repository, and I believe that this test is not being executed using IndexedDB storage.

@pubkey
Copy link
Owner

pubkey commented Oct 1, 2023

Screenshot from 2023-10-01 19-47-42

@leandrogehlen
Copy link
Contributor Author

I found the problem.
I was using ref that makes a proxy object.
To solve it is necessary use toRaw before store the object in rxdb

pubkey added a commit that referenced this issue Oct 5, 2023
pubkey added a commit that referenced this issue Oct 5, 2023
pubkey added a commit that referenced this issue Oct 12, 2023
* CHANGE eventReduce: true by default

* FIX orga

* v15 storage interface optimizations (#5002)

* CHANGE bulkWrite return arrays instead of objects

* FIX tests

* IMPROVE performance

* IMPROVE performance

* OPTIMIZE performance of write row categorizing

* IMPROVE memory write performance

* FIX tests

* CHANGE string regex (#5000)

* CHANGE string regex

* FIX lint

* Feature/async hashing (#5013)

* CHANGE async hash function

* FIX tests

* CHANGE hash attachments in rxdb instead of the RxStorage

* FIX mongodb random test failures

* TRIGGER push

* CHANGE use webcrypto API for hashing

* FIX test

* FIX not dependend on specific hash function

* TRY fix

* FIX hashing in replication states

* FIX types

* FIX tests

* FIX tests

* FIX vue

* RENAME replication-p2p to replication-webrtc

* ADD docs page redirect

* FIX random failures

* CHANGE RxLocalDocument.$ must emit a document instance, not the plain data

* FIX tests

* TRY fix react native

* ADD dev-mode check for dissalowed $ref #4926 (#5019)

* RENAME send$ to sent$ (#5020)

* UPDATE faker

* ADD attachment replication (#5039)

* ADD attachment replication

* FIX tests

* FIX tests

* FIX typos

* FIX tests

* FIX tests

* FIX ensure meta instance does not contain attachments data

* ADD context to debug

* FIX types

* FIX randomly failing test

* ADD(docs) attachment replication

* ADD .info call (#5045)

* ADD .info call

* FIX types

* REFACTOR data migrator (#5025)

* REFACTOR data migrator

* FIX maxLength

* ADD stuff

* CHORE migration

* CHORE migration

* CHORE migration

* CHORE migration

* REMOVE old

* FIX close broadcast channel

* FIX flutter

* FIX closing of storages

* CHORE migration

* FIX tests

* FIX types

* FIX test

* ADD log

* FIX

* ADD log

* ADD log

* FIX mongo

* FIX

* FIX spelling

* FIX docs

* FIX

* REFACTOR bulkUpsert (#5057)

* REFACTOR bulkUpsert

* FIX docs

* FIX docs

* FIX version

* REMOVE obsolete setter code from RxDocument

* IMPROVE property access performance (#5063)

* IMPROVE property access performance

* FIX #4949 RxDocument.get() on additonalProperty

* IMPROVE performance

* IMPROVE performance

* FIX bun

* FIX image

* ADD helpfull error message for #5046 (#5068)

* FIX types

* clear cache

* FIX types

* FIX npm ignore

* REMOVE is-blob

* CHORE type module (#5074)

* CHORE type module

* CHORE

* CHORE

* FIX build

* FIX

* cHORE

* FIX typecheck

* CHORE

* CHORE

* FIX typing tests

* CHORE

* CHORE

* CHORE

* CHORE

* CHORE

* ADD stuff

* FIX typings test

* FIX lint

* REMOVE deps

* ADD deno test

* FIX

* FIX

* FIX imports

* FIX test

* FIX test

* FIX browser tests

* FIX loki test

* FIX testes

* FIX root import

* FIX newline

* FIX karma test

* FIX lint

* FIX

* FIX build

* FIX perf tests

* FIX test

* FIX stuff

* FIX deno tests

* FIX require

* FIX loki

* FIX

* FIX deno

* FIX landingpage build

* ADD side effects false

* FIX deno

* FIX async storage init

* FIX init

* FIX deno tests

* FIX deno tests

* FIX empty tests

* ADD deno performance tests

* FIX types

* FIX test

* FIX

* FIX tests

* FIX tests

* FIX ci

* FIX ci order

* FIX test

* FIX init

* FIX lint

* FIX deno tests

* REMOVE browserify output

* REMOVE browserify index

* FIX missing dep

* FIX bigint not defined

* FIX flutter
@lavaxun
Copy link

lavaxun commented Nov 27, 2023

Hi @pubkey.
Thought it might be easier to just report the issue in here than creating a new ticket.

The structuredClone in the latest release ("rxdb": "15.0.0-beta.33") seems not working for React Native.
I've added a console.log to the dev-mode plugin and it shows the following error message.
Screenshot 2023-11-27 at 16 39 05

currently we're using a quick workaround in the codebase. however this does not seem ideal. Hope to have a proper fix from the plugin itself.

if (process.env.NODE_ENV !== 'production') {
  if (!global.structuredClone) {
    global.structuredClone = function structuredClone(objectToClone: any) {
      const stringified = JSON.stringify(objectToClone);
      const parsed = JSON.parse(stringified);
      return parsed;
    };
  }
}

Further read:

@pubkey
Copy link
Owner

pubkey commented Nov 27, 2023

@lavaxun Thank you for reporting. I am working on a fix: #5321

@lavaxun
Copy link

lavaxun commented Nov 27, 2023

@lavaxun Thank you for reporting. I am working on a fix: #5321

thank you!

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

No branches or pull requests

3 participants