-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Modal): fix errors with SSR (#2260)
* fix: Modal SSR Resolve Issue #2259 * Change isBrowser to function Allow isBrowser to be overridden for SSR tests
- Loading branch information
1 parent
9fd189c
commit 454daaa
Showing
14 changed files
with
87 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import _ from 'lodash' | ||
|
||
const hasDocument = typeof document === 'object' && document !== null | ||
const hasWindow = typeof window === 'object' && window !== null && window.self === window | ||
|
||
export default hasDocument && hasWindow | ||
// eslint-disable-next-line no-confusing-arrow | ||
const isBrowser = () => !_.isNil(isBrowser.override) | ||
? isBrowser.override | ||
: hasDocument && hasWindow | ||
|
||
export default isBrowser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import isBrowser from 'src/lib/isBrowser' | ||
|
||
describe('isBrowser', () => { | ||
it('should return true in a browser', () => { | ||
// tests are run in a browser, this should be true | ||
isBrowser.should.be.true() | ||
}) | ||
describe('browser', () => { | ||
it('should return true in a browser', () => { | ||
// tests are run in a browser, this should be true | ||
isBrowser().should.be.true() | ||
}) | ||
|
||
it('should return false when there is no document', () => { | ||
require('imports-loader?document=>undefined!src/lib/isBrowser').default().should.be.false() | ||
require('imports-loader?document=>null!src/lib/isBrowser').default().should.be.false() | ||
}) | ||
|
||
it('should return false when there is no document', () => { | ||
require('imports-loader?document=>undefined!src/lib/isBrowser').default.should.be.false() | ||
require('imports-loader?document=>null!src/lib/isBrowser').default.should.be.false() | ||
it('should return false when there is no window', () => { | ||
require('imports-loader?window=>undefined!src/lib/isBrowser').default().should.be.false() | ||
require('imports-loader?window=>null!src/lib/isBrowser').default().should.be.false() | ||
}) | ||
}) | ||
|
||
it('should return false when there is no window', () => { | ||
require('imports-loader?window=>undefined!src/lib/isBrowser').default.should.be.false() | ||
require('imports-loader?window=>null!src/lib/isBrowser').default.should.be.false() | ||
describe('server-side', () => { | ||
before(() => { | ||
isBrowser.override = false | ||
}) | ||
|
||
after(() => { | ||
isBrowser.override = null | ||
}) | ||
|
||
it('should return override value', () => { | ||
// tests are run in a browser, this should be true | ||
isBrowser().should.be.false() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters