-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Overhaul console integration (#525)
Our console integration was designed to work on the same page with the Spotlight UI. It was using a naive filtering method to avoid infinite loops from Spotlight debug mode logger itself. Moreover, it was not taking the `sidecarURL` option, was defaulting to `localhost:8969` as the sidecar URL. This patch overhauls the two, leveraging the fact that they are on the same page. This means switching to the local event-based message passing between the UI and the console integration, removing the need for `fetch` calls and passing around the sidecarURL option. It also overhauls the Spotlight logger to always try to use an unmodified console implementation, removing the need for hacky filtering on the console integration side. ref #521.
- Loading branch information
Showing
9 changed files
with
193 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@spotlightjs/overlay': patch | ||
--- | ||
|
||
Overhaul console integration for more performance and stability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
let loggerActive = false; | ||
import type { WindowWithSpotlight } from '../types'; | ||
|
||
export const SPOTLIGHT_PREFIX = '🔎 [Spotlight]'; | ||
|
||
const windowWithSpotlight = window as WindowWithSpotlight; | ||
if (!windowWithSpotlight.__spotlight) { | ||
windowWithSpotlight.__spotlight = {}; | ||
} | ||
if (!windowWithSpotlight.__spotlight.console) { | ||
windowWithSpotlight.__spotlight.console = {}; | ||
} | ||
|
||
if (!windowWithSpotlight.__spotlight.console.log) { | ||
windowWithSpotlight.__spotlight.console.log = window.console.log; | ||
} | ||
|
||
if (!windowWithSpotlight.__spotlight.console.warn) { | ||
windowWithSpotlight.__spotlight.console.warn = window.console.warn; | ||
} | ||
|
||
const original = windowWithSpotlight.__spotlight.console; | ||
|
||
const noop = (..._args: unknown[]) => {}; // eslint-disable-line @typescript-eslint/no-unused-vars | ||
let _log = noop; | ||
let _warn = noop; | ||
|
||
export function activateLogger() { | ||
loggerActive = true; | ||
_log = (...args: unknown[]) => original.log.call(window, SPOTLIGHT_PREFIX, ...args); | ||
_warn = (...args: unknown[]) => original.warn.call(window, SPOTLIGHT_PREFIX, ...args); | ||
} | ||
|
||
export function deactivateLogger() { | ||
loggerActive = false; | ||
_log = noop; | ||
_warn = noop; | ||
} | ||
|
||
export function log(...args: unknown[]) { | ||
if (loggerActive) { | ||
console.log('🔎 [Spotlight]', ...args); | ||
} | ||
_log(...args); | ||
} | ||
|
||
export function warn(...args: unknown[]) { | ||
if (loggerActive) { | ||
console.warn('🔎 [Spotlight]', ...args); | ||
} | ||
_warn(...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.