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
Failed to execute 'insertBefore' on 'Node':
with useAsyncData and Pre-Rendering
#27060
Comments
I'm guessing this issue might be related to #13350. Would you like to try the following method? It may help solve the error you encountered. <script setup>
const asyncData = useAsyncData('blog', () => $fetch('/api/blog'))
const { data } = asyncData
if (import.meta.server) {
const { error } = await asyncData
if (error.value) {
throw createError({
statusCode: 404,
statusMessage: 'Blog Posts Not Found',
fatal: true,
})
}
}
</script> |
Would you be able to provide a reproduction? 🙏 More infoWhy do I need to provide a reproduction?Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. What will happen?If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If How can I create a reproduction?We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as minimal as possible. See more details in our guide. You might also find these other articles interesting and/or helpful: |
Thanks, @Mini-ghost. Unfortunately, it does not solve the issue. Now, when I am in In the generated build, it also does not work and the errors are: Why is there a 404 error in the generated-version? Isn't that supposed to be loaded in the SSR-Process? |
I apologize, but I suspect this issue might be related to other components in your project. The method provided above is merely a workaround and does not truly solve the problem. If you could provide a minimal reproducible example, other developers in the community might be better able to help you clarify the issue. |
I am currently traveling. I will provide a reproduction early next week. Thanks for the help, everyone. |
Update: I created a reproduction of this issue and removed things that are unrelated to the /blog issue. @Mini-ghost seems to be right - the problem stops and everything seems to be okay. Here is the deployment of the branch: https://66447bc136ba9b78c1cebb85--cute-duckanoo-2e84be.netlify.app/blog Blog-Content is pre-rendered perfectly. No issue is visible and the content is shown. I will go on and try to localize which component/module caused the issue. |
Update 2: I spent another couple of hours and was able to locate the issue: I noticed that for some page navigation it worked (blog content loaded) and for some the error (insertBefore) occurred. The failing pages can one thing in common: I used a layout with a fancy SVG issue. So I went ahead and removed all svg-backgrounds and surprisingly the error stopped and the page is now loading the prerendered content perfectly: https://prisma-steuerberatung.netlify.app/blog Here is how I used the layouts in <script lang="ts" setup>
definePageMeta({
layout: 'with-background',
})
useHead({
htmlAttrs: {
class: 'bg-image-2',
},
})
</script>
File: <template>
<div class="layout-with-background">
<HeaderComponent />
<slot />
</div>
</template>
<script setup>
</script>
<style>
.layout-with-background {
@apply bg-cover bg-top bg-no-repeat;
background-image: url('~/assets/background_1.svg?inline');
}
</style>
I tried both: with Interestingly, I also removed almost everything from the layout and the error still came. So it might not even be related to SVG-Backgrounds but some issue with the layout. <template>
<div class="layout-with-background">
<HeaderComponent />
<slot />
</div>
</template> Any clue what might cause the issue? |
I found the reason by comparing my layouts and reading the docs again:
Unfortunately, my layouts did not have one root-node. This caused the problem. I am so glad it is working now 🎉 Suggestion: Can Nuxt show a console error if layout does not have a single root element? |
Environment
Reproduction
Link: https://prisma-steuerberatung.netlify.app/blog
I can try to produce a reproduction with Stackblitz if that helps to share the code.
Describe the bug
Hi!
I have created a website that uses SSR and Prerendering. Everything works locally when using
dev
, but a strange problem appears when I deploy it to Netlify or preview the build locally viaserve
.Here is the issue:
Here is a GIF of the issue:
Link to test it yourself: https://prisma-steuerberatung.netlify.app/blog
What am I doing wrong here?
Any help appreciated 🙏
Additional context
Here is the code of the index.vue to load the blogposts:
There are also similar issues like #24045 or #13656 where this error occured.
Logs
The text was updated successfully, but these errors were encountered: