@@ -265,6 +265,7 @@ function patchRuntimePlugin(
265
265
renderChunk ( code ) {
266
266
// patch rolldown_runtime to workaround a few things
267
267
if ( code . includes ( '//#region rolldown:runtime' ) ) {
268
+ // TODO: is this magic string heavy?
268
269
const output = new MagicString ( code )
269
270
// replace hard-coded WebSocket setup with custom client
270
271
output . replace ( / c o n s t s o c k e t = .* ?\n \} ; / s, getRolldownClientCode ( ) )
@@ -274,11 +275,11 @@ function patchRuntimePlugin(
274
275
. replace (
275
276
'for (var i = 0; i < module.parents.length; i++) {' ,
276
277
`
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++) {`,
282
283
)
283
284
if ( rolldownDevOptions . reactRefresh ) {
284
285
output . prepend ( getReactRefreshRuntimeCode ( ) )
@@ -318,7 +319,7 @@ function getRolldownClientCode() {
318
319
code += `
319
320
const hot = createHotContext("/__rolldown");
320
321
hot.on("rolldown:hmr", (data) => {
321
- (0, eval)(data[1]);
322
+ (0, eval)(data[1]);
322
323
});
323
324
window.__rolldown_hot = hot;
324
325
`
@@ -360,29 +361,29 @@ function getReactRefreshRuntimeCode() {
360
361
output . replaceAll ( 'process.env.NODE_ENV !== "production"' , 'true' )
361
362
output . replaceAll ( / \b e x p o r t s \. / g, '__react_refresh_runtime.' )
362
363
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
+ `)
387
388
return output . toString ( )
388
389
}
0 commit comments