vuejs / repl

Vue SFC REPL as a Vue 3 component
https://repl-vuejs.vercel.app
MIT License
930 stars 172 forks source link

fix: console logging for component instance proxies #62

Closed skirtles-code closed 1 year ago

skirtles-code commented 1 year ago

Console logging currently fails when the logged value is a component instance proxy:

SFC Playground Example

Those proxies cannot be passed to String() without throwing the error:

TypeError: Cannot convert object to primitive value

There were a couple of places that potentially pass those proxies to String(). The first (line 134) could be removed and replaced by a typeof check. The second I have replaced with a toString() helper function that handles error cases more gracefully.

The stringify function also caused problems because it attempts to enumerate the component's properties, leading to a warning. I've tweaked that to avoid that warning.

I've also moved the call to the original log function higher up. This helps to ensure that it still happens, even if an unexpected error occurs in the other code.