-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
[Feature] API for rendering VNodes to string #10183
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
Comments
The feature request text was too large to do through the issue helper |
Sorry about that, the system isn't perfect. Thanks for understanding :) |
This is pretty much a duplicate of your own issue: #9205 (comment) |
I also trying to render Vnode but in the browser so SSR is not an option here. |
Sorry, I wasn't referring to the SSR part, that shouldn't change where the conversation went: It still has to be optional on the client so it doesn't impact other users (rendering vnodes to a string is a niche case itself, even more on the client), like template compilation: it can be used on the client but can be stripped out as well. |
yeah, but the API is already there internally, it just needs to be exposed |
@posva will vue 3 have a feature like this, since they are opening up to a custom renderer API? |
A canonical example for this could be rendering HTML tooltip for V-Tooltip programatically. So it's not that much of a niche use-case. |
The Vue integration for ApexCharts would also benefit from this for custom tooltips since it handles this with a callback that must return raw HTML. |
This comment has been minimized.
This comment has been minimized.
Any news? |
This would be very helpful when wrapping vanilla JS libraries that have APIs for HTMLElement / HTML string. I am in this situation now with AG Grid |
We have a need for this as well when needing to dynamically render content for google map's info window objects. |
Any updates on this? |
In case it's helpful for anyone, it is possible to use Note that Nuxt is only the tool for creating a fast showcase, it's not needed at all. import { createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';
const app = createSSRApp({
data: () => {
return {
title: 'World',
text: 'Laborum quisquam et error magni ut eum fugiat. Deserunt quae magni sed voluptatem ducimus consequatur quae aperiam. Recusandae et ducimus hic quis et excepturi officia. Voluptatem facilis ut quis velit consequatur. Id aspernatur quis est animi eaque corrupti. Iure quod quae nulla omnis molestiae tempora aut voluptatibus.',
};
},
computed: {
getTitle() {
console.log('getTitle');
return this.title;
},
},
template: `
<div>
<h1>Hello {{ getTitle }}</h1>
<p>{{ text }}</p>
</div>`,
});
let htmlString = await renderToString(app); |
Simple example with <script setup lang="ts">
import { renderToString } from 'vue/server-renderer'
import { h } from 'vue'
const htmlString = await renderToString(h('div', 'Hello world'))
</script>
<template>
<span v-html="htmlString" />
{{ htmlString }}
</template>
|
@martinschilliger @kedniko Those work because you are pre-rendering upon compile time, not runtime. SSR functionality is not published with vue js browser runtime. Example: https://stackblitz.com/edit/rendertostring-example-tn5hyf?file=app.vue ![]() |
Ah, I see. I use it in runtime, but in node on the server side. Sorry, thought I had the solution, but I was wrong. 🤯 |
@AlbertMarashi this is done and in vue js prod? |
No I just don't use Vue anymore @johnwc and I haven't been keeping up with it. Feel free to re-open the issue |
What problem does this feature solve?
I've created a
<head>
management system and an awesome feature would be a native way to render VNodes to strings, both in SSR and on client-sideHere's what I've been currently doing in user-land:
hello-world.vue
master.vue
You can probably see some issues with how this is done, it only accounts for a single text node, and there may be more. Plus, it seems hacky to directly access slot data inside a template
The head is currently being stringified by a small component:
servue.vue
This whole process could be simplified by an API exposed by vue. The API already exists, it just needs to be exposed by Vue
What does the proposed API look like?
A few ideas
The text was updated successfully, but these errors were encountered: