Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
fix(ssr): disableSSR option
Browse files Browse the repository at this point in the history
  • Loading branch information
ostowe committed May 27, 2021
1 parent 07c51bc commit 120c818
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/core/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import set from 'lodash/fp/set';
import { actionLocationChange } from 'actions';
import Cookies from 'universal-cookie';
import App from 'components/app';
import { getValueFromConfig } from 'config/irving/getValueFromConfig';
import {
getValueFromConfig,
getValueFromUserConfig,
} from 'config/irving/getValueFromConfig';
import preloadedStateDenylist from 'config/preloadedStateDenylist';
import rootReducer from 'reducers';
import defaultState from 'reducers/defaultState';
Expand Down Expand Up @@ -66,12 +69,16 @@ history.listen((location, action) => {
));
});

// Determine if user wants to disable SSR.
const disableSSR = getValueFromUserConfig('disableSSR', false);
const renderMethod = disableSSR ? 'render' : 'hydrate';

const render = () => {
const rootEl = document.getElementById('root');
// It is imperative that the server React component tree matches the client
// component tree, so that the client can re-hydrate the app from the server
// rendered markup, otherwise the app will be completely re-rendered.
ReactDOM.hydrate(
ReactDOM[renderMethod](
<Provider store={store}>
<App />
</Provider>,
Expand Down
10 changes: 8 additions & 2 deletions packages/core/server/utils/getTemplateVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React from 'react';
import { renderToString } from 'react-dom/server';
import omit from 'lodash/fp/omit';
import mergeWith from 'lodash/mergeWith';
import { getConfigValues } from 'config/irving/getValueFromConfig';
import {
getConfigValues,
getValueFromUserConfig,
} from 'config/irving/getValueFromConfig';
import { getEnv, getSiteConfig } from 'config/multisite';

export const defaultHead = {
Expand All @@ -19,6 +22,9 @@ export const defaultHead = {
end: [],
};

// Determine if user wants to disable SSR.
const disableSSR = getValueFromUserConfig('disableSSR', false);

/**
* Check if a value is a function and, if so, call that function to get underlying value.
*
Expand Down Expand Up @@ -151,6 +157,6 @@ export default function getTemplateVars(
return {
...mergedVars,
head: mergedHead,
appHtml,
appHtml: disableSSR ? '' : appHtml,
};
}

0 comments on commit 120c818

Please sign in to comment.