Skip to content

Commit

Permalink
fix(monitoring): uncaught excetions hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPruzan committed Dec 9, 2024
1 parent 237f624 commit c3b1b85
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 283 deletions.
2 changes: 1 addition & 1 deletion packages/scan/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-scan",
"version": "0.0.41",
"version": "0.0.42",
"description": "Scan your React app for renders",
"keywords": [
"react",
Expand Down
46 changes: 25 additions & 21 deletions packages/scan/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,29 +314,33 @@ let flushInterval: any | undefined;

export const start = () => {
if (typeof window === 'undefined') return;

const existingOverlay = document.querySelector('react-scan-overlay');
if (existingOverlay) {
return;
}
initReactScanOverlay();
const overlayElement = document.createElement('react-scan-overlay') as any;

document.documentElement.appendChild(overlayElement);

const options = ReactScanInternals.options.value;

const ctx = overlayElement.getContext();
createInspectElementStateMachine();
const audioContext =
typeof window !== 'undefined'
? new (window.AudioContext ||
// @ts-expect-error -- This is a fallback for Safari
window.webkitAudioContext)()
: null;
createPerfObserver();
let ctx: CanvasRenderingContext2D;
let audioContext: any;

logIntro();
if (!Store.monitor.value) {
const existingOverlay = document.querySelector('react-scan-overlay');
if (existingOverlay) {
return;
}
initReactScanOverlay();
const overlayElement = document.createElement('react-scan-overlay') as any;

document.documentElement.appendChild(overlayElement);

ctx = overlayElement.getContext();
createInspectElementStateMachine();
audioContext =
typeof window !== 'undefined'
? new (window.AudioContext ||
// @ts-expect-error -- This is a fallback for Safari
window.webkitAudioContext)()
: null;
createPerfObserver();

logIntro();
}

globalThis.__REACT_SCAN__ = {
ReactScanInternals,
Expand Down Expand Up @@ -432,7 +436,7 @@ export const start = () => {

ReactScanInternals.instrumentation = instrumentation;

if (options.showToolbar) {
if (options.showToolbar && !Store.monitor.value) {
createToolbar();
}
};
Expand Down
246 changes: 0 additions & 246 deletions packages/scan/src/core/monitor/benchmark.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/scan/src/core/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const BaseMonitor = ({
url,
apiKey,
interactions: [],
session: getSession(),
session: getSession().catch(() => null),
route,
path,
};
Expand Down Expand Up @@ -61,7 +61,7 @@ export const Monitoring = ({
url,
apiKey,
interactions: [],
session: getSession(),
session: getSession().catch(() => null),
route,
path,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/scan/src/core/monitor/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const flush = async (): Promise<void> => {
return;
}
// idempotent
const session = await getSession();
const session = await getSession().catch(() => null);

if (!session) return;
// nisarg do not add this back fix it on your side
Expand Down
2 changes: 0 additions & 2 deletions packages/scan/src/core/monitor/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type Fiber } from 'react-reconciler';
import { type getDevicePerformance } from './benchmark';

export enum Device {
DESKTOP = 0,
Expand All @@ -16,7 +15,6 @@ export interface Session {
cpu: number;
gpu: string | null;
mem: number;
performance: Awaited<ReturnType<typeof getDevicePerformance>>;
}

export interface Interaction {
Expand Down
Loading

0 comments on commit c3b1b85

Please sign in to comment.