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

Error when unmounting after ssr if async component not loaded yet #3787

Closed
danelowe opened this issue May 17, 2021 · 1 comment
Closed

Error when unmounting after ssr if async component not loaded yet #3787

danelowe opened this issue May 17, 2021 · 1 comment
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr

Comments

@danelowe
Copy link

danelowe commented May 17, 2021

Version

3.1.0-beta.3

Reproduction link

https://github.com/danelowe/vite-ssr-lazy-component

Steps to reproduce

  • Clone reproducer.
  • Run npm run dev
  • Load the index page in browser directly from ssr (i,e, refresh on /)
  • Navigate to about page

What is expected?

Displays the about page with no error

What is actually happening?

Error:

Uncaught (in promise) TypeError: instance is null
    unmountComponent runtime-core.esm-bundler.js:4818
    unmount runtime-core.esm-bundler.js:4736
    unmountChildren runtime-core.esm-bundler.js:4864
    unmount runtime-core.esm-bundler.js:4754
    unmountComponent runtime-core.esm-bundler.js:4835
    unmount runtime-core.esm-bundler.js:4736
    resolve runtime-core.esm-bundler.js:1328
    registerDep runtime-core.esm-bundler.js:1452
    promise callback*registerDep runtime-core.esm-bundler.js:1414
    mountComponent runtime-core.esm-bundler.js:4213
    processComponent runtime-core.esm-bundler.js:4182

In. 3.1.0-beta.3

Uncaught (in promise) TypeError: vnode is null
    unmount runtime-core.esm-bundler.js:5619
    unmountComponent runtime-core.esm-bundler.js:5733
    unmount runtime-core.esm-bundler.js:5634
    unmountChildren runtime-core.esm-bundler.js:5762
    unmount runtime-core.esm-bundler.js:5652
    unmountComponent runtime-core.esm-bundler.js:5733
    unmount runtime-core.esm-bundler.js:5634
    resolve runtime-core.esm-bundler.js:1672
    registerDep runtime-core.esm-bundler.js:1796

I took the example at https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue, removed the dep-import-type dependency, added vite as a dependency. then modified the import of the Foo component to chain it's loading to an unresolved promise when rendering client-side.

The intention is to lazy-load/hydrate some components client-side, so any tips on how to achieve this would be appreciated.

In any case, I think this is a significant bug as it would cause errors when navigating before components are able to be loaded.

@HcySunYang HcySunYang added 🐞 bug Something isn't working ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. scope: ssr labels May 18, 2021
@HcySunYang
Copy link
Member

This is a minimized repro:

const AsyncComp = defineAsyncComponent(() => new Promise((r) => {}))

const CompA = defineComponent({
  render: () => h(AsyncComp)
})

const CompB = defineComponent({
  render: () => 'foo'
})

createSSRApp({
  setup() {
    const comp = shallowRef(CompA)

    return () => {
      return [
        h(comp.value),
        h('button', { onClick() { comp.value = CompB } }, 'click me')
      ]
    }
  }
}).mount('#app')

Use the following html as server-side rendering content

<div id="app"><!--[--><div></div><button>click</button><!--]--></div>

@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr
Projects
None yet
Development

No branches or pull requests

2 participants