<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues?q=is%3Aissue">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behavior</h2>
<p dir="auto">When dispatching an additional action (the middleware is <code class="notranslate">await</code>ing the second action before forwarding the first action to <code class="notranslate">next()</code>) from a redux middleware invoked by an action call in <code class="notranslate">getInitialProps</code>, the function should await both of the action promises resolving before rendering.</p>
<h2 dir="auto">Current Behavior</h2>
<p dir="auto">Server render does not include state from store dispatched by either action creator. If I don't <code class="notranslate">await</code> the second action call, state from the first action creator is present. As soon as the page is hydrated on the client side the actions dispatch normally in <code class="notranslate">componentDidMount()</code>.</p>
<p dir="auto">It seems as if for some reason, the server render is timing out and not waiting for <code class="notranslate">getInitialProps</code> to resolve.</p>
<p dir="auto"><code class="notranslate">getInitalProps</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="static async getInitialProps({
    store: { dispatch },
    query: { slug },
    res,
  }) {
    await dispatch(getActiveOrg(slug)).catch(
      ({ response: { status } }) =&gt; {
        if (status === 404) {
          res.statusCode = 404;
        }
      },
    );
    return {
      slug,
    };
  }"><pre class="notranslate"><span class="pl-k">static</span> <span class="pl-s1">async</span> <span class="pl-en">getInitialProps</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-c1">store</span>: <span class="pl-kos">{</span> dispatch <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">query</span>: <span class="pl-kos">{</span> slug <span class="pl-kos">}</span><span class="pl-kos">,</span>
    res<span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">await</span> <span class="pl-en">dispatch</span><span class="pl-kos">(</span><span class="pl-en">getActiveOrg</span><span class="pl-kos">(</span><span class="pl-s1">slug</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">catch</span><span class="pl-kos">(</span>
      <span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">response</span>: <span class="pl-kos">{</span> status <span class="pl-kos">}</span> <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">status</span> <span class="pl-c1">===</span> <span class="pl-c1">404</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-c1">statusCode</span> <span class="pl-c1">=</span> <span class="pl-c1">404</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
      slug<span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span></pre></div>
<p dir="auto">middleware:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default ({ dispatch }) =&gt; next =&gt; async action =&gt; {
  if (action.type === ORGANIZATION_INFO_RECEIVED) {
    const { payload } = action;
    if (payload.donor_landing_page === 'cause') {
      await dispatch(
        fetchCauses(
          payload.subdomain,
          payload.donor_landing_page_id,
        ),
      );
    }
  }
  next(action);
};"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-kos">(</span><span class="pl-kos">{</span> dispatch <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">next</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">async</span> <span class="pl-s1">action</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">action</span><span class="pl-kos">.</span><span class="pl-c1">type</span> <span class="pl-c1">===</span> <span class="pl-c1">ORGANIZATION_INFO_RECEIVED</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-kos">{</span> payload <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">action</span><span class="pl-kos">;</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">payload</span><span class="pl-kos">.</span><span class="pl-c1">donor_landing_page</span> <span class="pl-c1">===</span> <span class="pl-s">'cause'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">await</span> <span class="pl-en">dispatch</span><span class="pl-kos">(</span>
        <span class="pl-en">fetchCauses</span><span class="pl-kos">(</span>
          <span class="pl-s1">payload</span><span class="pl-kos">.</span><span class="pl-c1">subdomain</span><span class="pl-kos">,</span>
          <span class="pl-s1">payload</span><span class="pl-kos">.</span><span class="pl-c1">donor_landing_page_id</span><span class="pl-kos">,</span>
        <span class="pl-kos">)</span><span class="pl-kos">,</span>
      <span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
  <span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-s1">action</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">Context</h2>
<p dir="auto">The goal of this redux middleware is to allow for conditionally fetching additional data before the server response dependent on the response of an initial API call.</p>
<h2 dir="auto">Your Environment</h2>
<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>5.0.0</td>
</tr>
</tbody>
</table>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="176262894" data-permission-text="Title is private" data-url="https://github.com/gaearon/react-hot-loader/issues/356" data-hovercard-type="issue" data-hovercard-url="/gaearon/react-hot-loader/issues/356/hovercard" href="https://github.com/gaearon/react-hot-loader/issues/356">gaearon/react-hot-loader/issues/356</a> is the closest I found.</p>
<h2 dir="auto">Expected Behavior</h2>


<p dir="auto">Error free .next/bundles/pages/index.js</p>
<h2 dir="auto">Current Behavior</h2>


<p dir="auto">Firefox throws:</p>
<blockquote>
<p dir="auto">process.env is undefined</p>
</blockquote>
<p dir="auto">Chromium says:</p>
<blockquote>
<p dir="auto">TypeError: Cannot read property 'NODE_ENV' of undefined</p>
</blockquote>
<p dir="auto">both originate from:<br>
<code class="notranslate">;(function register() { /* react-hot-loader/webpack */ if (process.env.NODE_ENV !== 'production') { if (typeof __REACT_HOT_LOADER__ === 'undefined') { return; }</code></p>
<p dir="auto">In most places the generated index.js reads:<br>
<code class="notranslate">;(function register() { /* react-hot-loader/webpack */ if (true) { if (typeof __REACT_HOT_LOADER__ === 'undefined') { return; }</code></p>
<p dir="auto">Something, and I can't figure out what, triggered webpack and/or react-hot-loader to use "process.env.NODE_ENV" in the front-end, which kills it.</p>
<h2 dir="auto">Context</h2>


<p dir="auto">"next dev" is rendered useless, because the hot-reload feature breaks the front-end coding.</p>
<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>4.1.4</td>
</tr>
<tr>
<td>node</td>
<td>6.12.0</td>
</tr>
<tr>
<td>OS</td>
<td>Ubuntu 17.10</td>
</tr>
<tr>
<td>browser</td>
<td>Firefox and Chromium</td>
</tr>
</tbody>
</table>
<p dir="auto">Any help would be greatly appreciated. Banging my head against the wall since days :(<br>
Unfortunately I wasn't able to create a minimal-example, so if any code is required I will happily share it.</p>