-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(Sticky|Visibility): add null check on window #1990
Conversation
fix(Sticky|Visibility): add null check on window for server side rendering
Codecov Report
@@ Coverage Diff @@
## master #1990 +/- ##
=========================================
+ Coverage 99.8% 99.8% +<.01%
=========================================
Files 148 148
Lines 2589 2593 +4
=========================================
+ Hits 2584 2588 +4
Misses 5 5
Continue to review full report at Codecov.
|
@@ -141,7 +142,7 @@ export default class Visibility extends Component { | |||
} | |||
|
|||
static defaultProps = { | |||
context: window, | |||
context: isBrowser ? window : {}, |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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
Looking forward to this PR! Thanks |
I can't wait for this to merge, thank you! |
Has this been tested in SSR? I don't see how the componentDidMount() {
const { context } = this.props
context.addEventListener('scroll', this.handleScroll)
} In other components, we also exit methods early if they are accessing the componentDidMount() {
if (!isBrowser) return
const { context } = this.props
context.addEventListener('scroll', this.handleScroll)
} Would love to get some validation from SSR users before shipping. |
I can confirm that these changes fix my SSR apps, although I also need to make the same changes in |
@levithomason I tested it against my SSR app, but I will add null checks around the lifecycle methods too |
@tim-soft and @ChrisNLott, thanks for investigating and reporting back. Also, to @ChrisNLott for the updates. Merging! Will be released today :) |
Released in |
fix(Sticky|Visibility): add null check on window for server side rendering
fixes #1987