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

New routes not detected on Windows #59

Closed
1 task done
xHomu opened this issue Jul 3, 2023 · 10 comments
Closed
1 task done

New routes not detected on Windows #59

xHomu opened this issue Jul 3, 2023 · 10 comments

Comments

@xHomu
Copy link

xHomu commented Jul 3, 2023

Noticed this with Epic Stack and was able to nail down the issue as remix-flat-routes. Weird that no one caught this before:

What version of Remix are you using?

v1.18.1

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

  • Yes

Steps to Reproduce

(As a sanity check, I was able to confirm that this is unrelated to v2_dev server.)

  1. On a Windows environment, clone the bug repo https://github.com/xHomu/remix-v2-server/tree/flat-route-bug
  2. npm install; npm run dev
  3. Create app/routes/test.tsx and a basic export default component.
  4. Visit localhost:3000/test

Expected Behavior

See the test route.

Actual Behavior

404 Not Found thrown.

image

  • If we restart the dev server manually, localhost:3000/test renders correctly.
  • Edits to existing route files work as expected.
  • If we comment out flat routes in remix.config and repeat steps 1-4, localhost:3000/test renders correctly without error.

Possible related issue from remix core: https://github.com/remix-run/remix/pull/6293/files

@kiliman
Copy link
Owner

kiliman commented Jul 4, 2023

Ok, there are a couple of things.

  1. It appears that Remix wants the filename normalized to / separators, even on Windows. I normalize the route id, but keep the filename as the original path. I'll update that.
  2. In your remix.config, you need to make sure you to update ignoredRoutesFiles to ['**/*'] (ignore all files). Otherwise, the v2 convention will pick them up. You can still ignore files by passing them in options to the flatRoutes() function.

In the meantime, here's a workaround to fix the issue. It simply replaces the path separator before returning to Remix.

// route.config.js

  routes: async (defineRoutes) => {
    const routes = flatRoutes("routes", defineRoutes, {ignoredRouteFiles: ["**/.*"],});
    Object.keys(routes).forEach(key => routes[key].file = routes[key].file?.replace(/\\/g, '/'))
    return routes
  },

@xHomu
Copy link
Author

xHomu commented Jul 4, 2023

Ops, fixed #2. Any idea why this only occurs during dev and not if we manually restart?

@kiliman
Copy link
Owner

kiliman commented Jul 4, 2023

I just updated my comment with a workaround fix. I have a feeling the new dev server expects / paths only to determine if it was a route file that changed.

@kiliman
Copy link
Owner

kiliman commented Jul 4, 2023

Let me know if that fixes the issue, and I'll be sure to include that in the next update.

@xHomu
Copy link
Author

xHomu commented Jul 4, 2023

Can confirm the workaround, worked! Nice! I assume this will get pushed on the next package update?

@xHomu
Copy link
Author

xHomu commented Jul 4, 2023

Before I forgot, Happy Independence Day!

@kiliman
Copy link
Owner

kiliman commented Jul 4, 2023

Thanks. Yeah, I've got a couple of other changes then I'll push out the fix.

@xHomu
Copy link
Author

xHomu commented Jul 4, 2023

Will the next package be released pretty quickly, or we should go ahead and implement the workaround for now for the Epic Stack?

@kiliman kiliman closed this as completed in 7df24c7 Jul 4, 2023
@kiliman
Copy link
Owner

kiliman commented Jul 4, 2023

Ok, I pushed out v0.5.9 which includes the fix.

@xHomu
Copy link
Author

xHomu commented Jul 4, 2023

Can confirm v0.5.9 fixed the bug. Thanks again, @kiliman!

xHomu added a commit to manawiki/mana that referenced this issue Jul 4, 2023
xHomu added a commit to manasites/starrail that referenced this issue Jul 4, 2023
* Fix windows new route bug

kiliman/remix-flat-routes#59

* bump headlessui

* Update yarn.lock

Becoming quite garbled, so deleted and recreated yarn.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants