core icon indicating copy to clipboard operation
core copied to clipboard

fix(runtime-core): only set cache for object keys

Open danielroe opened this issue 2 years ago • 0 comments

Background

On SSR if an unregistered component is used we have a hard crash as we try to cache the details about this component, but it's a string (not a resolved object) and can't be used as a cache key to the WeakMap that's we're using.

It's true this is wrong usage, and there is a helpful warning:

[Vue warn]: Failed to resolve component: SomeThing
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

But there is also a fatal and hard error that occurs:

Fatal error:

Error: WeakMap key must be an object, got comp
    at _evaluate (https://node-2lafe5-dfi279td.w-corp.staticblitz.com/blitz.bff91798029e1af88e01551d056a592b2882b9ac.js:15:286611)
    at <anonymous> (<anonymous>)

Code

import { createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';

const app = createSSRApp({
  template: `<SomeThing />`,
});

console.log(await renderToString(app));

https://stackblitz.com/edit/node-2lafe5?file=index.mjs

danielroe avatar Jul 13 '22 08:07 danielroe