Code Monkey home page Code Monkey logo

Comments (4)

BlackFenix2 avatar BlackFenix2 commented on May 18, 2024

to comment, i might be doing something wrong with my getLoadableState method.

import React from 'react'
import { renderToString } from 'react-dom/server'
import { StaticRouter } from 'react-router'
import { getLoadableState } from 'loadable-components/server'
import App from './App'

const app = (
  <StaticRouter>
    <App />
  </StaticRouter>
)

// Traversing React tree to load all modules
getLoadableState(app).then(() => {
  const html = renderToString(<YourApp />) // what is "<YourApp /> in this context? could be what i am missing.
})

from loadable-components.

gregberge avatar gregberge commented on May 18, 2024

It is difficult to help you with this portion of code, but I will try.

Is getLoadableState(app) resolved? Is the then called? If yes your setup is right.

The problem could be that a loadable-components is not present in the React Tree, so it is undetectable for getLoadableState(app) do you see what I mean?

from loadable-components.

BlackFenix2 avatar BlackFenix2 commented on May 18, 2024

NVM, i figured out the issue. i forgot to declare external on my webpack server config:

// /
const nodeExternals = require('webpack-node-externals');
const path = require('path');
const webpack = require('webpack');

const ExtractTextPlugin = require('extract-text-webpack-plugin');

const outputPath = path.resolve('wwwroot', 'server');

const config = {
  // node specific settings
  // target: 'node',
  externals: nodeExternals(), // <- this is what i forgot
  // find starting js file
  entry: {
    server: './ClientApp/server.jsx'
    // serverTest: './ClientApp/serverTest.jsx'
  },
  // add file extensions to shorthand ES6 imports
  resolve: {
    extensions: ['json', '.js', '.jsx', '.css']
  },
  // bundled code output
  output: {
    path: path.resolve(__dirname, outputPath),
    publicPath: '/',
    filename: '[name].js',
    libraryTarget: 'commonjs2'
  },

  module: {
    loaders: [
      // Check JS and JSX files before building
      {
        enforce: 'pre',
        test: /\.jsx?$/,
        loader: 'eslint-loader',
        exclude: /node_modules/
      },
      {
        // check each loader for matching files
        oneOf: [
          // default loader for js and jsx with inline babel config
          {
            test: /\.jsx?$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            options: {
              presets: ['env', 'react'],
              plugins: [
                'babel-plugin-transform-runtime',
                'babel-plugin-dynamic-import-node',
                'babel-plugin-transform-object-rest-spread',
                'babel-plugin-transform-class-properties',
                'transform-es2015-modules-commonjs'
              ],
              // Don't read from .babelrc
              babelrc: false
            }
          },
          // default css loader
          // {
          //   test: /\.css$/,
          //   loader: ExtractTextPlugin.extract({
          //     use: 'css-loader',
          //     fallback: 'style-loader'
          //   })
          // },

          // fallback loader if other loaders excluded
          // URL loader falls back to file-loader
          {
            loader: 'url-loader',

            exclude: [/\.(js|jsx|mjs|css)$/, /\.html$/, /\.json$/],
            options: {
              name: '[name].[ext]'
            }
          }
        ]
      }
    ]
  },
  plugins: [
    // load css into separate .css file
    // new ExtractTextPlugin({
    //   filename: 'server.css',
    //   allChunks: true
    // })
  ]
};

module.exports = config;

now my Async Server-side rendering works perfectly now! sorry to bother!

from loadable-components.

gregberge avatar gregberge commented on May 18, 2024

Nice!

from loadable-components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.