Code Monkey home page Code Monkey logo

Comments (6)

harlan-zw avatar harlan-zw commented on August 20, 2024 2

Hey @SquirrelCoder, thanks for the issue.

I've looked at the repo and it looks like an issue with your setup. You are creating a new head instance after the tags have been rendered in _default.page.server.ts.

const appHtml = await renderToString(app);
const head = createHead(); // this is going to reset all collected head data
const { headTags, htmlAttrs, bodyAttrs, bodyTags } = await renderHeadToString(head);

If you need the head instance you should either create it exclusively in this file or you can return it from createApp.

  const { app, head } = createApp(Page, pageProps, pageContext);
  const appHtml = await renderToString(app);
  const { headTags, htmlAttrs, bodyAttrs, bodyTags } = await renderHeadToString(head);

Let me know if any of that isn't clear.

from head.

brillout avatar brillout commented on August 20, 2024 2

FYI the next vite-plugin-ssr version will warn the user when this happens.

from head.

SquirrelCoder avatar SquirrelCoder commented on August 20, 2024 1

oh shoot, I'm sorry, yeah that makes total sense. Thanks a lot.

from head.

SquirrelCoder avatar SquirrelCoder commented on August 20, 2024 1

@anatoliidaostreet That's not a problem with vueuse. I have asked the same question here: vikejs/vike#865.
You have to use it like this:

const documentHtml = escapeInject`<!DOCTYPE html>
    <html>
      <head>
      ${ dangerouslySkipEscape(headTags) }
    </head>
      <body>
        <div id="app">${ stringApp }</div>
      </body>
    </html>`;

or completely wrap your string in dangerouslySkipEscape. Like the following:

const documentHtml = dangerouslySkipEscape(`<!DOCTYPE html>
    <html>
      <head>
      ${ headTags }
    </head>
      <body>
        <div id="app">${ stringApp }</div>
      </body>
    </html>`);

from head.

 avatar commented on August 20, 2024

Hey @harlan-zw
I do how you propose, but i am getting sting of metadata in the body tag

const { app, head } = createApp(pageContext);
const pageHtml = pageContext.Page ? await renderToString(app) : '';
const { headTags, htmlAttrs, bodyTags } = await renderSSRHead(head);

Screenshot 2023-05-18 at 15 37 08

Did I miss something?

I use
vue3, vite-plugin-ssr with ssr and spa mode together

from head.

harlan-zw avatar harlan-zw commented on August 20, 2024

Amazing, thanks @brillout

from head.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.