Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

When server-side rendering, it doesn't load anything #42

Open
Sawtaytoes opened this issue Mar 31, 2017 · 2 comments
Open

When server-side rendering, it doesn't load anything #42

Sawtaytoes opened this issue Mar 31, 2017 · 2 comments
Assignees

Comments

@Sawtaytoes
Copy link

Doing something like this for react-router:

import loadFAQ from 'bundle-loader?lazy!components/pages/faq'

const FAQ = () => (
  <Bundle load={loadFAQ}>
    {(FAQ) => FAQ ? <FAQ /> : null}
  </Bundle>
)

const Pages = () => (
  <SiteLayout>
    <Switch>
      <Route path="/faq" component={FAQ} />
    </Switch>
  </SiteLayout>
)

export default Pages

For some reason, it's not loading from the server. Removing ?lazy doesn't make it work either. I understand this is loading async, but is there some way to know if the environment is Node and set it to sync vs async when client-side rendered? Is there something I can pass in the Webpack config depending on if it's the server or client build?

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 31, 2017

is there some way to know if the environment is Node and set it to sync vs async when client-side rendered?

webpack.config.js

export default {
   target: 'node'  // default 'web'
}

@Sawtaytoes But for async to sync I don't think { target: 'node' } will do that for you 😛

Why don't you using import()/require.ensure() webpack will create a split (async chunk) point for you? Is using bundle loader on purpose?

@Sawtaytoes
Copy link
Author

Yeah. I was thinking of a better method as my require.ensure() method wasn't ideal.
https://medium.com/@Sawtaytoes/async-react-router-v4-components-c18792e6f331

I'll take a fresh look 'n see if that method works for me instead in the same way I'm wrapping this using a <Bundle /> component.

@joshwiens joshwiens removed the question label May 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants