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

page:finish hook won't be triggered #102

Closed
sxzz opened this issue May 6, 2024 · 8 comments · Fixed by #106
Closed

page:finish hook won't be triggered #102

sxzz opened this issue May 6, 2024 · 8 comments · Fixed by #106
Labels
quirk Extra attention is needed

Comments

@sxzz
Copy link

sxzz commented May 6, 2024

If ssr option is disabled, then page:finish hook won't be triggered.

'page:finish': function () {
const { autoTrack } = umConfig.value;
if (!autoTrack)
return;
setTimeout(umTrackView, 300);

@ijkml
Copy link
Owner

ijkml commented May 6, 2024

Oh, boy... I'll look into this, thanks @sxzz.

@ijkml
Copy link
Owner

ijkml commented May 7, 2024

Hello again, @sxzz.
I finally had a chance but I couldn't reproduce it. The hook seems to trigger with ssr: false 🤷.
Anyway, could you take a look at this repro and let me know if I missed something?
https://stackblitz.com/edit/nuxt-umami?file=nuxt.config.ts

Thanks, again.

@sxzz sxzz changed the title page:finish hook won't be triggered if SSR is disabled page:finish hook won't be triggered May 12, 2024
@sxzz
Copy link
Author

sxzz commented May 12, 2024

Seems not relate to SSR, but relate to Suspense

Minimal reproduction repo: https://github.com/sxzz/nuxt-page-finish

@ijkml
Copy link
Owner

ijkml commented May 15, 2024

Yeah, you're right. It is related to Suspense.
But, the hook triggers when you add <NuxtPage />.
Repo: https://github.com/ijkml/nuxt-page-finish

Will look into how much of an effect this has 'cause the code is for autoTrack (useful when you have pages).

'page:finish': function () {
const { autoTrack } = umConfig.value;
if (!autoTrack)
return;
setTimeout(umTrackView, 300);

How did you find the bug, please?

@sxzz
Copy link
Author

sxzz commented May 15, 2024

I have an SPA project that doesn't automatically track pages. To fix this, I manually added another plugin using app:mounted hook.

https://github.com/sxzz/ast-explorer/blob/main/plugins/umami.ts

@ijkml
Copy link
Owner

ijkml commented May 15, 2024

Absolutely right, it is a <NuxtPage> / Suspense thing.

I'm stuck. Do you have any suggestions on a fix for this?

Also, instead of a plugin, onMounted(() => umTrackView()) in app.vue might work, no?

@sxzz
Copy link
Author

sxzz commented May 16, 2024

Of course, it works. Can we use hook app:mounted (with 300ms delay), instead of page:finish?

@ijkml
Copy link
Owner

ijkml commented May 18, 2024

Unfortunately, no.
app:mounted is only triggered once (https://nuxt.com/docs/api/advanced/hooks#app-hooks-runtime).

Mean time, I would add this behavior to faqs/quirks 👍.

@ijkml ijkml added the quirk Extra attention is needed label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quirk Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants