Skip to content

Null values for v-text directive not handled in SSR #6572

@pi0

Description

@pi0

Version

2.4.2

Reproduction link

https://glitch.com/edit/#!/v-text

https://v-text.glitch.me/html
https://v-text.glitch.me/text

Steps to reproduce

Try to render <span v-text="x"></span> where x is is null or undefined

What is expected?

It may be gracefully handled just like v-html directive (see notes below) or client side version of v-text.

What is actually happening?

Throwing an internal TypeError:

Cannot read property 'replace' of undefined
function escape (s) {
  return s.replace(/[<>"&]/g, escapeChar)
}

Seems the simple fix would be defining a default value for s parameter in util.js (or better do a string type check on value)

Related to nuxt/nuxt#1638

Some Notes

v-html behaviour also differs in SSR and client. SSR renders v-html: <span>null</span> while it changes into <span></span> on client side. Seems <span v-html="foo"> is being optimized into '<span>' + (_vm.foo). So we can change it into (_vm.foo|| '') to handle this inconsistency during SSR render.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions