question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSR - Use Only component cause generation different HTML on server and client

See original GitHub issue

What:

When using a component Only server HTML may differ from generated on client with warning:

Warning: Expected server HTML to contain a matching <div> in <div>.

Environment:

  • node vesrion: 10.15.0
  • npm version: 6.4.1
  • atomic-layout version: 0.6.2

Steps to reproduce:

Steps to reproduce the behavior:

Create component on server with such composition:

      <Composition
        template={templateMobile}
        templateMd={templateTablet}
        templateLg={templateMobile}
        templateColsMdOnly='minmax(100px, 1fr) 1fr'
        padding={15}
        gutter={15}
        gutterLg={25}
      >
        {({ Thumbnail, Heading, Actions }) => (
          <>
            <Thumbnail>
              Thumbnail
            </Thumbnail>
            <Heading>
              Heading
            </Heading>
            <Actions>
              <Only from='md' marginRight={10}>
                Button
              </Only>
              Actions
            </Actions>
          </>
        )}
      </Composition>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
kettanaitocommented, Apr 3, 2019

According to our discussion I have set the default value for conditional rendering to be false. This means the conditional content will not be rendered on a server-side, and will not be rendered initially on the client-side as well (to retain proper nodes hydration). After Only component mounting it will re-match the current media query, and re-render the conditional content in case a match occurs.

Published under https://github.com/kettanaito/atomic-layout/releases/tag/0.7.1.

I would be thankful if you could test this behavior in your projects and let me know. Thank you so much for this discussion, @lokhmakov, @bitttttten!

1reaction
lokhmakovcommented, Apr 3, 2019

@bitttttten Yep, for client dependent code like pixi.js or atomic-layout/Only we using dynamic import and all works fine, like:

import loadable from '@loadable/component'

const SectionTools = loadable(() =>
  import(`box/2d-editor/editor/web/section/SectionTools`),
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering the right way | by José Manuel Aguirre
SSR : The process where a user asks the server for some url, for example: https://www.mywebsite.com/how-to-ssr and the server responds with an ...
Read more >
Client-side vs. server-side rendering: why it's not all black and ...
Server -side rendering is the most common method for displaying information onto the screen. It works by converting HTML files in the server...
Read more >
Web Components in Server-Side Rendered (SSR) and Static ...
Static-Site Generation (SSG) - A build tool generates static HTML ... to the component's innerHTML into a separate module, the server (or ...
Read more >
Server-Side Rendering (SSR) - Vue.js
However, it is also possible to render the same components into HTML ... Static Site Generation (SSG), also referred to as pre-rendering, is...
Read more >
How to use client-side only packages with SSR in Gatsby and ...
This is how server-side rendering works: the server we requested the page from executes all the code in a node server: your browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found