Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config change handling #12319

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

markdalgleish
Copy link
Member

Note, this is some minor polish that can go out after the initial v7.0.0 release.

This makes the following improvements to react-router.config.ts change handling while the dev server / typegen watch is running:

  • Picks up config changes when react-router.config.ts is created or deleted.
  • Picks up changes to appDirectory and updates the file watcher, unwatching the old directory and watching the new one.

Copy link

changeset-bot bot commented Nov 20, 2024

🦋 Changeset detected

Latest commit: 7a6ffb8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

}
let configCodeChanged =
configFileAddedOrRemoved ||
(typeof reactRouterConfigFile === "string" &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Boolean or !== undefined.

Comment on lines +1096 to +1102
let message = (() => {
if (configChanged) return "Config changed.";
if (routeConfigChanged) return "Route config changed.";
if (configCodeChanged) return "Config saved.";
if (routeConfigCodeChanged) return "Route config saved.";
return "Config saved.";
})();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't help myself, had to see how this looked as a nested ternary

Suggested change
let message = (() => {
if (configChanged) return "Config changed.";
if (routeConfigChanged) return "Route config changed.";
if (configCodeChanged) return "Config saved.";
if (routeConfigCodeChanged) return "Route config saved.";
return "Config saved.";
})();
// prettier-ignore
let message =
configChanged ? "Config changed." :
routeConfigChanged ? "Route config changed." :
configCodeChanged ? "Config saved." :
routeConfigCodeChanged ? "Route config saved." :
"Config saved.";

Feel free to leave as is if you prefer, but I do like the ternary form better / less ceremony

Comment on lines +592 to +596
!dirname.startsWith(appDirectory) &&
// Ensure we're only watching files outside of the app directory
// that are at the root level, not nested in subdirectories
path !== root && // Watch the root directory itself
dirname !== root // Watch files at the root level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we could watch the root for only changes to <root>/react-router.config.ts (and its module graph) and the corresponding app directory, rather than coarse-grained allowlist for any file in the root. But that's not a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this would be relatively easy to do with Vite Node's .devserver.watcher.on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants