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.

server side rendering issue with universal component

See original GitHub issue

It might be silly but with the following code config, it is not working if i import pages via props. When i try to load http://localhost:8080, Home page is not rendering from server but later on gets rendered from client properly. This is the repository I am referring to. You can check the code.

import React from "react";
import { Route } from "react-router-dom";
import universal from "react-universal-component";
import { Switch, Redirect } from "react-router";
import Nav from "../Components/Nav";
import "../assets/css/globals.css";
import { Helmet } from "react-helmet";
import Loading from "../Components/Loading";
import NotFound from "../Views/NotFound";

const UniversalComponent = universal(
  props => import(`../Views/${props.page}`),
  {
    loading: () => <Loading />
  }
);

export default () => (
  <div>
    <Helmet>
      <title>React SSR Boilerplate</title>
    </Helmet>
    <Nav />
    <Switch>
      <Route exact path="/">
        <UniversalComponent page="Home" />
      </Route>
      <Route exact path="/about">
        <UniversalComponent page="About" />
      </Route>
      <Route exact path="/article">
        <UniversalComponent page="Article" />
      </Route>
      <Route>
        <NotFound />
      </Route>
    </Switch>
  </div>
);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:19

github_iconTop GitHub Comments

5reactions
ScriptedAlchemycommented, Sep 19, 2018

Fixes are being worked on for chunk mismatch’s.

This library family has grown significantly in popularity- as such I needed to look at an update to try and normalize the chunk resolution

2reactions
kyle-johnsoncommented, Sep 8, 2018

Based on a similar problem, I have a suspicion this is related to how webpack/babel interact in some configurations. Try this:

const UniversalComponent = universal(
  props => import(`../Views/${props.page}`),
  {
    loading: () => <Loading />,
    testBabelPlugin: true  // hack around this by using a debug feature
  }
);

If that succeeds, then the issue is the Babel plugin isn’t calling its hook early enough. You can call the hook yourself by sticking this at the top of your server file or perhaps before any use of universal:

import { setHasBabelPlugin } from "react-universal-component";
setHasBabelPlugin();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering (SSR) with Angular Universal
This guide describes Angular Universal, a technology that renders Angular applications on the server. A normal Angular application executes in the browser, ...
Read more >
Angular Universal: real app problems - InDepth.Dev
The project makes server-side rendering possible in Angular. This article will discuss the issues and possible solutions we encountered while developing a real ......
Read more >
Server-side Rendering (SSR): An intro to Angular Universal
A normal Angular application executes in the browser, rendering pages in the DOM in response to user actions. Angular Universal executes on ...
Read more >
Angular 7 Universal: inner components are not rendered
I have set up Angular 7 Universal with dynamic server-side rendering. Everything works fine except for the fact that dynamic components ...
Read more >
Don't let Angular Universal break you (or your app). Some tips ...
Server Side Rendering (SSR) is not without its caveats. Debugging & Hot Fixes are an almost certainty. You wanted to provide the best...
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