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

Vue SSR fails with innerHTML #6519

Closed
nickmessing opened this issue Sep 5, 2017 · 9 comments
Closed

Vue SSR fails with innerHTML #6519

nickmessing opened this issue Sep 5, 2017 · 9 comments
Labels

Comments

@nickmessing
Copy link
Member

nickmessing commented Sep 5, 2017

Version

2.4.2

Reproduction link

https://github.com/nickmessing/vue-ssr-issue

Steps to reproduce

Use domPropsInnerHTML in JSX or v-html in Vue Template.

Or:

What is expected?

No warning in console.

What is actually happening?

DOM Mismatching error.


v-html works fine when there are no children, but fails if there are.

One option is to completely ignore innerHTML and v-html in vue-ssr. Basically commenting this line solves the problem.

Another option is evaluating innerHTML before comparing DOM snapshots so you get value from innerHTML on static SSR-rendered website without DOM Mismatch.

Third option is ignoring children in createElment if there is innerHTML domProp. I think this one is the best.

@yyx990803
Copy link
Member

Probably related to #6490?

@nickmessing
Copy link
Member Author

@yyx990803, yes, it's same error.

@nickmessing
Copy link
Member Author

@yyx990803, thank you, will check with JSX

@yyx990803
Copy link
Member

@nickmessing should work JSX too since v-html is basically an alias for domProps: innerHTML. Feel free to PR for a JSX test case

@panganibanpj
Copy link

panganibanpj commented Oct 12, 2017

Still seeing an error if i replace the <h1>Hey</h1> in index.vue and <h2>Hey</h2> in jsx.vue with with &quot;<svg><path/></svg>

server innerHTML:  &quot;<svg><path/></svg>
client innerHTML:  "<svg><path></path></svg>

EDIT: my mistake, it looks to only be an issue in jsx.vue. but i've also noticed &quot; breaks it too

@tmorehouse
Copy link

tmorehouse commented Nov 14, 2017

@yyx990803 I ran into a similar issue in a functional component using innerHTML to render the entity &times;.

The &times; is the default value for a functional component prop (which can be changed to other HTML markup by the user)

SSR renders the inner HTML as &times;, but the browser when using innerHTML converts some entities to actual UTF-8 characters (i.e. &times; is converted by the browser, via native innerHTML, to ×)

Ultimately this causes rehydration to bail and re-render the component (and spew errors in dev mode)

A few other HTML entities can also fail hydration when used in innerHTML: &hellip;, &raquo;, &laquo;, etc.

Minimal markup to recreate SSR hydration bail issue:

export default {
  functional: true,
  props: {
    icon: { type: String, default '&times;' }
  },
  render(h, { props }) {
    return h('button', { domProps: { innerHTML: props.icon } });
  }
}

using a SFC template, (non functional component with v-html) the issue doesn't appear.

@yyx990803
Copy link
Member

@tmorehouse please open a separate issue.

ztlevi pushed a commit to ztlevi/vue that referenced this issue Feb 14, 2018
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
@naimlatifi5
Copy link

naimlatifi5 commented Nov 6, 2019

Hi,
I have an issue when working on transforming data that I receive from server. Let's say that server send data as string html content: <h1>Hi<h1> I want then to do some transformation in this element and add a data attribute like content: <h1 data-name="title">Hi with data attribue</h1> and render that in component with data attribute SSR .
Any idea how can I achieve this?
I appreciate any help!

@Alinawaz-786
Copy link

Alinawaz-786 commented Nov 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants