Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Sticky|Visibility): add null check on window #1990

Merged
merged 4 commits into from
Aug 28, 2017
Merged

fix(Sticky|Visibility): add null check on window #1990

merged 4 commits into from
Aug 28, 2017

Conversation

lottamus
Copy link
Contributor

fix(Sticky|Visibility): add null check on window for server side rendering

fixes #1987

fix(Sticky|Visibility): add null check on window for server side rendering
@codecov-io
Copy link

codecov-io commented Aug 21, 2017

Codecov Report

Merging #1990 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1990      +/-   ##
=========================================
+ Coverage    99.8%   99.8%   +<.01%     
=========================================
  Files         148     148              
  Lines        2589    2593       +4     
=========================================
+ Hits         2584    2588       +4     
  Misses          5       5
Impacted Files Coverage Δ
src/modules/Sticky/Sticky.js 100% <100%> (ø) ⬆️
src/behaviors/Visibility/Visibility.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23ec465...0385067. Read the comment docs.

@lottamus lottamus mentioned this pull request Aug 21, 2017
@@ -141,7 +142,7 @@ export default class Visibility extends Component {
}

static defaultProps = {
context: window,
context: isBrowser ? window : {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use null there:

isBrowser ? window : null,

Copy link
Contributor Author

@lottamus lottamus Aug 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@layershifter if we use null, should we also add null checks around https://github.com/ChrisNLott/Semantic-UI-React/blob/d3bd18cd7fca2be2ea5a32381b70798aa5de2c57/src/behaviors/Visibility/Visibility.js#L173? basically anywhere context is used? But I suppose the empty object would error in that case too

@lulalachen
Copy link

Looking forward to this PR! Thanks

@tim-soft
Copy link

I can't wait for this to merge, thank you!

@levithomason
Copy link
Member

Has this been tested in SSR? I don't see how the componentDidMount would work when context is null:

  componentDidMount() {
    const { context } = this.props
    context.addEventListener('scroll', this.handleScroll)
  }

In other components, we also exit methods early if they are accessing the document or window:

  componentDidMount() {
    if (!isBrowser) return

    const { context } = this.props
    context.addEventListener('scroll', this.handleScroll)
  }

Would love to get some validation from SSR users before shipping.

@tim-soft
Copy link

I can confirm that these changes fix my SSR apps, although I also need to make the same changes in dist/commonjs/behaviors/Visibility/Visibility.js and dist/commonjs/modules/Sticky/Stick.js

@lottamus
Copy link
Contributor Author

@levithomason I tested it against my SSR app, but I will add null checks around the lifecycle methods too

@levithomason
Copy link
Member

@tim-soft and @ChrisNLott, thanks for investigating and reporting back. Also, to @ChrisNLott for the updates.

Merging! Will be released today :)

@levithomason levithomason merged commit 2c0fda5 into Semantic-Org:master Aug 28, 2017
@levithomason
Copy link
Member

Released in semantic-ui-react@0.72.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReferenceError: window is not defined
6 participants