rstacruz / nprogress

For slim progress bars like on YouTube, Medium, etc
http://ricostacruz.com/nprogress
MIT License
26.09k stars 1.81k forks source link

document is undefine in isomorphic react application #159

Open gauravprwl14 opened 7 years ago

gauravprwl14 commented 7 years ago

hey, i am using react starter kit which is an isomorphic boilerplate. i tried using nprogress library in that library but it always give me "document is undefine" error . so can you help in in resolving this issue. screen shot 2016-11-02 at 4 27 06 pm

import React from 'react';
import NProgress from 'nprogress';

export default {

  path: '/dashboard/chartc3',

  async action() {
    NProgress.start();
    const ChartC3 = await new Promise((resolve) => {
      require.ensure([], (require) => resolve(require('./ChartC3')), 'chart_c3');
    });
    NProgress.done();
    return <ChartC3 />;
  },

};
alexlafroscia commented 7 years ago

You're probably going to want to check that you're not on the server before invoking nprogress. Does your React boilerplate have some way of detecting that you're on the server? If not, you could always just check for document before running NProgress.start(), or write a wrapper around the library for yourself that just no-ops on the server instead.

ImadBoumzaoued commented 7 years ago

just check if document is defined in render and isRendered methods, that did it for me