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
fix(nuxt): stop loading indicator if page keys are the same #24931
Conversation
Run & review this pull request in StackBlitz Codeflow. |
@@ -88,6 +89,10 @@ export default defineComponent({ | |||
} | |||
|
|||
const key = generateRouteKey(routeProps, props.pageKey) | |||
if (!nuxtApp.isHydrating && previousPageKey === key) { |
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.
should we use isChangingPage
?
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 don't know π€ , isChangingPage
is relying on to
and from
from a router guard.
This implementation is relying on whether we force rerender the page or not by comparing the generated key.
Do you think we should use a router guard instead ?
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.
Do we want to have a different behavior compared to isChangingPage
for checking? If not, let's use it.
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 think we want to stop the loading indicator only if the setup of the new page won't be run.
Using a router guard with beforeResolve don't necessaraly means that the setup will be re-run π€.
Is there a way to add some tests for loading indicator behaviour and these loading hooks? (Ensuring they are called in the right order, not over-called, etc.) |
We also have the issue on https://nuxt.com/modules when clicking on the categories: https://volta.s3.fr-par.scw.cloud/Clean_Shot_2024_01_02_at_13_24_58_71ddda020b.mp4 (made this temporary fix: nuxt/nuxt.com@8638e00) |
I'm trying to add some tests, but we'd need to at least wait for 300ms to get the failing case on the current main branch. 300ms seems to be way too long for the CI and i can't reduce it otherwise tests are becoming false positive. just FYI, this PR also fix the issue with queries |
@huang-julien FYI - we should also check nested page behavior with the |
@huang-julien Do you think we could reduce that by updating loading indicator props, e.g. |
Yes... this does also stop the loading indicator in nested pages since the higher one will trigger the stop hook...
Sadly it does not work π’ I have some fixtures ready for tests... but the browser used by playwright (is it chrome ?) seems to be veryyyy slow so we need to wait for 300ms before evaluating the opacity of the indicator |
My temporary solution is this: onMounted(() => {
setTimeout(() => {
const loadingIndicator = document.querySelector('.nuxt-loading-indicator');
if (loadingIndicator) {
loadingIndicator.classList.add('!opacity-0')
}
}, 1000);
})
onBeforeUnmount(() => {
const loadingIndicator = document.querySelector('.nuxt-loading-indicator');
if (loadingIndicator) {
loadingIndicator.classList.remove('!opacity-0')
}
}) |
@thezumrad it should already work in 3.9.1 |
Ahah yeah Thanks) |
π Linked issue
fix #24928
fix #25039
β Type of change
π Description
Hi π this PR stops the loading indicator by triggering
page:loading:end
if page keys are the same when re-renderingπ Checklist