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

Route infos not reloading #292

Closed
jods4 opened this issue Jan 9, 2024 · 2 comments
Closed

Route infos not reloading #292

jods4 opened this issue Jan 9, 2024 · 2 comments
Assignees
Labels
🐞 bug this isn't working as expected

Comments

@jods4
Copy link
Contributor

jods4 commented Jan 9, 2024

I generate a navigation component from vue-router/auto/routes.
When modifying a <route> block, I can see the update callbacks working (e.g. in extendRoute) yet most of the time my app is not properly refreshed. Strangely rarely it seems to work with no visible explanation.

I have a very trivial repro for you here:
https://github.com/jods4/unplugin-router-bug

Below is a video demonstrating the bug and a bit of debugging from my part.
The change handler works (albeit updatePage is called twice for a single save event... maybe a missed opportunity to debounce FS events), and internal structures look updated alright.
It seems to me that the problem is: no code notifies Vite that the virtual module was changed.
And after a bit of manual calls to server.invalidate("vue-router/auto/routes") and server.reload() it actually works!

I observe though that it works forever which kind of hints at why it sometimes persistently works in my project... Looks like the virtual file remains invalidated, maybe there's a missing call to tell Vite the file has been re-"validated" and should be cached?

2024-01-09_01-18-07.mp4

Side notes from my exploration of the source code for this issue:

  • getRouteBlock takes a file path as input and reads it from disk, although its only caller writeRouteInfoToNode already has the contents in a string (passed to extractDefinePageNameAndPath). Looks like unneeded I/O.
  • extractDefinePageNameAndPath only returns name and path? The docs make it sounds like you can use definePage for any purpose, like <route> block:

The macro definePage() allows you to define any extra properties related to the route. It is useful when you need to customize the path, the name, meta, etc

@jods4
Copy link
Contributor Author

jods4 commented Jan 9, 2024

Upon further thinking: I guess uplugin-vue-router should cache the route block value and the definePage argument.

  • so that it performs less work every time I save a file (most of the time unrelated to the router);
  • but more importantly so that it doesn't trigger a reload with every file save, just because "routes may have changed". It needs to be more precise than that to be useable.

@posva posva added the bug label Jan 9, 2024
@settings settings bot removed the bug label Feb 21, 2024
@posva posva added the 🐞 bug this isn't working as expected label Feb 21, 2024
@posva posva moved this from 🆕 New to 🔖 Ready in unplugin-vue-router May 20, 2024
@posva posva moved this from 🔖 Ready to 📋 Backlog in unplugin-vue-router May 20, 2024
@posva posva moved this from 📋 Backlog to 🔖 Ready in unplugin-vue-router Jun 18, 2024
posva added a commit that referenced this issue Jun 18, 2024
@posva posva self-assigned this Jun 18, 2024
@posva posva closed this as completed in 4925e7e Jun 21, 2024
@github-project-automation github-project-automation bot moved this from 🔖 Ready to ✅ Done in unplugin-vue-router Jun 21, 2024
@nhatphamcdn
Copy link

It seems there’s a bit of an issue with nested folders. Specifically:

When I place the pages in src/pages and register it in routesFolder, everything works fine. However, when I try to restructure the folders and place pages inside other modules, for example: src/modules/authen/pages
and then change the meta in the route block, it stops working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug this isn't working as expected
Projects
Archived in project
Development

No branches or pull requests

3 participants