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

[RFC] RN 0.18 Compatibility changes #95

Merged
merged 5 commits into from
Jan 5, 2016

Conversation

skevy
Copy link
Contributor

@skevy skevy commented Jan 3, 2016

This PR performs the necessary changes to fbjs to allow for better compatibility with React Native, post the facebook/react-native@6a838a4 commit.

TLDR; this PR does the following:

  1. Strips the @providesModule directives from the built, npm version of fbjs (courtesy of @zpao). This is no longer necessary after [RFC] Remove knowledge of fbjs from the packager react-native#5084 is merged.
  2. Switch to isomorphic-fetch, in order to avoid causing weird require issues that happen when the whatwg-fetch module is required on React Native (courtesy of @zpao). Also fixes the issues discussed in Switch to isomorphic-fetch #61, which is where this commit is from.
  3. Adds the React Native promise implementation as Promise.native.js. The .native suffix was added in facebook/react-native@6a838a4, and allows the RN packager to require a different file for a given module.
  4. Checks for existence of ErrorUtils before setting the fbjs version on global. This is needed as ErrorUtils on React Native is polyfilled with specific behavior.

Note: # 3 is most likely a temporary fix. After discussing with @spicyj, the desired result would be to eventually remove the packager complexity introduced in facebook/react-native@6a838a4. The reason I'm going for this approach at the moment is that it's only one module that needs this shimming in fbjs, and I think the value it brings, given the fact that this PR, along with the corresponding PR in react-native, allows for Relay to work OOTB, outweighs its small of amount of technical debt. It's very possible you all may disagree, and I'm happy to change the approach if we come up with a better solution. :)

return;
}

// Get the @providesModule piece of out the file and save that.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: out of

@yungsters
Copy link
Contributor

About to merge this, but wanted to double check. Have you tested this with the Relay examples from master to verify there aren't any regressions?

@skevy
Copy link
Contributor Author

skevy commented Jan 3, 2016

@yungsters I tested with my test Relay application...but let me test with the examples. I don't presume there will be any regressions, but I'll report back here in a bit.

@skevy
Copy link
Contributor Author

skevy commented Jan 3, 2016

Good news! It works! But, it brought to light test failures in Relay...fixed those in skevy/relay@b8fa29a

module.exports = global.fetch.bind(global);
} else {
module.exports = require('isomorphic-fetch');
}
Copy link
Member

Choose a reason for hiding this comment

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

I never got around to revisiting the feedback about this in #61. If it works then great but I just wanted to make sure it was all good. Sounds like combined with the providesModule bits it might have fixed the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works fine, both on web and native.

The RN packager actually still pulls in isomorphic fetch, unfortunately, because it doesn't know about conditional requires. But, there's no error like there was with whatwg-fetch.

@sophiebits
Copy link
Contributor

Note: Before merging this, we need a way to shim the 'warning' module, which we do internally at Facebook so that we can log the frequency of warnings in our dev environments. (YellowBox should probably go through the same codepath.)

@skevy
Copy link
Contributor Author

skevy commented Jan 4, 2016

@spicyj can you share how it's being shimmed now?

@sophiebits
Copy link
Contributor

The module is blacklisted and we have another file with @providesModule warning that takes its place. I also have a @providesModule fbjs/lib/warning which just exports require('warning') which is necessary because that's how React requires it. It's hacky now.

@skevy
Copy link
Contributor Author

skevy commented Jan 4, 2016

@spicyj So, in RN then (post merging facebook/react-native#5084), in the FB internal blacklist, couldn't you still do the same thing? Blacklist fbjs/lib/warning and then do a module with @providesModule fbjs/lib/warning? Or, blacklist Libraries/vendor/fbjs/warning and do a module with @providesModule warning

@sophiebits
Copy link
Contributor

Hm, maybe. It doesn't work if anyone in fbjs does a relative require of ./warning, but maybe that already doesn't work…

@skevy
Copy link
Contributor Author

skevy commented Jan 4, 2016

Yah, that's what I was thinking. I'm not sure if this PR or facebook/react-native#5084 actually change how you'd shim it -- besides making sure you guys are maintaining your own blacklist, which you already do anyway.

yungsters added a commit that referenced this pull request Jan 5, 2016
RN 0.18 Compatibility changes
@yungsters yungsters merged commit cb6c4cc into facebook:master Jan 5, 2016
@skevy
Copy link
Contributor Author

skevy commented Jan 5, 2016

Woo! Thanks @yungsters! You guys can close #61 and #84 now, as those were included here.

@boourns
Copy link

boourns commented Jan 5, 2016

🎉

ghost pushed a commit to facebook/relay that referenced this pull request Jan 28, 2016
Summary:
**This PR depends on an unreleased version of `fbjs`, so DO NOT MERGE.**

When merged along with facebook/react-native#5084, facebook/fbjs#95, and whatever PR fixes facebook/react-native#4062 (which I will update this issue with when I push it), this fixes #26.

The changes to Relay itself are super minor here:

1. Remove the reliance on ReactDOM. The only use of ReactDOM is `unstable_batchedupdates`. So to fix, I abstracted the reference to `unstable_batchedupdates` to it's own module, and then took advantage of the "react-native" `package.json` option, supported by the React Native packager, to load the correct version of this function given the execution context.
2. Removed `react-dom` from peerDependencies (but kept it in devDependencies, for use in tests), and also upgrade the `fbjs` dependency to a (yet unreleased) version that provides better compatibility with React Native.
Closes #713

Reviewed By: yungsters

Differential Revision: D2872129

fb-gh-sync-id: f6ba6d06cfdde8ad8cbb0c7cd9d645f44f65e437
ghost pushed a commit to facebook/react-native that referenced this pull request Feb 11, 2016
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes #5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: davidaurelio

fb-gh-sync-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
shipit-source-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
ghost pushed a commit to facebook/react-native that referenced this pull request Feb 11, 2016
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes #5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: javache

fb-gh-sync-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
shipit-source-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until facebook#95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes facebook#5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: davidaurelio

fb-gh-sync-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
shipit-source-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until facebook#95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes facebook#5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: javache

fb-gh-sync-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
shipit-source-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
cpojer pushed a commit to facebook/metro that referenced this pull request Jan 26, 2017
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes facebook/react-native#5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: davidaurelio

fb-gh-sync-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
shipit-source-id: fd257958ee2f8696eebe9048c1e7628c168bf4a2
cpojer pushed a commit to facebook/metro that referenced this pull request Jan 26, 2017
Summary:
As spicyj mentioned in commit 6a838a4, the ideal state of affairs when it comes to consuming `react` and `fbjs` from NPM is for the packager not to have knowledge of either package. This PR addresses the `fbjs` part of that, and relies on facebook/fbjs#95. **DO NOT MERGE** until #95 (or a variation) is in `fbjs` and is released to npm.

This PR does several things:

1. Adds stub modules within RN that expose `fbjs` modules to be required using Haste. After discussing a few ideas with spicyj, this seemed like a good option to keep internal FB devs happy (and not make them change the way they write JS), but allow for removing packager complexity and fit in better with the NPM ecosystem. Note -- it skips stubbing `fetch`, `ExecutionEnvironment`, and `ErrorUtils`, due to the fact that these need to have Native specific implementations, and there's no reason for those implementations to exist in `fbjs`.
2. Removes the modules that were previously being used in lieu of their `fbjs` eq
Closes facebook/react-native#5084

Reviewed By: bestander

Differential Revision: D2803288

Pulled By: javache

fb-gh-sync-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
shipit-source-id: 121ae811ce4cc30e6ea79246f85a1e4f65648ce1
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.

6 participants