@@ -265,6 +265,7 @@ function patchRuntimePlugin(
265265 renderChunk ( code ) {
266266 // patch rolldown_runtime to workaround a few things
267267 if ( code . includes ( '//#region rolldown:runtime' ) ) {
268+ // TODO: is this magic string heavy?
268269 const output = new MagicString ( code )
269270 // replace hard-coded WebSocket setup with custom client
270271 output . replace ( / c o n s t s o c k e t = .* ?\n \} ; / s, getRolldownClientCode ( ) )
@@ -274,11 +275,11 @@ function patchRuntimePlugin(
274275 . replace (
275276 'for (var i = 0; i < module.parents.length; i++) {' ,
276277 `
277- if (module.parents.length === 0) {
278- __rolldown_hot.send("rolldown:hmr-deadend", { moduleId });
279- break;
280- }
281- for (var i = 0; i < module.parents.length; i++) {`,
278+ if (module.parents.length === 0) {
279+ __rolldown_hot.send("rolldown:hmr-deadend", { moduleId });
280+ break;
281+ }
282+ for (var i = 0; i < module.parents.length; i++) {`,
282283 )
283284 if ( rolldownDevOptions . reactRefresh ) {
284285 output . prepend ( getReactRefreshRuntimeCode ( ) )
@@ -318,7 +319,7 @@ function getRolldownClientCode() {
318319 code += `
319320const hot = createHotContext("/__rolldown");
320321hot.on("rolldown:hmr", (data) => {
321- (0, eval)(data[1]);
322+ (0, eval)(data[1]);
322323});
323324window.__rolldown_hot = hot;
324325`
@@ -360,29 +361,29 @@ function getReactRefreshRuntimeCode() {
360361 output . replaceAll ( 'process.env.NODE_ENV !== "production"' , 'true' )
361362 output . replaceAll ( / \b e x p o r t s \. / g, '__react_refresh_runtime.' )
362363 output . append ( `
363- (() => {
364- __react_refresh_runtime.injectIntoGlobalHook(self);
365-
366- __react_refresh_transform_define = (file) => [
367- __react_refresh_runtime.createSignatureFunctionForTransform,
368- (type, id) => __react_refresh_runtime.register(type, file + '_' + id)
369- ];
370-
371- __react_refresh_transform_setupHot = (hot) => {
372- hot.accept((prev) => {
373- debouncedRefresh();
374- });
375- };
376-
377- function debounce(fn, delay) {
378- let handle
379- return () => {
380- clearTimeout(handle)
381- handle = setTimeout(fn, delay)
382- }
383- }
384- const debouncedRefresh = debounce(__react_refresh_runtime.performReactRefresh, 16);
385- })()
386- `)
364+ (() => {
365+ __react_refresh_runtime.injectIntoGlobalHook(self);
366+
367+ __react_refresh_transform_define = (file) => [
368+ __react_refresh_runtime.createSignatureFunctionForTransform,
369+ (type, id) => __react_refresh_runtime.register(type, file + '_' + id)
370+ ];
371+
372+ __react_refresh_transform_setupHot = (hot) => {
373+ hot.accept((prev) => {
374+ debouncedRefresh();
375+ });
376+ };
377+
378+ function debounce(fn, delay) {
379+ let handle
380+ return () => {
381+ clearTimeout(handle)
382+ handle = setTimeout(fn, delay)
383+ }
384+ }
385+ const debouncedRefresh = debounce(__react_refresh_runtime.performReactRefresh, 16);
386+ })()
387+ `)
387388 return output . toString ( )
388389}
0 commit comments