Skip to content

Commit b0ed9b7

Browse files
committed
Improve logging
1 parent c28f68e commit b0ed9b7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

packages/react-router-dev/config/config.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ type ChokidarEventName = ChokidarEmitArgs[0];
486486

487487
type ChangeHandler = (args: {
488488
result: Result<ResolvedReactRouterConfig>;
489+
configCodeUpdated: boolean;
489490
routeConfigChanged: boolean;
490491
path: string;
491492
event: ChokidarEventName;
@@ -531,6 +532,8 @@ export async function createConfigLoader({
531532
appDirectory = initialConfigResult.value.appDirectory;
532533
}
533534

535+
let lastConfig = initialConfigResult.value;
536+
534537
let fsWatcher: FSWatcher | undefined;
535538
let changeHandlers: ChangeHandler[] = [];
536539

@@ -562,32 +565,39 @@ export async function createConfigLoader({
562565
event === "change" &&
563566
filepath === path.normalize(reactRouterConfigFile);
564567

565-
let configModuleGraphChanged = Boolean(
568+
let configCodeUpdated = Boolean(
566569
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
567570
);
568571

569-
if (configModuleGraphChanged || appFileAddedOrRemoved) {
572+
if (configCodeUpdated || appFileAddedOrRemoved) {
570573
viteNodeContext.devServer?.moduleGraph.invalidateAll();
571574
viteNodeContext.runner?.moduleCache.clear();
572575
}
573576

574-
// todo: isolate from rest of config
575-
let routeConfigChanged = configModuleGraphChanged;
576-
577577
if (
578578
appFileAddedOrRemoved ||
579579
reactRouterConfigFileChanged ||
580-
configModuleGraphChanged
580+
configCodeUpdated
581581
) {
582582
let result = await getConfig();
583+
584+
let routeConfigChanged =
585+
result.ok &&
586+
!isEqualJson(lastConfig?.routes, result.value.routes);
587+
583588
for (let handler of changeHandlers) {
584589
handler({
585590
result,
591+
configCodeUpdated,
586592
routeConfigChanged,
587593
path: filepath,
588594
event,
589595
});
590596
}
597+
598+
if (result.ok) {
599+
lastConfig = result.value;
600+
}
591601
}
592602
});
593603
}
@@ -629,3 +639,7 @@ function findEntry(
629639

630640
return undefined;
631641
}
642+
643+
function isEqualJson(v1: unknown, v2: unknown) {
644+
return JSON.stringify(v1) === JSON.stringify(v2);
645+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
10811081
});
10821082

10831083
reactRouterConfigLoader.onChange(
1084-
async ({ result, routeConfigChanged }) => {
1084+
async ({ result, configCodeUpdated, routeConfigChanged }) => {
10851085
if (result.ok) {
10861086
let lastReactRouterConfig = ctx.reactRouterConfig;
10871087

@@ -1090,6 +1090,11 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
10901090
clear: true,
10911091
timestamp: true,
10921092
});
1093+
} else if (configCodeUpdated) {
1094+
logger.info(colors.green("Config updated."), {
1095+
clear: true,
1096+
timestamp: true,
1097+
});
10931098
}
10941099

10951100
await updatePluginContext();

0 commit comments

Comments
 (0)