openameba/react-safety-helmet

renderToNodeStream issues

Joelgullander opened this issue · 1 comments

I'm not sure what i'm doing wrong here, I followed your guidelines on renderToNodeStream:

const helmetStore = createHelmetStore();
hydrate(
  <HelmetProvider store={helmetStore}>
    <Helmet>
      <meta name="description" content="Helmet application" />
    </Helmet>
    <Provider store={store}>
      <ConnectedRouter history={history}>
        <ScrollToTopHoc>
          <App />
        </ScrollToTopHoc>
      </ConnectedRouter>
    </Provider>
  </HelmetProvider>,
  document.getElementById('root')
);

My SSR:

new Promise((resolve, reject) => {
      const helmetStore = createHelmetStore();
      let body = '';
      renderToNodeStream(
        <HelmetProvider store={helmetStore}>
          <Provider store={store}>
            <ConnectedRouter history={history} location={context}>
              <App/>
            </ConnectedRouter>
          </Provider>
        </HelmetProvider>
      )
        .on('data', (chunk) => {
          body += chunk;
        })
        .on('error', (err) => {
          reject(err);
        })
        .on('end', () => {
          resolve({
            body,
            helmet: helmetStore.renderStatic(),
          });
        });
    }).then(({body, helmet}) => {
     // Just logging the helmet data and it doesnt return anything.
      logger.log({
        level: 'error',
        message: `testme::::::: blablabla ${JSON.stringify(helmet)}`
      });
      var readStream = fs.createReadStream(htmlFilePath);

      return readStream
        .pipe(htmlReplace('#root', renderToNodeStream(body)))
        .pipe(replaceStream('__SERVER_DATA__', serialize(store.getState())))
        .pipe(res.status(status))

        // Create html with body and helmet object
    });

The issue i'm getting is that helmet returns nothing even if I define meta tags in the top level of my react components. helmet.meta = {} and so on.

@Joelgullander Hi, I have replied in this thread.
#4 (comment)
Best wishes!