kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 195 forks source link

[question] What is the proper way to avoid document is not defined while using SSR? #549

Open kokjinsam opened 8 years ago

kokjinsam commented 8 years ago

I tried

(1) putting my code in componentDidMount() (2) wrapping my component in <NoSSR> <!--component--> </NoSSR>

I got this error:

ReferenceError: document is not defined
W20160304-13:00:43.407(-6)? (STDERR)     at node_modules/node-waves/src/js/waves.js:35:1
W20160304-13:00:43.407(-6)? (STDERR)     at Waves (node_modules/node-waves/src/js/waves.js:24:1)
W20160304-13:00:43.407(-6)? (STDERR)     at meteorInstall.node_modules.node-waves.src.js.waves.js (node_modules/node-waves/src/js/waves.js:31:1)
W20160304-13:00:43.407(-6)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:202:1)
W20160304-13:00:43.407(-6)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:75:1)
W20160304-13:00:43.407(-6)? (STDERR)     at meteorInstall.app.imports.modules.core.components.button.jsx (/home/skaxwng/code/easy-make/app/.meteor/local/build/programs/server/app/app.js:1291:18)
W20160304-13:00:43.407(-6)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:202:1)
W20160304-13:00:43.408(-6)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:75:1)
W20160304-13:00:43.408(-6)? (STDERR)     at meteorInstall.app.imports.modules.core.components.js (app/imports/modules/core/reducers/index.js:3:16)
W20160304-13:00:43.408(-6)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:202:1)

However, if I do this in my component:

componentDidMount() {
    const Waves = require('node-waves');
    Waves.init();
    Waves.attach(this.refs.button);
  }

Everything works fine. I wonder if there's a better and proper way to deal with this?

ducdev commented 7 years ago

I've got this same issue.