Skip to content

Commit 13fa582

Browse files
committed
fix: chain pattern replacements and support HTML script tags in removal
- Fix removePatternFromContent to chain all pattern replacements instead of returning after first match - Add REACT_SCAN_HTML_SCRIPT_TAG pattern to match standard HTML <script></script> tags - Include HTML script tag pattern in Vite and Webpack removal functions - Run formatter on modified files
1 parent 377d944 commit 13fa582

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

packages/cli/src/utils/transform.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,17 +1612,18 @@ const removePatternFromContent = (
16121612
successMessage: string,
16131613
noChangesMessage: string,
16141614
): TransformResult => {
1615+
let newContent = originalContent;
16151616
for (const pattern of patterns) {
1616-
const newContent = originalContent.replace(pattern, "");
1617-
if (newContent !== originalContent) {
1618-
return {
1619-
success: true,
1620-
filePath,
1621-
message: successMessage,
1622-
originalContent,
1623-
newContent,
1624-
};
1625-
}
1617+
newContent = newContent.replace(pattern, "");
1618+
}
1619+
if (newContent !== originalContent) {
1620+
return {
1621+
success: true,
1622+
filePath,
1623+
message: successMessage,
1624+
originalContent,
1625+
newContent,
1626+
};
16261627
}
16271628
return {
16281629
success: true,
@@ -1635,6 +1636,8 @@ const removePatternFromContent = (
16351636
const REACT_SCAN_SCRIPT_WITH_DEV_CONDITION =
16361637
/\s*\{process\.env\.NODE_ENV === ["']development["'] && \(\s*<Script[^>]*react-scan[^>]*\/>\s*\)\}/gis;
16371638
const REACT_SCAN_SCRIPT_TAG = /<Script[^>]*react-scan[^>]*\/>/gi;
1639+
const REACT_SCAN_HTML_SCRIPT_TAG =
1640+
/<script[^>]*react-scan[^>]*>[\s\S]*?<\/script>/gi;
16381641
const REACT_SCAN_DYNAMIC_IMPORT =
16391642
/\s*import\s*\(\s*["']react-scan["']\s*\)\s*;?\s*/gi;
16401643
const REACT_SCAN_DEV_CONDITIONAL_IMPORT =
@@ -1661,7 +1664,7 @@ const removeReactScanFromVite = (
16611664
removePatternFromContent(
16621665
originalContent,
16631666
filePath,
1664-
[REACT_SCAN_DYNAMIC_IMPORT],
1667+
[REACT_SCAN_HTML_SCRIPT_TAG, REACT_SCAN_DYNAMIC_IMPORT],
16651668
"Remove React Scan from Vite",
16661669
"No React Scan import found",
16671670
);
@@ -1673,7 +1676,11 @@ const removeReactScanFromWebpack = (
16731676
removePatternFromContent(
16741677
originalContent,
16751678
filePath,
1676-
[REACT_SCAN_DEV_CONDITIONAL_IMPORT, REACT_SCAN_DYNAMIC_IMPORT],
1679+
[
1680+
REACT_SCAN_HTML_SCRIPT_TAG,
1681+
REACT_SCAN_DEV_CONDITIONAL_IMPORT,
1682+
REACT_SCAN_DYNAMIC_IMPORT,
1683+
],
16771684
"Remove React Scan from Webpack",
16781685
"No React Scan import found",
16791686
);

packages/mcp/src/server.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,11 @@ const createHttpServer = (port: number): Server => {
174174
return;
175175
}
176176

177-
response
178-
.writeHead(400, { "Content-Type": "application/json" })
179-
.end(
180-
JSON.stringify({
181-
error: "No valid session. Send an initialize request first.",
182-
}),
183-
);
177+
response.writeHead(400, { "Content-Type": "application/json" }).end(
178+
JSON.stringify({
179+
error: "No valid session. Send an initialize request first.",
180+
}),
181+
);
184182
return;
185183
}
186184

packages/react-grab/e2e/freeze-animations.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ test.describe("Freeze Animations", () => {
99
}) => {
1010
const getPageAnimationStates = async () => {
1111
return reactGrab.page.evaluate((attrName) => {
12-
return document.getAnimations().reduce<string[]>(
13-
(states, animation) => {
12+
return document
13+
.getAnimations()
14+
.reduce<string[]>((states, animation) => {
1415
if (animation.effect instanceof KeyframeEffect) {
1516
const target = animation.effect.target;
1617
if (target instanceof Element) {
@@ -25,9 +26,7 @@ test.describe("Freeze Animations", () => {
2526
}
2627
states.push(animation.playState);
2728
return states;
28-
},
29-
[],
30-
);
29+
}, []);
3130
}, ATTRIBUTE_NAME);
3231
};
3332

packages/react-grab/src/utils/scan.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,7 @@ const formatComponentLine = (
881881
);
882882

883883
if (passiveEffectCount > 0 && passiveEffectTime > 0) {
884-
diagnosticParts.push(
885-
`effect:${passiveEffectTime}ms*${passiveEffectCount}`,
886-
);
884+
diagnosticParts.push(`effect:${passiveEffectTime}ms*${passiveEffectCount}`);
887885
}
888886

889887
if (stats.layoutEffectCount > 0 && stats.totalLayoutEffectTime > 0) {
@@ -894,9 +892,7 @@ const formatComponentLine = (
894892

895893
const unstableEntries = unstablePropsPerComponent.get(componentName);
896894
if (unstableEntries && unstableEntries.size > 0) {
897-
diagnosticParts.push(
898-
`unstable:${Array.from(unstableEntries).join(",")}`,
899-
);
895+
diagnosticParts.push(`unstable:${Array.from(unstableEntries).join(",")}`);
900896
}
901897

902898
return diagnosticParts.join(" ");

0 commit comments

Comments
 (0)