Git Product home page Git Product logo

Comments (12)

ozyman42 avatar ozyman42 commented on July 17, 2024 1

Seems to not be working for gatsby apps.

from reactscrollbar.

souhe avatar souhe commented on July 17, 2024

Could you give me some more details?
I have no idea why you get 'window is not defined' error.

from reactscrollbar.

ekron avatar ekron commented on July 17, 2024

I have a slightly different version of the same problem.

For me, the ReferenceError: window is not defined is thrown when the lib is running on the server and tries to access window and document browser globals.

ScrollArea.jsx:

ScrollArea.defaultProps = {
    speed: 1,
    vertical: true,
    horizontal: true,
    contentWindow: window,
    ownerDocument: document
};

And:

ScrollBar.defaultProps = {
    type : 'vertical',
    ownerDocument: document
}

The next problem is when the build process uses the webpack style loader to load the .less styles.

The resulting output gives you the same error -- because the style loader code in the build also tries to window and document globals.

e.g.:

isOldIE = memoize(function() {
        return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase());
    }),

... it also heavily uses the document global. (The loader is not intended to run server-side.)

If react-scrollbar is intended for use in universal apps, a build process tweak and some guards around window, document and browser-specific code may be a fix?

from reactscrollbar.

souhe avatar souhe commented on July 17, 2024

You're right, window and document could be a huge problem for universal/isomorphic apps. I'll think about solving that problem. And of course I'll solve it!

I have one question about your second issue. You get that error during your build process or when you run app on the server (because of my loaded css styles into js file)?

from reactscrollbar.

marksyzm avatar marksyzm commented on July 17, 2024

I would consider using functionality tests rather than user agents

from reactscrollbar.

ekron avatar ekron commented on July 17, 2024

@souhe Sorry for the slow response and thanks for creating the component. With regard to:

I have one question about your second issue. You get that error during your build process or when you run app on the server (because of my loaded css styles into js file)?

The style-loader code I mentioned is included the react-scrollbar package (in the minified code in react-scrollbar/dist/scrollArea.js). The resulting built code looks for universal browser variables and fails on the server.

My guess is that using style-loader to build this package is the source of the problem. See this.

Hope that helps.

from reactscrollbar.

souhe avatar souhe commented on July 17, 2024

Thanks @ekron

Yes, that's style-loader issue. For universal apps the best solution would be probably using react-scrollbar in nocss version (see issue #30 ). I've did that change(it's on dev branch) but I'll merge it into master with release 0.4.0.

I'll also make sure that window and document references in react-scrollbar will be mocked up or removed.

from reactscrollbar.

ekron avatar ekron commented on July 17, 2024

Good plan. Thanks again @souhe.

from reactscrollbar.

magalhas avatar magalhas commented on July 17, 2024

I've submitted a PR to style-loader that I think that solves this.

from reactscrollbar.

souhe avatar souhe commented on July 17, 2024

@magalhas Good job! πŸ‘

from reactscrollbar.

souhe avatar souhe commented on July 17, 2024

I've just published version v.0.4.0 with possibility to require react-scrollbar in no-css version. I also made sure that window and document references in react-scrollbar don't make troubles in universal apps.

Until @magalhas PR will not be merged I recommended to use no-css version of react-scrollbar while server rendering.
So I'm closing that issue.

from reactscrollbar.

devnax avatar devnax commented on July 17, 2024

NextJs also, It's showing ReferenceError: window is not defined

from reactscrollbar.

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.