vue-dompurify-html: Contents not rendered at server-side with nuxt.
Hello,
thanks for the great plugin!
It seems that when doing static site generation (SSG) on the server-side (I suspect it also applies for the SSR use case), any HTML injected into the dom via dompurify-html will not be present in the pre-rendered HTML.
Sure, the content will be added to the DOM after the initial page visit at hydration time, but that causes multiple layout shifts as content come into the page increasing our CLS performance metric massively, not only offering a worse experience to the users but also affecting our SEO ranking. Another (possible) SEO hit comes more directly because the original HTML is missing crucial content.
FYI I’ve already seen this closed MR https://github.com/LeSuisse/vue-dompurify-html/pull/591
Tested with vue-dompurify-html v2.5.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 30 (10 by maintainers)
Commits related to this issue
- Allow to specify a custom DOMPurify instance builder This make possible for server-side users (e.g. Nuxt) to instantiate DOMPurify with JSDOM. See #1917. — committed to LeSuisse/vue-dompurify-html by LeSuisse 4 years ago
- Allow to specify a custom DOMPurify instance builder This make possible for server-side users (e.g. Nuxt) to instantiate DOMPurify with JSDOM. See #1917. — committed to LeSuisse/vue-dompurify-html by LeSuisse 4 years ago
- Allow to specify a custom DOMPurify instance builder This make possible for server-side users (e.g. Nuxt) to instantiate DOMPurify with JSDOM. The README has been update to describe the setup. See ... — committed to LeSuisse/vue-dompurify-html by LeSuisse 4 years ago
- Allow to specify a custom DOMPurify instance builder This make possible for server-side users (e.g. Nuxt) to instantiate DOMPurify with JSDOM. The README has been update to describe the setup. See ... — committed to LeSuisse/vue-dompurify-html by LeSuisse 4 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
- feat: Bring support for SSR props Related to #1917 — committed to LeSuisse/vue-dompurify-html by LeSuisse 2 years ago
Nuxt 3 SSR support would be awesome.
I have some stashed change for this I just need the combination of time and motivation to finish it. I cannot accept the PR as is because it will pull
jsdominto the dependency tree of everybody even if they do not use Nuxt/need SSR.hi there, do you have any update?
Nice, I can take a look next week.
@LeSuisse, sorry for tagging you. Could you please review the linked PR? 😉❤️
Edit: PR closed, please see this comment https://github.com/LeSuisse/vue-dompurify-html/issues/1917#issuecomment-2834517732
Understood. Thanks for letting me know. I’ll watch this issue in case the feature is added in the future.
It’s worth sharing here, that many (most?) nuxt users fetch page data from a CMS, which very often contains HMTL (as rich text that non-technical CMS users author on a CMS word-like text editor) that needs to be injected into the page and be present at server-side generation.
And of course, given that injected HTML is expected to be everywhere for CMS-driven websites, sanitization on every page is a no-brainer.
So I’m impressed this issue hasn’t come up before, because it sounds to me that my use case should be the main “target group” of this plugin. I could be wrong of course.
Thanks for taking the time to respond! 🙏
You can now ask to
vue-dompurify-htmlto set thegetSSRPropshook via the configuration startingvue-dompurify-html5.3.0.https://github.com/LeSuisse/vue-dompurify-html/tree/main/packages/vue-dompurify-html#usage-with-nuxt-3
works fine with ssr support and isomorphic-dompurify seems drop-in-replacement 👍
Running into the same issue in Nuxt 3. It would indeed be very nice to get a Nuxt 3 plugin for this. I cannot get the example above by @marcinkozaczyk to work either. Elements using the directive just turn out empty after being server-side rendered, so I’m getting lots of hydration mismatches everywhere. If I add
console.log(innerHTML)just before the return statement, I do see rendered HTML in the CLI, it’s just not inserted into the element that uses thev-dompurify-htmldirective.Might be related to this? https://github.com/vuejs/core/issues/8112
@LeSuisse did you already try to get this to run in nuxt 3 when using SSR mode? It looks like the bundleRenderer is not as easily accessible anymore compared to Nuxt 2, though maybe I haven’t found the right documentation, yet. I’ll fiddle around in the next days, but I’d appreciate any information that you have. Thank you.
Thanks for the PR @serialine!
Hi,
I did some changes to expose the necessary primitive so the directive can be also used on the server side. You can see the setup here: https://github.com/LeSuisse/vue-dompurify-html/tree/vue-legacy#server-side
I will take a look to provide a Nuxt module for the v3 to make the setup easier.