Skip to content

Dev server HMR and *.server.ts naming convention doesn't work with monorepos using shared routes #6711

Description

@jrestall

What version of Remix are you using?

v1.18

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

Minimal Reproduction: https://github.com/jrestall/remix-nx-monorepo/

  1. Create a monorepo using Nx or Turborepo such as Logan's example at https://github.com/mcansh/remix-shared-routes/ that has shared route packages outside the app directory.
  2. Setup the new dev server.
  3. Modify files outside the main app directory and note HMR doesn't work.
  4. Add files outside the main app directory that are used by shared routes that follow the *.server.ts pattern and note they don't get replaced with an empty module.

Expected Behavior

HMR and *.server.ts naming convention works with code outside the app dir that uses shared routes.

Actual Behavior

Following are the areas of code that limit HMR and *.server conventions to only work with routes in the app dir. I'm happy to submit a PR to fix this if a better approach can be agreed.

HMR

!fs.existsSync(args.path) ||
!args.path.startsWith(config.appDirectory))
) {
return undefined;
}

args.path.startsWith(config.appDirectory)
? fs.statSync(args.path).mtimeMs
: undefined

If the goal here is to not add react refresh to node_modules code, could we perhaps explicitly check whether the file is in node_modules instead?

Naming Convention

path
.resolve(args.resolveDir, args.path)
.startsWith(config.appDirectory)
) {
return { path: args.path, namespace: "empty-module" };

Instead of limiting this convention to the app dir, if the goal is to exclude node_modules, could we change it to something like the following?

    !args.path.includes("node_modules")

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions