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 10 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: df8d61c

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we've since disabled the watcher for the Vite Node context. But my point still stands: its better to watch for changes in the app directory and the React Router config directly, rather than watching the root and ignoring paths.

We'd need to take care to add any files that are part of the module graph for the React Router config to the watched files and then clean them up as needed. So there is a bit of complexity to get this working.

@pcattori pcattori force-pushed the markdalgleish/handle-new-config-file branch from 229e181 to df8d61c Compare March 13, 2025 11:41
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