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

Fixed MongoDBCollection#watch on React Native #4155

Merged
merged 7 commits into from Dec 17, 2021

Conversation

kraenhansen
Copy link
Member

@kraenhansen kraenhansen commented Dec 16, 2021

What, How & Why?

This closes #3494 by adding documentation on installing polyfills and a babel plugin, plus calling the React Native fetch polyfill with the right option.

If the user forgets to add the polyfill and calls watch()

TypeScript documentation as seen in VC Code

The JSDoc documentation

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 🚦 Tests (manually locally)
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated

@kraenhansen kraenhansen self-assigned this Dec 16, 2021
@cla-bot cla-bot bot added the cla: yes label Dec 16, 2021
@@ -6,7 +6,7 @@
"./header.eslintrc"
],
"env": {
"es2017": true
"es2020": true
Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed to be able to use the globalThis keyword and should be okay for the platforms we support.

@@ -63,6 +63,21 @@ export default [
nodeResolve(),
],
},
{
input: "src/react-native/index.ts",
Copy link
Member Author

Choose a reason for hiding this comment

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

We're adding a new "react-native" bundle to separate the code that runs on "react-native" from that which run on web.

// Setting this non-standard option to enable text streaming
// See https://github.com/react-native-community/fetch#enable-text-streaming
DefaultNetworkTransport.extraFetchOptions = {
reactNative: { textStreaming: true },
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Please add it as a comment

Copy link
Member Author

Choose a reason for hiding this comment

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

It's already there - two lines above the line I commented on here :)

@@ -69,6 +70,7 @@ export class DefaultNetworkTransport implements NetworkTransport {
try {
// We'll await the response to catch throw our own error
return await DefaultNetworkTransport.fetch(url, {
...DefaultNetworkTransport.extraFetchOptions,
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried setting this only on the streaming requests, but that yield the following in my test app:

 LOG  Running "ReactNativeTestApp" with {"rootTag":61,"initialProps":{}}
 WARN  Invalid responseType: blob
 ERROR  {"code": -1, "message": "undefined is not an object (evaluating 'options.blobId')"}
 WARN  Invalid responseType: blob
 LOG  Unable to symbolicate stack trace: undefined is not an object (evaluating 'options.blobId')
 WARN  Invalid responseType: blob
 WARN  Invalid responseType: blob
 WARN  Invalid responseType: blob

// Setting this non-standard option to enable text streaming
// See https://github.com/react-native-community/fetch#enable-text-streaming
DefaultNetworkTransport.extraFetchOptions = {
reactNative: { textStreaming: true },
Copy link
Member

Choose a reason for hiding this comment

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

Please add it as a comment

Copy link
Contributor

@takameyer takameyer left a comment

Choose a reason for hiding this comment

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

Awesome. Do we need to prominently document this somewhere, besides in the comments?

@kraenhansen
Copy link
Member Author

Awesome. Do we need to prominently document this somewhere, besides in the comments?

Besides the changes I'm proposing to the TypeScript docs and JSDoc, I would say the instructions on adding the babel plugin and globals polyfill needs to be inserted on https://docs.mongodb.com/realm/sdk/react-native/examples/query-mongodb/#real-time-change-notifications as well.

@kraenhansen kraenhansen merged commit 9459ffa into master Dec 17, 2021
@kraenhansen kraenhansen deleted the kh/react-native-watch-fixed branch December 17, 2021 07:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

collection.watch() fails on React Native SDK
3 participants