From ff5a1b72fde92d3f7401fdef5477cd276e47a1f1 Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 18 Oct 2019 10:06:29 -0700 Subject: [PATCH] Fix infinite console proxy bug in headless Summary: Headless flipper is getting an infinite recursion problem after the console proxy was changed to an in-place method swap. This uses an in-place method swap in headless too, so they don't conflict with each other. Reviewed By: passy, priteshrnandgaonkar Differential Revision: D18007638 fbshipit-source-id: 62dce7fa94f4ce6b90da4f3c6ec6e8d9ed15fbe7 --- headless/index.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/headless/index.tsx b/headless/index.tsx index 2bc4ae6e0..91a761336 100644 --- a/headless/index.tsx +++ b/headless/index.tsx @@ -216,17 +216,13 @@ async function startFlipper(userArguments: UserArguments) { |__| |_|_| _| _|___|_| v${global.__VERSION__} |_| |_| `); + // redirect all logging to stderr - const originalConsole = global.console; - global.console = new Proxy(console, { - get: function(_obj, prop) { - return (...args: any[]) => { - if (prop === 'error' || verbose) { - originalConsole.error(`[${String(prop)}] `, ...args); - } - }; - }, - }); + const overriddenMethods = ['debug', 'info', 'log', 'warn', 'error']; + for (const method of overriddenMethods) { + (global.console as {[key: string]: any})[method] = + method === 'error' || verbose ? global.console.error : () => {}; + } // Polyfills global.WebSocket = require('ws'); // used for redux devtools