From 805886e4a96bc543f39052f1d715c71bb76eee76 Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Wed, 5 Oct 2016 14:22:01 +0200 Subject: [PATCH] We trigger current url history only once the page has been mounted --- .../gitbook-core/src/lib/createContext.js | 6 --- .../gitbook-core/src/lib/renderWithContext.js | 41 +++++++++++++++---- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/packages/gitbook-core/src/lib/createContext.js b/packages/gitbook-core/src/lib/createContext.js index c88baadb5..87593e39f 100644 --- a/packages/gitbook-core/src/lib/createContext.js +++ b/packages/gitbook-core/src/lib/createContext.js @@ -19,12 +19,6 @@ const isBrowser = (typeof window !== 'undefined'); * @type {Plugin} */ const corePlugin = new Plugin({ - activate: (dispatch) => { - dispatch(Navigation.activate()); - }, - deactivate: (dispatch) => { - dispatch(Navigation.deactivate()); - }, reduce: coreReducers, actions: { Components, I18n, Navigation diff --git a/packages/gitbook-core/src/lib/renderWithContext.js b/packages/gitbook-core/src/lib/renderWithContext.js index 32553d9d1..44f8ba442 100644 --- a/packages/gitbook-core/src/lib/renderWithContext.js +++ b/packages/gitbook-core/src/lib/renderWithContext.js @@ -4,6 +4,39 @@ const { InjectedComponent } = require('../components/InjectedComponent'); const PJAXWrapper = require('../components/PJAXWrapper'); const I18nProvider = require('../components/I18nProvider'); const ContextProvider = require('../components/ContextProvider'); +const Navigation = require('../actions/navigation'); +const contextShape = require('../shapes/context'); + +const GitBookApplication = React.createClass({ + propTypes: { + context: contextShape + }, + + componentDidMount() { + const { context } = this.props; + context.dispatch(Navigation.activate()); + }, + + componentWillUnmount() { + const { context } = this.props; + context.dispatch(Navigation.deactivate()); + }, + + render() { + const { context } = this.props; + + return ( + + + + + + + + ); + } +}); + /** * Render the application for a GitBook context. @@ -13,13 +46,7 @@ const ContextProvider = require('../components/ContextProvider'); */ function renderWithContext(context) { return ( - - - - - - - + ); }