Skip to content

Templates do not use toString() on objects #3944

Closed
@chemicalcrux

Description

@chemicalcrux

Version

3.1.1

Reproduction link

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE+e3sgbXNnIH19PC9oMT5cbiAgPGgxPnt7IG90aGVyTXNnIH19PC9oMT5cbiAgPGgxPnt7IG1zZy50b1N0cmluZygpIH19PC9oMT5cbiAgPGgxPnt7IG90aGVyTXNnLnRvU3RyaW5nKCkgfX08L2gxPlxuPC90ZW1wbGF0ZT5cblxuPHNjcmlwdCBzZXR1cD5cbmNvbnN0IG1zZyA9IHtcbiAgZm9vOiBcImJhclwiXG59XG5tc2cudG9TdHJpbmcgPSAoKSA9PiBcIkhlbGxvXCJcbiAgXG5jbGFzcyBUZXN0IHtcbiAgY29uc3RydWN0b3IgKCkge1xuICAgIHRoaXMuYmF6ID0gXCJidXpcIlxuICB9XG4gIHRvU3RyaW5nICgpIHtcbiAgICByZXR1cm4gXCJXb3JsZFwiXG4gIH1cbn1cbiAgXG5jb25zdCBvdGhlck1zZyA9IG5ldyBUZXN0KClcbjwvc2NyaXB0PiJ9

Steps to reproduce

  1. Render an object in a template that has a non-default toString() method

What is expected?

In Vue 2, the template would render with the result of calling toString() on the object.

It would check if the object's toString property was different from Object.toString.

https://github.com/vuejs/vue/blob/dev/src/shared/util.js#L81

What is actually happening?

In Vue 3.1.1, the template renders with the result of running JSON.stringify on the object.

It only checks that it's working with an object.

https://github.com/vuejs/vue-next/blob/master/packages/shared/src/toDisplayString.ts


This feels like a breaking change, but I don't see it listed anywhere. Confusingly, however, I've also seen zero people talking about this being a problem!

Obviously, I can just call .toString() everywhere that I was relying on this behavior, but that's a bit tedious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has workaroundA workaround has been found to avoid the problemneed guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions