Subscribe on changes!

Failed to execute 'insertBefore'

avatar
Jun 2nd 2022

Vue version

3.2.36

Link to minimal reproduction

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8ZGl2PlxuICAgIDxkaXY+XG4gICAgICA8Rm9vIHYtaWY9XCJ0YWIgPT09IDJcIj48L0Zvbz5cbiAgICAgIDwhLS0gcmVtb3ZlIHRoaXMgbGluZSBjYW4gZml4IGVycm9yIC0tPlxuICAgIDwvZGl2PlxuICA8L2Rpdj5cbjwvdGVtcGxhdGU+XG5cbjxzY3JpcHQgbGFuZz1cInRzXCIgc2V0dXA+XG5pbXBvcnQgeyBkZWZpbmVDb21wb25lbnQsIHJlZiB9IGZyb20gJ3Z1ZSc7XG5cbmNvbnN0IHRhYiA9IHJlZigxKTtcbmNvbnN0IEZvbyA9IGRlZmluZUNvbXBvbmVudCh7IGFzeW5jIHNldHVwKCkgeyB9IH0pO1xuXG5sZXQgaW50ZXJ2YWwgPSBzZXRJbnRlcnZhbCgoKSA9PiB7XG4gIHRhYi52YWx1ZSsrXG4gIGNvbnNvbGUubG9nKHRhYi52YWx1ZSk7XG4gIGlmICh0YWIudmFsdWUgPj0gMykge1xuICAgIGNsZWFySW50ZXJ2YWwoaW50ZXJ2YWwpO1xuICAgIGNvbnNvbGUubG9nKCdjbGVhckludGVydmFsJyk7XG4gIH1cbn0sIDEwKTtcbjwvc2NyaXB0PlxuIiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge1xuICAgIFwidnVlXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3Z1ZS5ydW50aW1lLmVzbS1icm93c2VyLmpzXCIsXG4gICAgXCJ2dWUvc2VydmVyLXJlbmRlcmVyXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3NlcnZlci1yZW5kZXJlci5lc20tYnJvd3Nlci5qc1wiXG4gIH1cbn0ifQ==

Steps to reproduce

Open the reproduce link, or paste below code to SFC playground.

<template>
  <div>
    <div>
      <Foo v-if="tab === 2"></Foo>
      <!-- remove this line can fix error -->
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineComponent, ref } from 'vue';

const tab = ref(1);
const Foo = defineComponent({ async setup() { } });
const interval = setInterval(() => {
  tab.value++
  console.log(tab.value);
  if (tab.value >= 3) {
    clearInterval(interval);
  }
}, 10);
</script>

What is expected?

No error showing.

What is actually happening?

Got error report Uncaught (in promise) DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node..

System Info

No response

Any additional comments?

Remove <!-- remove this line can fix error --> can fix the error.

avatar
Jun 2nd 2022

I feel this is not a bug, because A component with async setup() must be nested in a <Suspense> in order to be rendered

image

but the error is not handled😉.

image

Example

avatar
Jun 18th 2022

have the same problem

avatar
Jun 18th 2022

Well, read the warning and act accordingly:

a) switch away from setup async to normal setup, or b) add a Suspense boundary.

avatar
Jun 18th 2022

The problem occurs in a bit of complex code, I'll try to update the example to exclude defineComponent({ async setup() { } });.

avatar
Aug 29th 2022

Sorry for late 🙏, close this for now before I provide minimal reproduction.