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

getSSRProps return value does not pass down innerHTML as dom props #8112

Closed
henkvhest opened this issue Apr 18, 2023 · 5 comments
Closed

getSSRProps return value does not pass down innerHTML as dom props #8112

henkvhest opened this issue Apr 18, 2023 · 5 comments

Comments

@henkvhest
Copy link

Vue version

3.2.47

Link to minimal reproduction

https://stackblitz.com/edit/github-c1z4a8-we3axz?file=src/main.ts

Steps to reproduce

return { innerHTML: 'some value' } from a Vue directive via getSSRProps. innerHTML is then not propagated. (see also stackblitz example)

What is expected?

I expect innerHTML to be defined serverside so that my component is prefilled with content before rendering.

What is actually happening?

The innerHTML is not filled, which means the content stays blank (see stackblitz example)

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Pro
    Memory: 96.88 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.14.2/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 112.0.5615.121
    Firefox: 112.0.1
    Safari: 16.0

Any additional comments?

I'm currently working rewriting some parts of our codebase from Nuxt 2 to Nuxt 3. I initially thought this was related to Nuxt but the same issue is happening in Vue 3 with SSR rendering too. I try to modify the innerHTML serverside but it seems that innerHTML is not propagated. I tried in the stackblitz example to write some content to innerHTML via getSSRProps. I'm not sure if this is a bug or intended behaviour, or perhaps there is a different way to modify innerHTML in getSSRProps?

@mannymu
Copy link

mannymu commented Jun 19, 2023

I use webpack and have the same problem

@mannymu
Copy link

mannymu commented Jun 19, 2023

image

getSSRProps does not support rendering of these properties. But I use v-html in ssr server is normal

@henkvhest
Copy link
Author

Ah good find, seems like it's intentional indeed! I'll close this one

@edison1105
Copy link
Member

I think it needs to be fixed, and this only happens in optimized compilation. For client-compiled render functions it works.

if (props.innerHTML) {

@yyx990803
Copy link
Member

yyx990803 commented Aug 6, 2024

This is fixed by 79602f9

However note that the getSSRProps in the linked reproduction is incorrect - it should be:

app.directive('inner-html', {
    getSSRProps(binding) {
      return {
-       domProps: {
-         innerHTML: 'sanitizeCustom(directiveMeta.value)',
-       },
+       innerHTML: sanitizeCustom(binding.value)
      };
    },
  });

Also, innerHTML and textContent will only be respected if the element has no static children.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants