Skip to content

Commit a6eb16b

Browse files
committed
fix
1 parent f326fd8 commit a6eb16b

File tree

8 files changed

+56
-48
lines changed

8 files changed

+56
-48
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ Add this to your `index.html`:
122122
</html>
123123
```
124124
125+
> **Note:** If you use Vite in [Express middleware mode](https://vite.dev/guide/ssr#setting-up-the-dev-server) (e.g. Replit starter templates), the inline script can cause `Failed to parse JSON file` errors when Chromium DevTools is open. For these setups, import from your entry file instead:
126+
>
127+
> ```tsx
128+
> // src/main.tsx
129+
> if (import.meta.env.DEV) {
130+
> import("react-grab");
131+
> }
132+
> ```
133+
125134
#### Webpack
126135
127136
First, install React Grab:

packages/cli/src/utils/templates.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const NEXT_APP_ROUTER_SCRIPT = `{process.env.NODE_ENV === "development" &
4949
export const NEXT_APP_ROUTER_SCRIPT_WITH_AGENT = (
5050
agent: AgentIntegration,
5151
): string => {
52-
if (agent === "none" || agent === "mcp") return NEXT_APP_ROUTER_SCRIPT;
52+
if (agent === "none") return NEXT_APP_ROUTER_SCRIPT;
5353

5454
return `{process.env.NODE_ENV === "development" && (
5555
<Script
@@ -77,7 +77,7 @@ export const NEXT_PAGES_ROUTER_SCRIPT = `{process.env.NODE_ENV === "development"
7777
export const NEXT_PAGES_ROUTER_SCRIPT_WITH_AGENT = (
7878
agent: AgentIntegration,
7979
): string => {
80-
if (agent === "none" || agent === "mcp") return NEXT_PAGES_ROUTER_SCRIPT;
80+
if (agent === "none") return NEXT_PAGES_ROUTER_SCRIPT;
8181

8282
return `{process.env.NODE_ENV === "development" && (
8383
<Script
@@ -101,7 +101,7 @@ export const VITE_SCRIPT = `<script type="module">
101101
</script>`;
102102

103103
export const VITE_SCRIPT_WITH_AGENT = (agent: AgentIntegration): string => {
104-
if (agent === "none" || agent === "mcp") return VITE_SCRIPT;
104+
if (agent === "none") return VITE_SCRIPT;
105105

106106
return `<script type="module">
107107
if (import.meta.env.DEV) {
@@ -116,7 +116,7 @@ export const WEBPACK_IMPORT = `if (process.env.NODE_ENV === "development") {
116116
}`;
117117

118118
export const WEBPACK_IMPORT_WITH_AGENT = (agent: AgentIntegration): string => {
119-
if (agent === "none" || agent === "mcp") return WEBPACK_IMPORT;
119+
if (agent === "none") return WEBPACK_IMPORT;
120120

121121
return `if (process.env.NODE_ENV === "development") {
122122
import("react-grab");
@@ -131,7 +131,7 @@ export const TANSTACK_EFFECT = `useEffect(() => {
131131
}, []);`;
132132

133133
export const TANSTACK_EFFECT_WITH_AGENT = (agent: AgentIntegration): string => {
134-
if (agent === "none" || agent === "mcp") return TANSTACK_EFFECT;
134+
if (agent === "none") return TANSTACK_EFFECT;
135135

136136
return `useEffect(() => {
137137
if (import.meta.env.DEV) {

packages/cli/src/utils/transform.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const addAgentToExistingNextApp = (
175175
agent: AgentIntegration,
176176
filePath: string,
177177
): TransformResult => {
178-
if (agent === "none" || agent === "mcp") {
178+
if (agent === "none") {
179179
return {
180180
success: true,
181181
filePath,
@@ -249,7 +249,7 @@ const addAgentToExistingVite = (
249249
agent: AgentIntegration,
250250
filePath: string,
251251
): TransformResult => {
252-
if (agent === "none" || agent === "mcp") {
252+
if (agent === "none") {
253253
return {
254254
success: true,
255255
filePath,
@@ -301,7 +301,7 @@ const addAgentToExistingWebpack = (
301301
agent: AgentIntegration,
302302
filePath: string,
303303
): TransformResult => {
304-
if (agent === "none" || agent === "mcp") {
304+
if (agent === "none") {
305305
return {
306306
success: true,
307307
filePath,
@@ -353,7 +353,7 @@ const addAgentToExistingTanStack = (
353353
agent: AgentIntegration,
354354
filePath: string,
355355
): TransformResult => {
356-
if (agent === "none" || agent === "mcp") {
356+
if (agent === "none") {
357357
return {
358358
success: true,
359359
filePath,
@@ -769,43 +769,45 @@ export const previewTransform = (
769769
reactGrabAlreadyConfigured: boolean = false,
770770
force: boolean = false,
771771
): TransformResult => {
772+
const resolvedAgent: AgentIntegration = agent === "mcp" ? "none" : agent;
773+
772774
switch (framework) {
773775
case "next":
774776
if (nextRouterType === "app") {
775777
return transformNextAppRouter(
776778
projectRoot,
777-
agent,
779+
resolvedAgent,
778780
reactGrabAlreadyConfigured,
779781
force,
780782
);
781783
}
782784
return transformNextPagesRouter(
783785
projectRoot,
784-
agent,
786+
resolvedAgent,
785787
reactGrabAlreadyConfigured,
786788
force,
787789
);
788790

789791
case "vite":
790792
return transformVite(
791793
projectRoot,
792-
agent,
794+
resolvedAgent,
793795
reactGrabAlreadyConfigured,
794796
force,
795797
);
796798

797799
case "tanstack":
798800
return transformTanStack(
799801
projectRoot,
800-
agent,
802+
resolvedAgent,
801803
reactGrabAlreadyConfigured,
802804
force,
803805
);
804806

805807
case "webpack":
806808
return transformWebpack(
807809
projectRoot,
808-
agent,
810+
resolvedAgent,
809811
reactGrabAlreadyConfigured,
810812
force,
811813
);

packages/cli/test/templates.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ describe("Next.js App Router templates", () => {
4040
expect(script).toContain(`@react-grab/${agent}`);
4141
}
4242
});
43-
44-
it("should return basic script when agent is mcp", () => {
45-
const script = NEXT_APP_ROUTER_SCRIPT_WITH_AGENT("mcp");
46-
47-
expect(script).toContain("react-grab");
48-
expect(script).not.toContain("@react-grab/");
49-
});
5043
});
5144

5245
describe("Vite templates", () => {
@@ -68,13 +61,6 @@ describe("Vite templates", () => {
6861
expect(script).toContain("react-grab");
6962
expect(script).not.toContain("@react-grab/");
7063
});
71-
72-
it("should generate script with mcp agent", () => {
73-
const script = VITE_SCRIPT_WITH_AGENT("mcp");
74-
75-
expect(script).toContain("react-grab");
76-
expect(script).toContain("@react-grab/mcp/client");
77-
});
7864
});
7965

8066
describe("Webpack templates", () => {
@@ -97,20 +83,4 @@ describe("Webpack templates", () => {
9783
expect(importBlock).toContain("react-grab");
9884
expect(importBlock).not.toContain("@react-grab/");
9985
});
100-
101-
it("should generate import with mcp agent", () => {
102-
const importBlock = WEBPACK_IMPORT_WITH_AGENT("mcp");
103-
104-
expect(importBlock).toContain("react-grab");
105-
expect(importBlock).toContain("@react-grab/mcp/client");
106-
});
107-
});
108-
109-
describe("TanStack templates", () => {
110-
it("should generate effect with mcp agent", () => {
111-
const effect = TANSTACK_EFFECT_WITH_AGENT("mcp");
112-
113-
expect(effect).toContain("react-grab");
114-
expect(effect).toContain("@react-grab/mcp/client");
115-
});
11686
});

packages/cli/test/transform.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
195195
expect(result.newContent).toContain("@react-grab/cursor");
196196
});
197197

198-
it("should add MCP client to layout when agent is mcp", () => {
198+
it("should add base script without agent client when agent is mcp", () => {
199199
const layoutWithHead = `export default function RootLayout({ children }: { children: React.ReactNode }) {
200200
return (
201201
<html lang="en">
@@ -214,7 +214,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
214214

215215
expect(result.success).toBe(true);
216216
expect(result.newContent).toContain("react-grab");
217-
expect(result.newContent).toContain("@react-grab/mcp");
217+
expect(result.newContent).not.toContain("@react-grab/mcp");
218218
});
219219

220220
it("should fail when layout file not found", () => {
@@ -304,7 +304,7 @@ describe("previewTransform - Vite", () => {
304304
expect(result.newContent).toContain("@react-grab/claude-code");
305305
});
306306

307-
it("should add MCP client to Vite index.html when agent is mcp", () => {
307+
it("should add base script without agent client when agent is mcp", () => {
308308
mockExistsSync.mockImplementation((path) =>
309309
String(path).endsWith("index.html"),
310310
);
@@ -314,7 +314,7 @@ describe("previewTransform - Vite", () => {
314314

315315
expect(result.success).toBe(true);
316316
expect(result.newContent).toContain("react-grab");
317-
expect(result.newContent).toContain("@react-grab/mcp/client");
317+
expect(result.newContent).not.toContain("@react-grab/mcp");
318318
});
319319
});
320320

packages/grab/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ Add this to your `index.html`:
122122
</html>
123123
```
124124
125+
> **Note:** If you use Vite in [Express middleware mode](https://vite.dev/guide/ssr#setting-up-the-dev-server) (e.g. Replit starter templates), the inline script can cause `Failed to parse JSON file` errors when Chromium DevTools is open. For these setups, import from your entry file instead:
126+
>
127+
> ```tsx
128+
> // src/main.tsx
129+
> if (import.meta.env.DEV) {
130+
> import("grab");
131+
> }
132+
> ```
133+
125134
#### Webpack
126135
127136
First, install React Grab:

packages/react-grab/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ Add this to your `index.html`:
122122
</html>
123123
```
124124
125+
> **Note:** If you use Vite in [Express middleware mode](https://vite.dev/guide/ssr#setting-up-the-dev-server) (e.g. Replit starter templates), the inline script can cause `Failed to parse JSON file` errors when Chromium DevTools is open. For these setups, import from your entry file instead:
126+
>
127+
> ```tsx
128+
> // src/main.tsx
129+
> if (import.meta.env.DEV) {
130+
> import("react-grab");
131+
> }
132+
> ```
133+
125134
#### Webpack
126135
127136
First, install React Grab:

packages/website/public/install.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ Add to `index.html`:
126126
</head>
127127
```
128128
129+
> **Note:** If you use Vite in [Express middleware mode](https://vite.dev/guide/ssr#setting-up-the-dev-server) (e.g. Replit starter templates), the inline script can cause `Failed to parse JSON file` errors when Chromium DevTools is open. For these setups, import from your entry file instead:
130+
>
131+
> ```tsx
132+
> // src/main.tsx
133+
> if (import.meta.env.DEV) {
134+
> import("react-grab");
135+
> }
136+
> ```
137+
129138
#### Webpack
130139
131140
Add to your main entry file (e.g., `src/index.tsx`):

0 commit comments

Comments
 (0)