Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Improve SSR performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 6, 2020
1 parent 480f2ce commit 8d29d07
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"packages": [
"packages/*"
],
"version": "1.0.2"
"version": "1.0.3-ssr-perf.1"
}
4 changes: 2 additions & 2 deletions packages/bumbag-addon-highlighted-code/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bumbag-addon-highlighted-code",
"version": "1.0.2",
"version": "1.0.3-ssr-perf.1",
"description": "An accessible, composable, and friendly React UI Kit",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@testing-library/react": "8.0.7",
"@testing-library/react-hooks": "1.1.0",
"bumbag": "^1.0.2",
"bumbag": "^1.0.3-ssr-perf.1",
"react-test-renderer": "16.8.6"
},
"author": "Jake Moxey",
Expand Down
4 changes: 2 additions & 2 deletions packages/bumbag-addon-markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bumbag-addon-markdown",
"version": "1.0.2",
"version": "1.0.3-ssr-perf.1",
"description": "An accessible, composable, and friendly React UI Kit",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@testing-library/react": "8.0.7",
"@testing-library/react-hooks": "1.1.0",
"bumbag": "^1.0.2",
"bumbag": "^1.0.3-ssr-perf.1",
"react-test-renderer": "16.8.6"
},
"author": "Jake Moxey",
Expand Down
2 changes: 1 addition & 1 deletion packages/bumbag-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bumbag-server",
"version": "1.0.0",
"version": "1.0.3-ssr-perf.0",
"main": "lib/index.js",
"module": "es/index.js",
"types": "ts/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/bumbag-theme-medipass/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bumbag-theme-medipass",
"version": "1.0.0",
"version": "1.0.3-ssr-perf.0",
"main": "lib/index.js",
"module": "es/index.js",
"types": "ts/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/bumbag/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bumbag",
"version": "1.0.2",
"version": "1.0.3-ssr-perf.1",
"description": "An accessible, composable, and friendly React UI Kit",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
19 changes: 9 additions & 10 deletions packages/bumbag/src/ColorMode/ColorModeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ export const ColorModeContext = React.createContext<any>({ setColorMode: () => {
type Props = {
children: React.ReactNode;
mode: string;
isSSR?: boolean;
};

ColorModeProvider.defaultProps = {
isSSR: false
}

export function ColorModeProvider(props: Props) {
const { children, mode: _defaultMode } = props;
const { children, mode: _defaultMode, isSSR } = props;

////////////////////////////////////

Expand Down Expand Up @@ -62,16 +67,10 @@ export function ColorModeProvider(props: Props) {

////////////////////////////////////

if (!mounted) {
return (
<div style={{ visibility: 'hidden' }}>{children}</div>
)
if (isSSR && !mounted) {
return <div style={{ visibility: 'hidden' }}>{children}</div>;
}
return (
<ColorModeContext.Provider value={value}>
{children}
</ColorModeContext.Provider>
);
return <ColorModeContext.Provider value={value}>{children}</ColorModeContext.Provider>;
}

export function useColorMode() {
Expand Down
5 changes: 3 additions & 2 deletions packages/bumbag/src/Provider/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ProviderProps = {
isStandalone?: boolean;
collapseBelow?: LayoutBreakpoint;
colorMode?: string;
isSSR?: boolean;
theme?: ThemeConfig;
};

Expand All @@ -25,7 +26,7 @@ Provider.defaultProps = {
};

export function Provider(props: ProviderProps) {
const { children, colorMode, collapseBelow, isStandalone, theme: _theme } = props;
const { children, colorMode, collapseBelow, isSSR, isStandalone, theme: _theme } = props;

////////////////////////////////////////////////

Expand All @@ -52,7 +53,7 @@ export function Provider(props: ProviderProps) {
return (
<BumbagThemeContext.Provider value={themeContextValue}>
<EmotionProvider theme={derivedTheme}>
<ColorModeProvider mode={colorMode}>
<ColorModeProvider isSSR={isSSR} mode={colorMode}>
<IdProvider>
<ToastProvider>
<PageProvider collapseBelow={collapseBelow}>
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-bumbag/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-plugin-bumbag",
"version": "1.0.0",
"version": "1.0.3-ssr-perf.0",
"main": "lib/index.js",
"module": "es/index.js",
"types": "ts/index.d.ts",
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"@emotion/babel-preset-css-prop": "10.0.27",
"bumbag-server": "^1.0.0"
"bumbag-server": "^1.0.3-ssr-perf.0"
},
"peerDependencies": {
"@types/react": "16.x",
Expand Down
14 changes: 7 additions & 7 deletions packages/website/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "bumbag-website",
"private": true,
"version": "1.0.2",
"version": "1.0.3-ssr-perf.1",
"dependencies": {
"@fortawesome/free-brands-svg-icons": "5.14.0",
"@fortawesome/free-solid-svg-icons": "5.13.1",
"@mdx-js/mdx": "1.1.0",
"@mdx-js/react": "1.0.27",
"base64-url": "2.3.2",
"bumbag": "^1.0.2",
"bumbag-addon-highlighted-code": "^1.0.2",
"bumbag-addon-markdown": "^1.0.2",
"bumbag-server": "^1.0.0",
"bumbag-theme-medipass": "^1.0.0",
"bumbag": "^1.0.3-ssr-perf.1",
"bumbag-addon-highlighted-code": "^1.0.3-ssr-perf.1",
"bumbag-addon-markdown": "^1.0.3-ssr-perf.1",
"bumbag-server": "^1.0.3-ssr-perf.0",
"bumbag-theme-medipass": "^1.0.3-ssr-perf.0",
"change-case": "3.1.0",
"classnames": "2.2.6",
"gatsby": "^2.21.33",
"gatsby-image": "^2.4.3",
"gatsby-plugin-bumbag": "^1.0.0",
"gatsby-plugin-bumbag": "^1.0.3-ssr-perf.0",
"gatsby-plugin-google-analytics": "2.3.11",
"gatsby-plugin-manifest": "^2.4.3",
"gatsby-plugin-mdx": "1.2.7",
Expand Down
4 changes: 3 additions & 1 deletion packages/website/src/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export default class MyDocument extends Document {

Then, open up your `_app.js` file, and add the `<BumbagProvider>`:

**Make sure you add `isSSR` as a prop to `BumbagProvider`. This will help with color mode consistency.**


```jsx
import NextApp from 'next/app';
Expand All @@ -141,7 +143,7 @@ export default class App extends NextApp {
render() {
const { Component, pageProps } = this.props;
return (
<BumbagProvider>
<BumbagProvider isSSR>
<Component {...pageProps} />
</BumbagProvider>
);
Expand Down

0 comments on commit 8d29d07

Please sign in to comment.