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

Open
jods4 opened this issue Jan 9, 2024 · 1 comment
Open

Route infos not reloading #292

jods4 opened this issue Jan 9, 2024 · 1 comment
Labels
🐞 bug this isn't working as expected

Comments

@jods4
Copy link

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
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
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
None yet
Development

No branches or pull requests

2 participants