No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    SSR window is not defined

    Help
    2
    4
    2069
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mbrandeis last edited by

      When trying to add the component vue2-leaflet to an SSR page I’m getting “window is not defined”

      What are the recommended ways of handling a component that is not SSR-friendly?

      I can import the library, but when I add it to the components {} list it generates the error “window is not defined”. Fine, it needs to run on the client. But how can I tell quasar to not try to render it on the server and have it render on the client.

      M 1 Reply Last reply Reply Quote 0
      • M
        mbrandeis @mbrandeis last edited by mbrandeis

        For anyone following this thread, the q-no-ssr documentation doesn’t show a realistic example (who would use q-no-ssr to not render an H1 tag on the server?)

        I found the best solution was to create a component for my troublesome package and put that component in q-no-ssr, AND THEN adding a javascript check in the component (not the page) to see if it is running on the server like this:

        <script>
        let Vue2Leaflet = {}
        
        if (!process.env.SERVER) {
          console.log('loading vue2-leaflet')
          Vue2Leaflet = require('vue2-leaflet')
        }
        export default {
          name: 'CampaignMap',
          components: {
            'l-map': Vue2Leaflet.LMap,
            'l-tile-layer': Vue2Leaflet.LTileLayer,
            'l-marker': Vue2Leaflet.LMarker
          },
        ....
        
        1 Reply Last reply Reply Quote 0
        • rstoenescu
          rstoenescu Admin last edited by rstoenescu

          @mbrandeis who would use q-no-ssr to not render an H1 tag on the server? :))
          Should it should use an example with H2 instead? Leaving jokes aside, isn’t the documentation supposed to offer the concept of QNoSsr? Who cares what the QNoSsr example nodes contain? The concept matters.

          Small tip: you can use process.env.CLIENT to avoid the unnecessary negation on process.env.SERVER.

          1 Reply Last reply Reply Quote 0
          • M
            mbrandeis last edited by

            @rstoenescu You’re right - the tag doesn’t matter. The real issue I had was that the case of code that doesn’t work with QNoSsr and needing to use process.env.CLIENT is not documented.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post