Hot Loading Sourcemaps

Summary:
public

To make sourcemaps work on Hot Loading work, we'll need to be able to serve them for each module that is dynamically replaced. To do so we introduced a new parameter to the bundler, namely `entryModuleOnly` to decide whether or not to process the full dependency tree or just the module associated to the entry file. Also we need to add `//sourceMappingURL` to the HMR updates so that in case of an error the runtime retrieves the sourcemaps for the file on which an error occurred from the server.

Finally, we need to refactor a bit how we load the HMR updates into JSC. Unfortunately, if the code is eval'ed when an error is thrown, the line and column number are missing. This is a bug/missing feature in JSC. To walkaround the issue we need to eval the code on native. This adds a bit of complexity to HMR as for both platforms we'll have to have a thin module to inject code but I don't see any other alternative. when debugging this is not needed as Chrome supports sourceMappingURLs on eval'ed code

Reviewed By: javache

Differential Revision: D2841788

fb-gh-sync-id: ad9370d26894527a151cea722463e694c670227e
This commit is contained in:
Martín Bigio
2016-01-27 14:55:02 -08:00
committed by facebook-github-bot-0
parent b85a52a461
commit f2438b440d
17 changed files with 331 additions and 128 deletions

View File

@@ -11,37 +11,37 @@
*/
'use strict';
var sourceMapPromise;
var exceptionID = 0;
let exceptionID = 0;
/**
* Handles the developer-visible aspect of errors and exceptions
*/
function reportException(e: Error, isFatal: bool) {
var loadSourceMap = require('loadSourceMap');
var parseErrorStack = require('parseErrorStack');
var RCTExceptionsManager = require('NativeModules').ExceptionsManager;
const parseErrorStack = require('parseErrorStack');
const RCTExceptionsManager = require('NativeModules').ExceptionsManager;
var currentExceptionID = ++exceptionID;
const currentExceptionID = ++exceptionID;
if (RCTExceptionsManager) {
var stack = parseErrorStack(e);
const stack = parseErrorStack(e);
if (isFatal) {
RCTExceptionsManager.reportFatalException(e.message, stack, currentExceptionID);
} else {
RCTExceptionsManager.reportSoftException(e.message, stack, currentExceptionID);
}
if (__DEV__) {
(sourceMapPromise = sourceMapPromise || loadSourceMap())
.then(map => {
var prettyStack = parseErrorStack(e, map);
RCTExceptionsManager.updateExceptionMessage(e.message, prettyStack, currentExceptionID);
})
.catch(error => {
// This can happen in a variety of normal situations, such as
// Network module not being available, or when running locally
console.warn('Unable to load source map: ' + error.message);
});
require('SourceMapsCache').getSourceMaps().then(sourceMaps => {
const prettyStack = parseErrorStack(e, sourceMaps);
RCTExceptionsManager.updateExceptionMessage(
e.message,
prettyStack,
currentExceptionID,
);
})
.catch(error => {
// This can happen in a variety of normal situations, such as
// Network module not being available, or when running locally
console.warn('Unable to load source map: ' + error.message);
});
}
}
}
@@ -81,15 +81,15 @@ function installConsoleErrorReporter() {
if (arguments[0] && arguments[0].stack) {
reportException(arguments[0], /* isFatal */ false);
} else {
var stringifySafe = require('stringifySafe');
var str = Array.prototype.map.call(arguments, stringifySafe).join(', ');
const stringifySafe = require('stringifySafe');
const str = Array.prototype.map.call(arguments, stringifySafe).join(', ');
if (str.slice(0, 10) === '"Warning: ') {
// React warnings use console.error so that a stack trace is shown, but
// we don't (currently) want these to show a redbox
// (Note: Logic duplicated in polyfills/console.js.)
return;
}
var error : any = new Error('console.error: ' + str);
const error : any = new Error('console.error: ' + str);
error.framesToPop = 1;
reportException(error, /* isFatal */ false);
}