Skip to content

Commit 02ade43

Browse files
Fix react-refresh source maps (#12686)
Co-authored-by: Mark Dalgleish <[email protected]>
1 parent 372e25f commit 02ade43

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

.changeset/polite-clocks-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Fix react-refresh source maps

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
- soartec-lab
277277
- sorrycc
278278
- souzasmatheus
279+
- soxtoby
279280
- srmagura
280281
- SsongQ-92
281282
- stasundr

packages/react-router-dev/vite/plugin.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,32 +1701,14 @@ function addRefreshWrapper(
17011701
]
17021702
: [];
17031703
return (
1704-
"\n\n" +
1705-
withCommentBoundaries(
1706-
"REACT REFRESH HEADER",
1707-
REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id))
1708-
) +
1709-
"\n\n" +
1710-
withCommentBoundaries("REACT REFRESH BODY", code) +
1711-
"\n\n" +
1712-
withCommentBoundaries(
1713-
"REACT REFRESH FOOTER",
1714-
REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id))
1715-
.replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports))
1716-
.replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
1717-
) +
1718-
"\n"
1704+
REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id)) +
1705+
code +
1706+
REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id))
1707+
.replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports))
1708+
.replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
17191709
);
17201710
}
17211711

1722-
function withCommentBoundaries(label: string, text: string) {
1723-
let begin = `// [BEGIN] ${label} `;
1724-
begin += "-".repeat(80 - begin.length);
1725-
let end = `// [END] ${label} `;
1726-
end += "-".repeat(80 - end.length);
1727-
return `${begin}\n${text}\n${end}`;
1728-
}
1729-
17301712
const REACT_REFRESH_HEADER = `
17311713
import RefreshRuntime from "${virtualHmrRuntime.id}";
17321714
@@ -1747,7 +1729,7 @@ if (import.meta.hot && !inWebWorker) {
17471729
RefreshRuntime.register(type, __SOURCE__ + " " + id)
17481730
};
17491731
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
1750-
}`.trim();
1732+
}`.replaceAll("\n", ""); // Header is all on one line so source maps aren't affected
17511733

17521734
const REACT_REFRESH_FOOTER = `
17531735
if (import.meta.hot && !inWebWorker) {
@@ -1762,7 +1744,7 @@ if (import.meta.hot && !inWebWorker) {
17621744
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
17631745
});
17641746
});
1765-
}`.trim();
1747+
}`;
17661748

17671749
function getRoute(
17681750
pluginConfig: ResolvedReactRouterConfig,

0 commit comments

Comments
 (0)