Skip to content

Commit 2ea83cc

Browse files
authored
Add subpath that allows scan to run in production (#394)
1 parent 2bb744b commit 2ea83cc

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

packages/scan/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-scan",
3-
"version": "0.3.4",
3+
"version": "0.3.6",
44
"description": "Scan your React app for renders",
55
"keywords": ["react", "react-scan", "react scan", "render", "performance"],
66
"homepage": "https://react-scan.million.dev",
@@ -70,14 +70,14 @@
7070
".": {
7171
"production": {
7272
"import": {
73-
"types": "./dist/rsc-shim.d.mts",
73+
"types": "./dist/index.d.mts",
7474
"react-server": "./dist/rsc-shim.mjs",
75-
"default": "./dist/rsc-shim.mjs"
75+
"default": "./dist/index.mjs"
7676
},
7777
"require": {
78-
"types": "./dist/rsc-shim.d.ts",
78+
"types": "./dist/index.d.mts",
7979
"react-server": "./dist/rsc-shim.js",
80-
"default": "./dist/rsc-shim.js"
80+
"default": "./dist/index.mjs"
8181
}
8282
},
8383
"development": {
@@ -105,6 +105,11 @@
105105
}
106106
}
107107
},
108+
"./all-environments": {
109+
"types": "./dist/core/all-environments.d.ts",
110+
"import": "./dist/core/all-environments.mjs",
111+
"require": "./dist/core/all-environments.js"
112+
},
108113
"./install-hook": {
109114
"types": "./dist/install-hook.d.ts",
110115
"import": "./dist/install-hook.mjs",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactScanInternals, scan as innerScan } from '.';
2+
3+
export const scan = /*#__PURE__*/ (...params: Parameters<typeof innerScan>) => {
4+
if (typeof window !== 'undefined') {
5+
ReactScanInternals.runInAllEnvironments = true;
6+
innerScan(...params);
7+
}
8+
};

packages/scan/src/core/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export interface Internals {
238238
onRender: ((fiber: Fiber, renders: Array<Render>) => void) | null;
239239
Store: StoreType;
240240
version: string;
241+
runInAllEnvironments: boolean;
241242
}
242243

243244
export type FunctionalComponentStateChange = {
@@ -320,6 +321,7 @@ export const ReactScanInternals: Internals = {
320321
// smoothlyAnimateOutlines: true,
321322
// trackUnnecessaryRenders: false,
322323
}),
324+
runInAllEnvironments: false,
323325
onRender: null,
324326
scheduledOutlines: new Map(),
325327
activeOutlines: new Map(),
@@ -544,6 +546,7 @@ export const start = () => {
544546
}
545547

546548
if (
549+
!ReactScanInternals.runInAllEnvironments &&
547550
getIsProduction() &&
548551
!ReactScanInternals.options.value.dangerouslyForceRunInProduction
549552
) {
@@ -634,7 +637,11 @@ export const scan = (options: Options = {}) => {
634637
setOptions(options);
635638
const isInIframe = Store.isInIframe.value;
636639

637-
if (isInIframe && !ReactScanInternals.options.value.allowInIframe) {
640+
if (
641+
isInIframe &&
642+
!ReactScanInternals.options.value.allowInIframe &&
643+
!ReactScanInternals.runInAllEnvironments
644+
) {
638645
return;
639646
}
640647

packages/scan/tsup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ void (async () => {
5959
names.push(exportItem.n);
6060
}
6161

62-
const createFn = (name: string) =>
63-
`export let ${name}=()=>{console.error('Do not use ${name} directly in a Server Component module. It should only be used in a Client Component.');return undefined}`;
62+
const createFn = (name: string) => `export let ${name}=()=>{}`;
6463
const createVar = (name: string) => `export let ${name}=undefined`;
6564

6665
let script = '';
@@ -117,6 +116,7 @@ export default defineConfig([
117116
entry: [
118117
'./src/index.ts',
119118
'./src/install-hook.ts',
119+
'./src/core/all-environments.ts',
120120
'./src/core/monitor/index.ts',
121121
'./src/core/monitor/params/next.ts',
122122
'./src/core/monitor/params/react-router-v5.ts',

0 commit comments

Comments
 (0)