-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
pendingLoad Cannot read properties of null (reading 'then')
#495
Comments
If |
@minht11 I can't help if you don't share the code relevant to using data loaders. This would be helpful to provide runtime warnings in the future to help users detect problems |
Yes, the code of the page for that route and the code of the components using any of the loaders that is rendered by that page |
I can't share the code, loaders are used in multiple components and levels, not one clean snippet, issue also occurs in multiple pages. |
Yes, please. |
Took a lot of time, but I managed to reproduce it. Issue occurs when one of the loaders throws an error and you try to navigate to same page again. // App.vue
<script lang="ts" setup>
import { ref } from 'vue';
import { RouterView, useRouter } from 'vue-router';
const router = useRouter();
const isError = ref(false);
router.onError(() => {
isError.value = true;
});
const reset = () => {
isError.value = false;
router.push('/');
};
</script>
<template>
<div v-if="isError">
Error happened
<button @click="reset">Login</button>
</div>
<div v-else>
<RouterView />
</div>
</template> // pages/index.vue
<script lang="ts">
import { defineBasicLoader } from 'unplugin-vue-router/data-loaders/basic';
import { useRouter } from 'vue-router';
export const useHomePageData = defineBasicLoader(() => Promise.resolve(true));
</script>
<script lang="ts" setup>
useHomePageData();
const router = useRouter();
const details = () => router.push({ name: '/details' });
</script>
<template>
<button @click="details">Go to details</button>
</template> // pages/details.vue
<script lang="ts">
import { defineBasicLoader } from 'unplugin-vue-router/data-loaders/basic';
export const useDetailsPageData = defineBasicLoader(async () => {
throw new Error('Not implemented');
});
</script>
<script lang="ts" setup>
// Empty
</script>
<template>Details Page</template> Screen.Recording.2024-09-06.at.22.52.13.mov |
Thanks! the online repro is great, no need to paste the code here too when you do that 😄 |
In your case, the issue came down to having the duplicated navigation of |
Yeah duplicated navigation is the cause, we saw in few more cases, not only with errors, but also when clicking the link of the active page on sidebar and later navigating somewhere else would produce an error, though it had some before enter guards and nested layouts. Workaround for that one was just hiding the link, other cases like the one in the repo are trickier, because what should you do after error happens if you can't navigate. |
After upgrade to latest version of unplugin-router-router and using pinia colada, I noticed errors in sentry.
I do not have a reproduction but I narrowed it down to this:
unplugin-vue-router/src/data-loaders/defineLoader.ts
Lines 345 to 350 in fb772a2
Promise is asserted as not being null, but at least from the Sentry errors that is not the case. Maybe it is race condition thing, most of the issues are from android, though I see some macs as well. I haven't seen it myself.
The text was updated successfully, but these errors were encountered: