-
Notifications
You must be signed in to change notification settings - Fork 1.2k
React Native bundle #114
React Native bundle #114
Conversation
package.json
Outdated
@@ -37,6 +37,7 @@ | |||
"install-peers-cli": "^2.2.0", | |||
"jest-cli": "^26.0.1", | |||
"prettier": "^2.0.5", | |||
"react-native": "^0.62.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added RN as a dev dependency. I'm not actually sure what the right approach is here, because react-dom
and react-native
are optional dependencies (one of them is required).
A good approach might be to remove react-dom
from the peer deps, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work fine to make react-dom
as a devDependency for the test runner and leave out react-native
entirely
src/npm/index.js
Outdated
@@ -1,7 +1,7 @@ | |||
'use strict'; | |||
|
|||
if (process.env.NODE_ENV === 'production') { | |||
module.exports = require('./recoil.production.js'); | |||
module.exports = require('./recoil.production'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the explicit extension so that the React Native bundler (Metro) imports recoil.{mode}.native.js
. If this is too terse, we can add an index.native.js
entry file and a react-native
key to the package.json.
src/Recoil.js
Outdated
@@ -76,4 +80,5 @@ module.exports = { | |||
|
|||
// Other functions | |||
isRecoilValue, | |||
setBatch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library user can call setBatch
and pass a batching function exported by whatever React renderer they use. Due to the current setup (the lack of an alternate-renderers
entrypoint), they'll still need react-dom
as a dependency.
src/Recoil.js
Outdated
@@ -29,6 +29,10 @@ export type { | |||
RecoilValueReadOnly, | |||
} from './core/Recoil_RecoilValue'; | |||
|
|||
const {unstable_batchedUpdates} = require('./util/ReactBatchedUpdates'); | |||
const {setBatch} = require('./util/Recoil_batch'); | |||
setBatch(unstable_batchedUpdates); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that this is exported; future-proofs the library a bit. We should probably add a test for this once they are passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
src/Recoil.js
Outdated
@@ -29,6 +29,10 @@ export type { | |||
RecoilValueReadOnly, | |||
} from './core/Recoil_RecoilValue'; | |||
|
|||
const {unstable_batchedUpdates} = require('./util/ReactBatchedUpdates'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that this module will be resolved differently depending on the build, thus giving us a different default and not requiring setBatch to be called on either platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. You'll either get unstable_batchedUpdates
from React DOM or from React Native here depending on the platform. Then we pass that platform-specific batching function to setBatch
.
I'd love it if someone with experience in this area could weigh in on whether this or #108 is better long-term. What I want:
|
Will this or approch #108 also work with Expo on iOS and Android? Because there is no .native.js in Expo even though it is react-native. |
It will, @hirbod. Expo uses the same bundler as a bare React Native app, so will also resolve the |
Hey @davidmccabe. Both approaches are very similar. The difference with this one is that you can, as a library user, set the batching function to anything you want. So custom renderers are supported here: import {setBatch} from 'recoil'
import {unstable_batchedUpdates} from 'react-test-renderer'
setBatch(unstable_batchedUpdates) To answer your specific questions:
|
@hirbod - there is a .native.js extension in Expo, it uses the same platform extensions as bare React Native but also adds .expo.js to that, as @jacques-blom pointed out :) |
Is there any reason this hasn't seen a merge? |
Howdy @davidmccabe. Mind having a look at my reply above when you have a chance, please? It'd be great to get RN support merged in soon. Let me know if there is anything else I can do to help move this along. |
(or if you're able to, @drarmstr) 🙂 |
I also applied the change fixing the react-dom reference, as noted by @mondaychen. Everything seems to be working for me, I haven’t merged the latest changes here yet, but I can try. My react-native test is on an out of tree platform so it’s a little different than testing against mobile. |
Thanks @mondaychen. I didn't hit the The problem was that I didn't do a new publish of my package after I fixed this.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mondaychen has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Thanks so much for putting in all the work on this! Is there a way to tell when module replacement is occurring on React Native? That would allow us to suppress the duplicate key error message. |
@davidmccabe this might be related: redux-saga/redux-saga#1961 looks like redux-saga had the same issue |
Redux Saga seemed to have issues with sagas being registered multiple times, but I haven't experienced any issues related to Fast Refresh on RN, so a check should be good enough. The only downside to this, as far as I understand it, is the user won't see the warning if they have Fast Refresh enabled and there are actually two atoms with the same key. What do you think, @davidmccabe? Also, I couldn't find a way to check whether or not Fast Refresh is enabled. Do you think you could reach out to the RN from your side? Or perhaps someone else in the thread has some context on this. Unfortunately |
So I'm merging this, with a few changes I made on internal tool
Let's keep looking for an elegant solution for the duplicated atom key issue triggered by hot reload. |
Would someone here be able to help with a regression test for React Native so it doesn't accidentally break in a future release? |
@mondaychen merged this pull request in 3b1bbc1. |
Thanks so much for everyone's contributions to this! It's super awesome that we got it merged. @drarmstr, I'll have another go at a regression test. 👍 What is the release process for Recoil, @mondaychen? Will this be manually released with other changes? And do you know roughly when the release will happen? Thanks. |
@jacques-blom thank you for working on this! It's a big step for Recoil. |
@mondaychen any chance we could get a "next" release on npm? Running nightlies maybe? |
@haswalt Good idea. I'll talk to team and keep you guys posted. |
Hi everyone! FYI we've published a "nightly build" branch for testing purposes. If you want to try out recoil with react native before we release next version, try install the
Or
|
@mondaychen hey, thank you for your work. |
Thank you for your wonderful work |
Have been using the 'recoil-react-native: 0.0.8-patch1" for development. It seems that the repo has been discarded maybe. Can we safely port to the nightly update or will there be any breaking changes? |
We've been using nightly for development on ReactNative for a little while now and haven't experienced any issues. |
@haswalt Have you used the library https://www.npmjs.com/package/recoil-react-native |
@krakzk no beacuse that package is really old, none official and there is ReactNative support built into Recoil |
@mondaychen which package are you talking about? |
@thegauravthakur The recoil official package instead of any others. Add in package as "recoil" : "0.1.2" |
Summary: Fixes facebookexperimental/Recoil#99 **Additions:** - Add the ability to set/get a batch function, which defaults to `ReactBatchedUpdates`. - Add `ReactBatchedUpdates` files for Web and Native that are imported to set the batch function to the renderer-specific function. - Add a `native` target to Rollup, which resolves `ReactBatchedUpdates`. **Result:** This gives us out of the box support for React DOM and React Native, with the library user not needing to make any changes. **Notes:** I haven't changed the use of `unstable_batchedUpdates` in the tests. (In fact I haven't been able to get the suite to pass on `master`, which I'll have another go at later, and file an issue if I'm still stuck.) But it'd be great if the maintainers or anyone with more contexts on the tests could weigh in here. It seems like we should use `unstable_batchedUpdates` from `react-test-renderer` here. In future, we could add a separate entry point (e.g. `'recoil/alternate-renderers'`) that doesn't set a batch function and doesn't depend on `react-dom` or `react-native`. We should be able to do this really easily because the infrastructure for setting the batching function to anything is available (and already exported in this PR). **Prior art for this PR:** - React Redux: [Alternate renderers entry point](https://github.com/reduxjs/react-redux/blob/master/src/alternate-renderers.js) and [get/set batch functions](https://github.com/reduxjs/react-redux/blob/master/src/utils/batch.js) - dustinsoftware's [PR](facebookexperimental/Recoil#108) with a similar implementation {emoji:1f64c} Pull Request resolved: facebookexperimental/Recoil#114 Reviewed By: drarmstr, davidmccabe Differential Revision: D23733076 Pulled By: mondaychen fbshipit-source-id: 948d45dd43b6e9ebac86ed6dd8433f3a1207c799
Summary: Fixes facebookexperimental/Recoil#99 **Additions:** - Add the ability to set/get a batch function, which defaults to `ReactBatchedUpdates`. - Add `ReactBatchedUpdates` files for Web and Native that are imported to set the batch function to the renderer-specific function. - Add a `native` target to Rollup, which resolves `ReactBatchedUpdates`. **Result:** This gives us out of the box support for React DOM and React Native, with the library user not needing to make any changes. **Notes:** I haven't changed the use of `unstable_batchedUpdates` in the tests. (In fact I haven't been able to get the suite to pass on `master`, which I'll have another go at later, and file an issue if I'm still stuck.) But it'd be great if the maintainers or anyone with more contexts on the tests could weigh in here. It seems like we should use `unstable_batchedUpdates` from `react-test-renderer` here. In future, we could add a separate entry point (e.g. `'recoil/alternate-renderers'`) that doesn't set a batch function and doesn't depend on `react-dom` or `react-native`. We should be able to do this really easily because the infrastructure for setting the batching function to anything is available (and already exported in this PR). **Prior art for this PR:** - React Redux: [Alternate renderers entry point](https://github.com/reduxjs/react-redux/blob/master/src/alternate-renderers.js) and [get/set batch functions](https://github.com/reduxjs/react-redux/blob/master/src/utils/batch.js) - dustinsoftware's [PR](facebookexperimental/Recoil#108) with a similar implementation {emoji:1f64c} Pull Request resolved: facebookexperimental/Recoil#114 Reviewed By: drarmstr, davidmccabe Differential Revision: D23733076 Pulled By: mondaychen fbshipit-source-id: 948d45dd43b6e9ebac86ed6dd8433f3a1207c799
Summary: Fixes facebookexperimental/Recoil#99 **Additions:** - Add the ability to set/get a batch function, which defaults to `ReactBatchedUpdates`. - Add `ReactBatchedUpdates` files for Web and Native that are imported to set the batch function to the renderer-specific function. - Add a `native` target to Rollup, which resolves `ReactBatchedUpdates`. **Result:** This gives us out of the box support for React DOM and React Native, with the library user not needing to make any changes. **Notes:** I haven't changed the use of `unstable_batchedUpdates` in the tests. (In fact I haven't been able to get the suite to pass on `master`, which I'll have another go at later, and file an issue if I'm still stuck.) But it'd be great if the maintainers or anyone with more contexts on the tests could weigh in here. It seems like we should use `unstable_batchedUpdates` from `react-test-renderer` here. In future, we could add a separate entry point (e.g. `'recoil/alternate-renderers'`) that doesn't set a batch function and doesn't depend on `react-dom` or `react-native`. We should be able to do this really easily because the infrastructure for setting the batching function to anything is available (and already exported in this PR). **Prior art for this PR:** - React Redux: [Alternate renderers entry point](https://github.com/reduxjs/react-redux/blob/master/src/alternate-renderers.js) and [get/set batch functions](https://github.com/reduxjs/react-redux/blob/master/src/utils/batch.js) - dustinsoftware's [PR](facebookexperimental/Recoil#108) with a similar implementation {emoji:1f64c} Pull Request resolved: facebookexperimental/Recoil#114 Reviewed By: drarmstr, davidmccabe Differential Revision: D23733076 Pulled By: mondaychen fbshipit-source-id: 948d45dd43b6e9ebac86ed6dd8433f3a1207c799
Fixes #99
Additions:
ReactBatchedUpdates
.ReactBatchedUpdates
files for Web and Native that are imported to set the batch function to the renderer-specific function.native
target to Rollup, which resolvesReactBatchedUpdates
.Result:
This gives us out of the box support for React DOM and React Native, with the library user not needing to make any changes.
Notes:
I haven't changed the use of
unstable_batchedUpdates
in the tests. (In fact I haven't been able to get the suite to pass onmaster
, which I'll have another go at later, and file an issue if I'm still stuck.) But it'd be great if the maintainers or anyone with more contexts on the tests could weigh in here. It seems like we should useunstable_batchedUpdates
fromreact-test-renderer
here.In future, we could add a separate entry point (e.g.
'recoil/alternate-renderers'
) that doesn't set a batch function and doesn't depend onreact-dom
orreact-native
. We should be able to do this really easily because the infrastructure for setting the batching function to anything is available (and already exported in this PR).Prior art for this PR: