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

fix(nuxt): stop loading indicator if page keys are the same #24931

Merged
merged 6 commits into from Jan 5, 2024

Conversation

huang-julien
Copy link
Member

@huang-julien huang-julien commented Dec 27, 2023

πŸ”— Linked issue

fix #24928
fix #25039

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Hi πŸ‘‹ this PR stops the loading indicator by triggering page:loading:end if page keys are the same when re-rendering

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

stackblitz bot commented Dec 27, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the 3.x label Dec 27, 2023
@huang-julien huang-julien self-assigned this Dec 27, 2023
@@ -88,6 +89,10 @@ export default defineComponent({
}

const key = generateRouteKey(routeProps, props.pageKey)
if (!nuxtApp.isHydrating && previousPageKey === key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use isChangingPage?

Copy link
Member Author

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 ?

Copy link
Member

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.

Copy link
Member Author

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 πŸ€”.

@danielroe
Copy link
Member

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.)

Copy link
Member

Atinux commented Jan 2, 2024

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)

@huang-julien
Copy link
Member Author

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

@manniL
Copy link
Member

manniL commented Jan 4, 2024

@huang-julien FYI - we should also check nested page behavior with the back button. Ideally this PR solves that too (see #25039)

@danielroe
Copy link
Member

@huang-julien Do you think we could reduce that by updating loading indicator props, e.g. throttle and duration?

@huang-julien huang-julien marked this pull request as draft January 4, 2024 19:37
@huang-julien
Copy link
Member Author

huang-julien commented Jan 4, 2024

@huang-julien FYI - we should also check nested page behavior with the back button. Ideally this PR solves that too (see #25039)

Yes... this does also stop the loading indicator in nested pages since the higher one will trigger the stop hook...

@huang-julien Do you think we could reduce that by updating loading indicator props, e.g. throttle and duration?

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

@danielroe danielroe merged commit fd812ef into main Jan 5, 2024
34 checks passed
@danielroe danielroe deleted the fix/anchor-loadingstate branch January 5, 2024 10:07
@github-actions github-actions bot mentioned this pull request Jan 5, 2024
@thezumrad
Copy link

thezumrad commented Jan 12, 2024

My temporary solution is this:
Just hiding it for a certain page

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')
}
})

@manniL
Copy link
Member

manniL commented Jan 12, 2024

@thezumrad it should already work in 3.9.1 ☺️

@thezumrad
Copy link

Ahah yeah
I've 3.9.0. Did not pay attention

Thanks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants