File tree 6 files changed +32
-0
lines changed
6 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1
1
## Unreleased
2
2
3
3
* Add missing TypeScript ` title ` attribute type to steps.
4
+ * Fix various issues related to Next.js and SSR.
4
5
5
6
## 0.6.0
6
7
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Component } from 'react';
4
4
5
5
import * as introJsPropTypes from '../../helpers/proptypes' ;
6
6
import * as introJsDefaultProps from '../../helpers/defaultProps' ;
7
+ import { isServer } from '../../helpers/server' ;
7
8
8
9
/**
9
10
* Intro.js Hints Component.
@@ -92,6 +93,10 @@ export default class Hints extends Component {
92
93
* Installs Intro.js.
93
94
*/
94
95
installIntroJs ( ) {
96
+ if ( isServer ( ) ) {
97
+ return ;
98
+ }
99
+
95
100
this . introJs = introJs ( ) ;
96
101
97
102
const { onClick, onClose } = this . props ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import renderer from 'react-test-renderer';
3
3
import { shallow } from 'enzyme' ;
4
4
5
5
import Hints from './index' ;
6
+ import * as server from '../../helpers/server' ;
6
7
7
8
/**
8
9
* Hints.
@@ -119,4 +120,12 @@ describe('Hints', () => {
119
120
120
121
expect ( wrapper . instance ( ) . introJs . onHintClose ) . toBe ( onClose ) ;
121
122
} ) ;
123
+
124
+ test ( 'should not install intro.js during SSR' , ( ) => {
125
+ jest . spyOn ( server , 'isServer' ) . mockReturnValueOnce ( true ) ;
126
+
127
+ const wrapper = shallow ( < Hints hints = { hints } /> ) ;
128
+
129
+ expect ( wrapper . instance ( ) . introJs ) . toBe ( null ) ;
130
+ } ) ;
122
131
} ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
5
5
6
6
import * as introJsPropTypes from '../../helpers/proptypes' ;
7
7
import * as introJsDefaultProps from '../../helpers/defaultProps' ;
8
+ import { isServer } from '../../helpers/server' ;
8
9
9
10
/**
10
11
* Intro.js Steps Component.
@@ -221,6 +222,10 @@ export default class Steps extends Component {
221
222
* Installs Intro.js.
222
223
*/
223
224
installIntroJs ( ) {
225
+ if ( isServer ( ) ) {
226
+ return ;
227
+ }
228
+
224
229
this . introJs = introJs ( ) ;
225
230
226
231
this . introJs . onexit ( this . onExit ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import renderer from 'react-test-renderer';
4
4
import { shallow } from 'enzyme' ;
5
5
6
6
import Steps from './index' ;
7
+ import * as server from '../../helpers/server' ;
7
8
8
9
jest . useFakeTimers ( ) ;
9
10
@@ -344,4 +345,12 @@ describe('Steps', () => {
344
345
345
346
expect ( wrapper . instance ( ) . introJs . _introItems [ 0 ] . element ) . toEqual ( expect . any ( HTMLDivElement ) ) ;
346
347
} ) ;
348
+
349
+ test ( 'should not install intro.js during SSR' , ( ) => {
350
+ jest . spyOn ( server , 'isServer' ) . mockReturnValueOnce ( true ) ;
351
+
352
+ const wrapper = shallow ( < Steps initialStep = { 0 } steps = { steps } onExit = { ( ) => { } } /> ) ;
353
+
354
+ expect ( wrapper . instance ( ) . introJs ) . toBe ( null ) ;
355
+ } ) ;
347
356
} ) ;
Original file line number Diff line number Diff line change
1
+ export function isServer ( ) {
2
+ return typeof window === 'undefined' ;
3
+ }
You can’t perform that action at this time.
0 commit comments