File tree Expand file tree Collapse file tree 6 files changed +32
-0
lines changed Expand file tree Collapse file tree 6 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 11## Unreleased
22
33* Add missing TypeScript ` title ` attribute type to steps.
4+ * Fix various issues related with Next.js and SSR.
45
56## 0.6.0
67
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Component } from 'react';
44
55import * as introJsPropTypes from '../../helpers/proptypes' ;
66import * as introJsDefaultProps from '../../helpers/defaultProps' ;
7+ import { isServer } from '../../helpers/server' ;
78
89/**
910 * Intro.js Hints Component.
@@ -92,6 +93,10 @@ export default class Hints extends Component {
9293 * Installs Intro.js.
9394 */
9495 installIntroJs ( ) {
96+ if ( isServer ( ) ) {
97+ return ;
98+ }
99+
95100 this . introJs = introJs ( ) ;
96101
97102 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';
33import { shallow } from 'enzyme' ;
44
55import Hints from './index' ;
6+ import * as server from '../../helpers/server' ;
67
78/**
89 * Hints.
@@ -119,4 +120,12 @@ describe('Hints', () => {
119120
120121 expect ( wrapper . instance ( ) . introJs . onHintClose ) . toBe ( onClose ) ;
121122 } ) ;
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+ } ) ;
122131} ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
55
66import * as introJsPropTypes from '../../helpers/proptypes' ;
77import * as introJsDefaultProps from '../../helpers/defaultProps' ;
8+ import { isServer } from '../../helpers/server' ;
89
910/**
1011 * Intro.js Steps Component.
@@ -221,6 +222,10 @@ export default class Steps extends Component {
221222 * Installs Intro.js.
222223 */
223224 installIntroJs ( ) {
225+ if ( isServer ( ) ) {
226+ return ;
227+ }
228+
224229 this . introJs = introJs ( ) ;
225230
226231 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';
44import { shallow } from 'enzyme' ;
55
66import Steps from './index' ;
7+ import * as server from '../../helpers/server' ;
78
89jest . useFakeTimers ( ) ;
910
@@ -344,4 +345,12 @@ describe('Steps', () => {
344345
345346 expect ( wrapper . instance ( ) . introJs . _introItems [ 0 ] . element ) . toEqual ( expect . any ( HTMLDivElement ) ) ;
346347 } ) ;
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+ } ) ;
347356} ) ;
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