Coder Social home page Coder Social logo

Comments (4)

mrchief avatar mrchief commented on July 24, 2024 1

Found this: webpack/webpack#6525. Thanks again for digging into this!

from react-infinite-scroll-component.

ankeetmaini avatar ankeetmaini commented on July 24, 2024

@mrchief I looked at this issue long and deep. I'm using window only in and after componentDidMount. This is safe for SSR as componentDidMount gets called on the client and not on the server.

To test this out, I took a React SSR boilerplate and added InfiniteScroll component in the shared bundle. And it worked without any errors. first commit

Next, I added your dropdown component and it failed saying window is not defined. At this point I forked your repo, and changed the webpack mode to development so that Dropdown's code isn't minified to debug the issue. (I copy pasted the built files into this repo to access the Dropdown code)

Please see that the error was reported on line number 10, which is output of the IIFE.
screen shot 2018-06-07 at 12 01 31 am
screen shot 2018-06-07 at 12 01 44 am

I suspect this is because of the way Webpack 4 is generating the UMD definition. I then lowered the Webpack to 2.3.4 which I'm using at work, and built the Dropdown component and it worked fine.

So I'm guessing Webpack 4 is what's causing an issue, and not the infinite scroll component.

I made three commits to this https://github.com/ankeetmaini/infinite-scroll-ssr for you to see the steps.

Let me know if I can help more, and sorry for not getting to it earlier.

from react-infinite-scroll-component.

ankeetmaini avatar ankeetmaini commented on July 24, 2024

Webpack 2 generates the IIFE like this - it uses this instead of window

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("react"));
	else if(typeof define === 'function' && define.amd)
		define("ReactDropdownTreeSelect", ["react"], factory);
	else if(typeof exports === 'object')
		exports["ReactDropdownTreeSelect"] = factory(require("react"));
	else
		root["ReactDropdownTreeSelect"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) {
return /******/ (function(modules) { // webpackBootstrap

Webpack 4 produces this

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("react"));
	else if(typeof define === 'function' && define.amd)
		define("ReactDropdownTreeSelect", ["react"], factory);
	else if(typeof exports === 'object')
		exports["ReactDropdownTreeSelect"] = factory(require("react"));
	else
    root["ReactDropdownTreeSelect"] = factory(root["React"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE_react__) {
return /******/ (function(modules) { // webpackBootstrap

from react-infinite-scroll-component.

mrchief avatar mrchief commented on July 24, 2024

@ankeetmaini Thanks for this deep dive. Let me take a detailed look and get back to you. This is very helpful! 👍

from react-infinite-scroll-component.

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.