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 ExecJS::ProgramError when using client side code splitting

See original GitHub issue

Steps to reproduce

I have a component that has a componentDidMount like so:

  public async componentDidMount() {
    const [Foo, Bar] = await Promise.all([
      import(/* webpackChunkName: "stuff" */ 'foo'),
      import(/* webpackChunkName: "stuff" */ 'bar'),
     ]);
    this.setState({
      Foo: Foo.default,
      Bar: Bar.default,
    });
  }

Expected behavior

Since the import occurs inside componentDidMount, it’s expected that that code does not cause issues when using SSR with ExecJS. In this code, the intention is for code splitting to occur for the client side only.

Actual behavior

A ExecJS::ProgramError is raised, stating ‘ReferenceError: window is not defined’. I have eliminated it down to this code which happens to be the very beginning of the server_rendering.js output:

/******/ (function(modules) { // webpackBootstrap
/******/ 	// install a JSONP callback for chunk loading
/******/ 	var parentJsonpFunction = window["webpackJsonp"];
...

If I change componentDidMount to be blank (or really just remove the import calls in it), webpack does not add the above snippet and no SSR error occurs. Is there a mechanism within this gem to allow for client side code splitting like this and still allow for the component to be rendered server-side?

System configuration

Sprockets or Webpacker version: Webpacker 3.5.3 React-Rails version: 2.4.7 Rect_UJS version: 2.4.4 Rails version: 5.2.0 Ruby version: 2.5.1p57

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nopelluhhcommented, Oct 2, 2019

I’m looking into the above fix, will report back!

1reaction
jdfmcommented, Jan 15, 2019

@bcharna Although I have this issue as well on a project I’m working on, I don’t think this is related to react-rails at all, but indeed webpack, so, I’m thinking reporting it to the https://github.com/rails/webpacker people will be more useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - How to achieve code splitting + SSR with @loadable ...
I'm trying to add code splitting + SSR to my React web app using @loadable/component . My current situation: This is how I've...
Read more >
React Server Side Code Splitting Made.. Again - ITNEXT
How SSR now works? In short – you render a page on a server, send it to a client, load js needed, then...
Read more >
Code Splitting, SSR, Lazy loading React components - Medium
First things first, we have to understand why is there a difference between the two rendering techniques and why should we even care...
Read more >
React On Rails Ssr "Typeerror: Cannot Read Property ...
Render any react component with a Provider on the server set prerender as true The ... Now Rails is throwing the error: #<ExecJS::ProgramError:...
Read more >
Untitled
Gcr tire centers canada, Desert side of your mind, Tokyo drift dikey, ... Karel en elegast vertaling, Bolita de grasa en ojo, Execjs...
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