-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Reduce addRoutes function calls #3443
Reduce addRoutes function calls #3443
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there! Good point @grimasod - please check the #3412 which is partially solving this issue but just for the route dispatcher using locking mechanism on the RouterManager level; probably won’t work for the case you have just fixed but just to be sure we’re not duplicating the code for the same issue
I’m not sure if it is reducing the router.addRoutes to just single one (which can obviously solve the multiple routes call once and for all) but maybe we can do it by postponing the registration till very end just before app.mount call(?) the other option is to add a paragraph to the docs on how to use the locking mechanism in the RouteManager level and a note to not use the router hooks directly Or even better - add docs + add a mechanism to register hooks from roterManager level that are locking the calls themselves Then, we need to find all the instances or adding the hooks listeners to router directly and replace them with the wrapper calls from the router manager I think this makes sense as the routermanager is the only class which can be safely used for adding the routes because of the url dispatcher module @filrak ive mentioned you in the other PR regarding passing routermanager instead of router to the module constructors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks nice.
It reduces one of the guards like from 14 times to only once in my testing and all URLs are working like they should.
The only nice thing would be to have some unit tests for these changes.
Hi @pkarw, yeah I saw #3412 and tested after it was merged. It didn't affect this issue. As you suggest, postponing all additions to the end could ensure there was exactly only one addRoutes. I thought about something like that when I started working on this, but it seemed quite complex! And I wonder if it could affect some custom modules or themes? So, I thought the solution in this PR might be more suitable for a hotfix, as it shouldn't have any knock-on effects. It's not 100% perfect, but it's a huge improvement. In our custom theme, it reduced User beforeEach calls from about 750 to just 1 or 2, depending on the page. There's another point to consider (not dealt with in this fix) ... Is it necessary to create routes for all stores? Considering it's not possible to navigate directly between stores. Instead, the app gets reloaded, and all the routes recreated. So only the current store routes need to be added. Right? The exception is SSR for SEO, but that can be handled separately. This also seems like a big change though and could possibly affect some customizations. In the end, I thought this simple fix would be best for 1.10.1 and maybe a bigger update can be planned for 1.11. What do you think? |
@ResuBaka Good point. I haven't done any unit testing work on VS, do you have any suggestions or pointers? |
@grimasod One point would be this test file which we have four the multistore.ts. Then all unit test are under test/unit/<function/file you want to test>.spec.ts inside the folder the to testing file is. Example of the structure: Then the unit test are written in jest (docs) when you need some help you can write me in the slack a dm. Test can be startet with @pkarw @patzick should we maybe backport my fix so more people can use the watch feature of jest in the older version? |
@ResuBaka Thanks. I'll look into it! |
Thinking about this more... isn't it actually incorrect to generate routes for all stores based on the routes of one store? For example:
|
When I think about that we should do, for a quick improvement to your code check if the stores have enabled the appendStoreCode config value because when they don't they most likely have different/need to domains for each store so only mapping stores where the appendStoreCode is set to true would improve this too. |
@ResuBaka Yeah, you're right. Static routes are added using |
This looks really good, I just need a while to test this properly first to be sure :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked it and i think it works nice and fast. @pkarw, would you mind to re-review?
Thanks for the discussion, it was really cool! Great insights 👍
@grimasod how about trying to implement these upgrades? |
Thanks for the feedback :) @pkarw I can work on it, but it won't be soon. I'm releasing our v1.10 site this week and don't have much time for anything else.
|
Sure, 1.11 sounds reasonable @patzick |
Cool; i created a #3454 just for that |
Just stopping by to thank you guys for saving me many more hours of debugging on an unrelated project. Also to add a few observations and keywords for those coming after. Interestingly this only happens with async calls to
Also note that this does not happen in a very simply Vue application such as this fiddle below. It's somehow related to further complexities around how we're bootstrapping up Vue. |
Related issues
closes #3442
Short description and why it's useful
Greatly reduces the number of times the router beforeEach hooks are run
Screenshots of visual changes before/after (if there are any)
Which environment this relates to
Check your case. In case of any doubts please read about Release Cycle
develop
branch and want to merge it back todevelop
release
branch and want to merge it back torelease
hotfix
ormaster
branch and want to merge it back tohotfix
Upgrade Notes and Changelog
IMPORTANT NOTICE - Remember to update
CHANGELOG.md
with description of your changeContribution and currently important rules acceptance