Skip to content

Commit 7a9d4ff

Browse files
committed
fix(transform): suppress React Fragment data-ds prop warning in vite and webpack
Add the same console.error filter already present in the turbopack loader preamble to the Vite and Webpack plugins. Suppresses React's "Invalid prop `data-ds` supplied to React.Fragment" warning that fires when a component resolves to Fragment at runtime via a dynamic expression.
1 parent 5bdc74a commit 7a9d4ff

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

packages/domscribe-transform/src/plugins/vite/vite.plugin.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,23 @@ export function domscribe(options: VitePluginOptions = {}): Plugin {
304304
transformIndexHtml(): IndexHtmlTransformResult | undefined {
305305
const tags: HtmlTagDescriptor[] = [];
306306

307+
// Suppress React's "Invalid prop `data-ds` supplied to React.Fragment"
308+
// warning. Fires when a component resolves to Fragment at runtime
309+
// (e.g. `const P = hasKey ? dynamic(...) : Fragment`). Harmless but
310+
// clutters the console and triggers error overlays.
311+
tags.push({
312+
tag: 'script',
313+
children:
314+
`if(!window.__DOMSCRIBE_CONSOLE_PATCHED__){` +
315+
`window.__DOMSCRIBE_CONSOLE_PATCHED__=true;` +
316+
`var _ce=console.error;` +
317+
`console.error=function(){` +
318+
`if(typeof arguments[0]==='string'&&arguments[0].indexOf('data-ds')!==-1&&arguments[0].indexOf('React.Fragment')!==-1)return;` +
319+
`return _ce.apply(console,arguments)` +
320+
`}}`,
321+
injectTo: 'head-prepend',
322+
});
323+
307324
// Inject relay port for overlay discovery
308325
// The overlay (browser UI) needs to know which port to connect to
309326
if (relayPort && relayHost) {
@@ -338,10 +355,7 @@ export function domscribe(options: VitePluginOptions = {}): Plugin {
338355
});
339356
}
340357

341-
if (tags.length > 0) {
342-
return { html: '', tags };
343-
}
344-
return undefined;
358+
return { html: '', tags };
345359
},
346360
};
347361
}

packages/domscribe-transform/src/plugins/webpack/webpack.plugin.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ export class DomscribeWebpackPlugin {
268268
const headTags: string[] = [];
269269
const bodyTags: string[] = [];
270270

271+
// Suppress React's "Invalid prop `data-ds` supplied to React.Fragment"
272+
// warning. Fires when a component resolves to Fragment at runtime
273+
// (e.g. `const P = hasKey ? dynamic(...) : Fragment`).
274+
headTags.push(
275+
`<script>` +
276+
`if(!window.__DOMSCRIBE_CONSOLE_PATCHED__){` +
277+
`window.__DOMSCRIBE_CONSOLE_PATCHED__=true;` +
278+
`var _ce=console.error;` +
279+
`console.error=function(){` +
280+
`if(typeof arguments[0]==='string'&&arguments[0].indexOf('data-ds')!==-1&&arguments[0].indexOf('React.Fragment')!==-1)return;` +
281+
`return _ce.apply(console,arguments)` +
282+
`}}` +
283+
`</script>`,
284+
);
285+
271286
// Add relay script tag to head
272287
const relayTag = this.getRelayScriptTag();
273288
if (relayTag) {

0 commit comments

Comments
 (0)