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

Wrap console calls into a check #2301

Merged
merged 2 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/react-dev-utils/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var connection = new SockJS(
// to avoid spamming the console. Disconnect usually happens
// when developer stops the server.
connection.onclose = function() {
if (typeof console !== 'undefined') {
if (typeof console !== 'undefined' && typeof console.info === 'function') {
console.info(
'The development server has disconnected.\nRefresh the page if necessary.'
);
Expand All @@ -186,8 +186,8 @@ var hasCompileErrors = false;

function clearOutdatedErrors() {
// Clean up outdated compile errors, if any.
if (typeof console !== 'undefined') {
if (hasCompileErrors && typeof console.clear === 'function') {
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
if (hasCompileErrors) {
console.clear();
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ function handleWarnings(warnings) {
errors: [],
});

if (typeof console !== 'undefined') {
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
for (var i = 0; i < formatted.warnings.length; i++) {
console.warn(stripAnsi(formatted.warnings[i]));
}
Expand Down Expand Up @@ -266,7 +266,7 @@ function handleErrors(errors) {
showErrorOverlay(formatted.errors[0]);

// Also log them to the console.
if (typeof console !== 'undefined') {
if (typeof console !== 'undefined' && typeof console.error === 'function') {
for (var i = 0; i < formatted.errors.length; i++) {
console.error(stripAnsi(formatted.errors[i]));
}
Expand Down
28 changes: 15 additions & 13 deletions packages/react-error-overlay/src/effects/proxyConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ const permanentRegister = function proxyConsole(
) {
if (typeof console !== 'undefined') {
const orig = console[type];
console[type] = function __stack_frame_overlay_proxy_console__() {
try {
const message = arguments[0];
if (typeof message === 'string' && reactFrameStack.length > 0) {
callback(message, reactFrameStack[reactFrameStack.length - 1]);
if (typeof orig === 'function') {
console[type] = function __stack_frame_overlay_proxy_console__() {
try {
const message = arguments[0];
if (typeof message === 'string' && reactFrameStack.length > 0) {
callback(message, reactFrameStack[reactFrameStack.length - 1]);
}
} catch (err) {
// Warnings must never crash. Rethrow with a clean stack.
setTimeout(function() {
throw err;
});
}
} catch (err) {
// Warnings must never crash. Rethrow with a clean stack.
setTimeout(function() {
throw err;
});
}
return orig.apply(this, arguments);
};
return orig.apply(this, arguments);
};
}
}
};

Expand Down