Skip to content

Data loaders inside nested layouts with params causes undefined data error when existing page in prod and with HRM. #567

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

Open
minht11 opened this issue Jan 12, 2025 · 8 comments
Labels
⚡️ enhancement improvement over an existing feature

Comments

@minht11
Copy link

minht11 commented Jan 12, 2025

For a while I noticed errors in production environment, only on pages which had dynamic page params. Not all of the users had the errors and it was very hard to reliably reproduce it, likely timing related. Except the same error could be observed under specific circumstances with HMR.

Basic loader fails instantly on the same page or on the next navigation.

Screen.Recording.2025-01-13.at.00.01.51.mov

Colada loader fails on next navigation. Feels like previous page data is being cleared too early, while component is still mounted.

Screen.Recording.2025-01-13.at.00.04.12.mov

Reproduction

@posva posva added the ⚡️ enhancement improvement over an existing feature label Jan 15, 2025
@posva
Copy link
Owner

posva commented Jan 15, 2025

Thanks for the repro. How do you know this is the same issue in prod? Any way to reliably reproduce it? I don't think they are related.

@posva posva moved this from 🆕 New to 📋 Backlog in unplugin-vue-router Jan 15, 2025
@minht11
Copy link
Author

minht11 commented Jan 15, 2025

I am getting issues on Sentry Cannot read properties of undefined ... on multiple routes, where loader value is accessed.
Not all of them use dynamic params, but all of them have nested layouts.

When making a reproduction, specific requirement have had to be met for error to occur, like loader inside component, nested layout and so on.

I've seen error myself, but only very rarely and by accident. This is how I narrowed issue with HRM, but was unable to reproduce it consistently without it.

@posva
Copy link
Owner

posva commented Jan 15, 2025

Thanks for the feedback. I will research it a bit but I think both issues are unrelated so fixing this might not fix the actual prod issue

@ERPedersen
Copy link

I am experiencing the same issue. Only happens on our prod environment, and seems timing related.

@minht11 did you find any way to circumvent this?

@minht11
Copy link
Author

minht11 commented Jan 29, 2025

No not yet. Didn't have a lot of time to investigate further.

@ERPedersen
Copy link

I managed to find a fix for my own case.

The issue was happening to me, because I had one loader that was dependent on three other loaders.

const a = await useLoaderA()
const b = await useLoaderB()
const c = await useLoaderC()

Wrapping their calls in a Promise.all fixed the issue.

const [a, b, c] = await Promise.all([
  useLoaderA(),
  useLoaderB(),
  useLoaderC(),
])

Not sure exactly why.

@minht11
Copy link
Author

minht11 commented Jan 29, 2025

Were you using them like this?

defineLoader(() => {
const [a, b, c] = await Promise.all([
  useLoaderA(),
  useLoaderB(),
  useLoaderC(),
])
})

In my own codebase I don't seem to have nested loaders.

@posva
Copy link
Owner

posva commented Jan 29, 2025

@ERPedersen can you share the code of the loaders? This could be key to reproduce the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ enhancement improvement over an existing feature
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants