From 13b624bc05b5fe2a69505a877d51bbb1604b1348 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Fri, 16 Feb 2018 15:49:41 -0800 Subject: [PATCH] Makes Toast SSR compatible #66 --- packages/marble-topbar/src/Topbar.js | 5 +++++ packages/marble-topbar/test/Topbar.node.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/marble-topbar/test/Topbar.node.js diff --git a/packages/marble-topbar/src/Topbar.js b/packages/marble-topbar/src/Topbar.js index c4a0100..8e84ad4 100644 --- a/packages/marble-topbar/src/Topbar.js +++ b/packages/marble-topbar/src/Topbar.js @@ -1,3 +1,4 @@ +import {isServerSide} from 'metal'; import Component from 'metal-component'; import Soy from 'metal-soy'; import Toggler from 'metal-toggler'; @@ -10,6 +11,10 @@ import templates from './Topbar.soy.js'; */ class Topbar extends Component { attached() { + if (isServerSide()) { + return; + } + this.toggler = new Toggler({ content: '.topbar-list', header: '.topbar-toggle', diff --git a/packages/marble-topbar/test/Topbar.node.js b/packages/marble-topbar/test/Topbar.node.js new file mode 100644 index 0000000..ff7f724 --- /dev/null +++ b/packages/marble-topbar/test/Topbar.node.js @@ -0,0 +1,13 @@ +/** + * @jest-environment node + */ + +import Component from 'metal-component'; +import Topbar from '../src/Topbar'; + +describe('Topbar.node', () => { + it('should not fail on the server side', () => { + const topbar = Component.renderToString(Topbar); + expect(topbar).not.toBeNull(); + }); +});