Skip to content

Commit

Permalink
Bugfix/no structuredClone on react native (#5321)
Browse files Browse the repository at this point in the history
* FIX randomly failing test

* FIX `structuredClone` not available in ReactNative
  • Loading branch information
pubkey authored Nov 27, 2023
1 parent e0d00da commit 7486ce9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ examples/supabase/
examples/vite-vanilla-ts
node_modules
docs
docs-src/files/logo/js.build.js
docs-src/static/files/logo/js.build.js
docs-src/_book/
docs-src/build/
1 change: 1 addition & 0 deletions docs-src/docs/releases/15.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ In the past we used gitbook which is no longer maintained and had some major iss
- FIX PushModifier applied to pre-change legacy document, resulting in old document sent to endpoint [#5256](https://github.com/pubkey/rxdb/issues/5256)
- [Attachment compression](../rx-attachment.md#attachment-compression) is now using the native `Compression Streams API`.
- FIX [#5311](https://github.com/pubkey/rxdb/issues/5311) URL.createObjectURL is not a function in a browser plugin environment(background.js)
- FIX `structuredClone` not available in ReactNative [#5046](https://github.com/pubkey/rxdb/issues/5046#issuecomment-1827374498)
- The following things moved out of beta:
- [Firestore replication](../replication-firestore.md)
- [WebRTC replication](../replication-webrtc.md)
Expand Down
12 changes: 10 additions & 2 deletions src/rx-storage-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,23 @@ export function getWrappedStorageInstance<
* Ensure it can be structured cloned
*/
try {
structuredClone(writeRow);
/**
* Notice that structuredClone() is not available
* in ReactNative, so we test for JSON.stringify() instead
* @link https://github.com/pubkey/rxdb/issues/5046#issuecomment-1827374498
*/
if (typeof structuredClone === 'function') {
structuredClone(writeRow);
} else {
JSON.parse(JSON.stringify(writeRow));
}
} catch (err) {
throw newRxError('DOC24', {
collection: storageInstance.collectionName,
document: writeRow.document
});
}


/**
* Ensure that the new revision is higher
* then the previous one
Expand Down

0 comments on commit 7486ce9

Please sign in to comment.