Summary:
This is a follow up of the work by brentvatne in #5052. This addresses the feedback by astreet.
- Uses ReactChoreographer with a new callback type
- Callback dispatch logic moved to JS
- Only calls into JS when needed, when there are pending callbacks, it even removes the Choreographer listener when no JS context listen for idle events.
** Test plan **
Tested by running a background task that burns all remaining idle time (see new UIExplorer example) and made sure that UI and JS fps stayed near 60 on a real device (Nexus 6) with dev mode disabled. Also tried adding a JS driven animation and it stayed smooth.
Tested that native only calls into JS when there are pending idle callbacks.
Also tested that timers are executed before idle callback.
```
requestIdleCallback(() => console.log(1));
setTimeout(() => console.log(2), 100);
burnCPU(1000);
// 2
// 1
```
I did *not* test with webworkers but it should work as I'm using executor tokens.
Closes https://github.com/facebook/react-native/pull/8569
Differential Revision: D3558869
Pulled By: astreet
fbshipit-source-id: 61fa82eb26001d2b8c2ea69c35bf3eb5ce5454ba
Summary:
Currently, DevTools only work under ios (although this is undocumented!),
because the JavaScriptEngine initialization process skips setupDevTools() on
android.
DevTools work fine with Android, as tested on 0.26, 0.27, and 0.28 using
Nuclide's inspector.
For reference, the relevant issue on react-devtools.
Closes https://github.com/facebook/react-native/pull/8095
Reviewed By: bestander
Differential Revision: D3492788
Pulled By: andreicoman11
fbshipit-source-id: 1eda9196d7125da19a8d7baaab22b61b744ca629
Summary:
Currently, DevTools only work under ios (although this is undocumented!), because the JavaScriptEngine initialization process skips setupDevTools() on android.
DevTools work fine with Android, as tested on 0.26, 0.27, and 0.28 using Nuclide's inspector.
For reference, [the relevant issue on react-devtools](https://github.com/facebook/react-devtools/issues/229).
Closes https://github.com/facebook/react-native/pull/8095
Reviewed By: javache
Differential Revision: D3443980
Pulled By: bestander
fbshipit-source-id: ce0f7dd62ae0f7dfe6654380821660f8660318a6
Summary:
Currently, DevTools only work under ios (although this is undocumented!), because the JavaScriptEngine initialization process skips setupDevTools() on android.
DevTools work fine with Android, as tested on 0.26, 0.27, and 0.28 using Nuclide's inspector.
For reference, [the relevant issue on react-devtools](https://github.com/facebook/react-devtools/issues/229).
Closes https://github.com/facebook/react-native/pull/8095
Reviewed By: javache
Differential Revision: D3443980
Pulled By: andreicoman11
fbshipit-source-id: 3d7b2e83cf4158a1228d2e21510509ab63411a5d
Summary:
Cleans up `InitializeJavaScriptAppEngine` in a few ways:
- Fix bug where `global.navigation.geolocation` was being assigned to `global`.
- Rename `polyfillGlobal` to `defineProperty`.
- Rename `polyfillLazyGlobal` to `defineLazyProperty`.
- Inline `polyfillIfNeeded` (only used once).
- Rename `setUpMapAndSet` to `setUpCollections`.
- Add `flow`.
I've changed `defineProperty` and `defineLazyProperty` to always accept an `object` property since it is not only used for defining properties on `global`.
Reviewed By: davidaurelio
Differential Revision: D3472147
fbshipit-source-id: 492da62a303cf040211c386fa6260789e50b43c1
Summary:
This will let the JSC exception handling catch the error, and
display it in a red box.
Reviewed By: yungsters
Differential Revision: D3468336
fbshipit-source-id: b89335dbcebf16a881bba783c68242e2b0cd509f
Summary:
Currently, DevTools only work under ios (although this is undocumented!), because the JavaScriptEngine initialization process skips setupDevTools() on android.
DevTools work fine with Android, as tested on 0.26, 0.27, and 0.28 using Nuclide's inspector.
For reference, [the relevant issue on react-devtools](https://github.com/facebook/react-devtools/issues/229).
Closes https://github.com/facebook/react-native/pull/8095
Reviewed By: bestander
Differential Revision: D3430206
Pulled By: javache
fbshipit-source-id: 76f19407271a3779e12bd244f1bc31ef3a8659c7
Summary:
Currently, DevTools only work under ios (although this is undocumented!), because the JavaScriptEngine initialization process skips setupDevTools() on android.
DevTools work fine with Android, as tested on 0.26, 0.27, and 0.28 using Nuclide's inspector.
For reference, [the relevant issue on react-devtools](https://github.com/facebook/react-devtools/issues/229).
Closes https://github.com/facebook/react-native/pull/8095
Reviewed By: bestander
Differential Revision: D3430206
Pulled By: javache
fbshipit-source-id: 826f0252fff3f0ec2c843149540a0109e34d1d18
Summary:
`polyfillLazyGlobal` used a top level this which get stripped by babel `transform-es2015-modules-commonjs` with the default config. This is mainly an issues for people not using the react native babel preset.
This also replaces a few GLOBAL with global for consistency with the rest of the file.
**Test plan**
Tested that there was an error when using `['transform-es2015-modules-commonjs', { strict: true, allowTopLevelThis: false }]` in the babel config and that it was fixed after applying my changes.
Fixes#7700
Closes https://github.com/facebook/react-native/pull/7971
Differential Revision: D3427675
Pulled By: javache
fbshipit-source-id: 48f258b0db1bf21185193bd56df453ced9242e64
Summary: When we're profiling, we want to load Systrace immediately and profile all the startup and initial render code. The code here used to load Systrace during startup only if `__DEV__` but would always start profiling once Systrace was otherwise required. That seems pretty hard to reason about, so I'm switching to always requiring Systrace during the startup path and enabling profiling if appropriate. In actual production that'll always be false, of course.
Reviewed By: javache
Differential Revision: D3338216
fbshipit-source-id: f173e82f34e110d83e7ff04f11af9b302a54b859
Summary:
Reuses the original property descriptor when overwriting / polyfilling globals to ensure enumerability and writability are the same
Closes https://github.com/facebook/react-native/pull/7704
Differential Revision: D3338119
Pulled By: davidaurelio
fbshipit-source-id: ab456324a3346cd3ec8b2c3e3a2378408c92087c
Summary:
This make the transform behave closer to the standard for modules.
This removes the few places that a top level this was used to refer to the global space. It also clean up the usage of `GLOBAL` to use `global` instead as this is what is used everywhere else in the code base. We still define `GLOBAL` for compatibility with other modules.
**Test plan**
Clear the packager cache to make sure the transforms run again. (node ./local-cli/cli.js start --reset-cache).
Run the Movies example (UIExplorer is broken atm) and make sure there are no errors.
Closes https://github.com/facebook/react-native/pull/6255
Differential Revision: D3037227
Pulled By: mkonicek
fb-gh-sync-id: bcf1350ae7a6e92c77d3a87fc9d6e42eb93cb9b9
fbshipit-source-id: bcf1350ae7a6e92c77d3a87fc9d6e42eb93cb9b9
Summary:
This avoids requiring things that may never be used at all by the application such as WebSocket or Geolocation. It also stops us from asking for native modules
before we actually start the application enabling us to potentially be more lazy in the future.
Reviewed By: davidaurelio
Differential Revision: D3212802
fb-gh-sync-id: 70cf0d1a85f39fedc47758e5eb5df789a511bc9b
fbshipit-source-id: 70cf0d1a85f39fedc47758e5eb5df789a511bc9b
Summary: Fixes#6227 as discussed in FB group, also a follow up to ide commit 6ec4d65aec
Differential Revision: D3041185
Pulled By: javache
fb-gh-sync-id: 544c55b14d238eb8bfed3ab1588c6e48d164943e
shipit-source-id: 544c55b14d238eb8bfed3ab1588c6e48d164943e
Summary:
At the moment we have to disable strict mode for the transform-es2015-modules-commonjs because strict mode leaks to the global scope and breaks the bridge. It was due to the way the polyfills were bundled in the package. To fix it, I wrapped the polyfill modules in an IIFE. Then when strict mode was enabled some polyfills were broken due to strict mode errors so that was fixed too. Also removed the IIFE from the polyfills that included one.
This diff doesn't enable the strict mode transform since some internal facebook modules depend on it not being enabled. When #5214 lands we could make the default babel config shipped with OSS react-native use strict mode modules and facebook could just modify the babel config to disable it if needed.
This will allow removing `"strict": false` from https://github.com/facebook/react-native/blob/master/packager/react-packager/.babelrc#L16Fixes#5316
Closes https://github.com/facebook/react-native/pull/5422
Reviewed By: svcscm
Differential Revision: D2846422
Pulled By: davidaurelio
fb-gh-sync-id: a3e2f8909aa87dabab2b872c61b887e80220fb56
Summary:
public
Map and Set are a standard JavaScript features, but are only supported in a subset of JSC versions that we target (e.g. iOS 7's JSC doesn't support Set).
The consequence of this is that failing to require('Set') before using it won't error during testing on a modern OS, but will fail on older OS versions. This diff makes the Map and Set polyfills available globally to all RN apps to avoid that problem.
Reviewed By: davidaurelio
Differential Revision: D2833997
fb-gh-sync-id: 713d8b69f6a1bce2472a1b2e6b84f69d75f30289
Summary:
public
Implement all the necessary glue code for several diffs submitted before to get Hot Loading work end to end:
- Simplify `HMRClient`: we don't need to make it stateful allowing to enable and disable it because both when we enable and disable the interface we need to reload the bundle.
- On the native side we introduced a singleton to process the bundle URL. This new class might alter the url to include the `hot` attribute. I'm not 100% sure this is the best way to implement this but we cannot use `CTLSettings` for this as it's are not available on oss and I didn't want to contaminate `RCTBridge` with something specific to hot loading. Also, we could potentially use this processor for other things in the future. Please let me know if you don't like this approach or you have a better idea :).
- Use this processor to alter the default bundle URL and request a `hot` bundle when hot loading is enabled. Also make sure to enable the HMR interface when the client activates it on the dev menu.
- Add packager `hot` option.
- Include gaeron's `react-transform` on Facebook's JS transformer.
The current implementation couples a bit React Native to this feature because `react-transform-hmr` is required on `InitializeJavaScriptAppEngine`. Ideally, the packager should accept an additional list of requires and include them on the bundle among all their dependencies. Note this is not the same as the option `runBeforeMainModule` as that one only adds a require to the provided module but doesn't include all the dependencies that module amy have that the entry point doesn't. I'll address this in a follow up task to enable asap hot loading (9536142)
I had to remove 2 `.babelrc` files from `react-proxy` and `react-deep-force-update`. There's an internal task for fixing the underlaying issue to avoid doing this horrible hack (t9515889).
Reviewed By: vjeux
Differential Revision: D2790806
fb-gh-sync-id: d4b78a2acfa071d6b3accc2e6716ef5611ad4fda
Summary:
public
Rename the `BridgeProfiling` JS module to `Systrace`, since it's actually just
an API to Systrace markers.
This should make it clearer as we add more perf tooling.
Reviewed By: jspahrsummers
Differential Revision: D2734001
fb-gh-sync-id: 642848fa7340c545067f2a7cf5cef8af1c8a69a2
Summary: Fix for [Issue 1331](https://github.com/facebook/react-native/issues/1331). Sets navigator.product to ReactNative and navigator.productSub to the version string in package.json.
Note that the code requires package.json, which works fine in the RN packager, but webpack users will probably a need to configure a json loader in their config file.
Tested using UIExplorer and console.log printout of the product variables in xcode and Chrome debugger.
Closes https://github.com/facebook/react-native/pull/4083
Reviewed By: svcscm
Differential Revision: D2696881
Pulled By: vjeux
fb-gh-sync-id: 511446432dcd0ec658100715129c77153e743423
Summary: public
Dynamically profile events from RelayProfiler if available. This will expose time spent in Relay in the systraces.
Reviewed By: tadeuzagallo
Differential Revision: D2674215
fb-gh-sync-id: d5f9d529b86d267a80b0cda2223f6a28a08ac385
Summary: public
Make sure some modules that are only available in dev mode are only
included in dev bundles.
Depends on: D2663838
Reviewed By: davidaurelio
Differential Revision: D2663889
fb-gh-sync-id: 42be40b865ef305828b3519556125af090ec61f4
Summary: public
Call the native bindings explicitly from BridgeProfiling instead of polyfill'ing `console.profile` with
a function that has a different signature.
Reviewed By: vjeux
Differential Revision: D2602313
fb-gh-sync-id: 9295eff9458f2caa35b7e982c0f7c06dbe65fd09
Summary: Set up the polyfills for console and process before initializing other modules. Some modules do work (e.g. call `invariant`) when they are first required, so requiring the DefaultInjection module at the beginning ensures we have a consistent JS environment.
Closes https://github.com/facebook/react-native/pull/3526
Reviewed By: spicyj
Differential Revision: D2560340
Pulled By: frantic
fb-gh-sync-id: 44c743e3212ff1dcdbe0169041dfd3ea8f1a54f7
Summary: @public
jest is running the polyfill multiple times on the same environment (cc @cpojer, need to fix that!). By default jest doesn't have XMLHttpRequest polyfilled so it'll define a property with writable to be false. It'll fatal the second time it tries to override XMLHttpRequest.
The hacky workaround is to make properties that do not exist with writable: true. But the long term fix would be to make jest stop running the polyfill multiple times.
Reviewed By: @javache
Differential Revision: D2532019
fb-gh-sync-id: a82abf69541781a64a0744798c736f90833e28cb