gabrielbull / react-router-server

Server Side Rendering library for React Router v4.
MIT License
434 stars 17 forks source link

endless loop using `babel-preset-env` with node >= 4 #31

Closed tswaters closed 6 years ago

tswaters commented 7 years ago

It looks like the transpile is slightly different when the preset-env picks up that the node environment supports arrow functions. The regular expressions aren't matching properly and things go haywire.

The imports before --

// unminified
function () {
  return __webpack_require__.e/* import() */(6).then(__webpack_require__.bind(null, 73));
}

// minified
function (){return l.e(6).then(l.bind(null,73))}

And after --

// unminified
() => __webpack_require__.e/* import() */(6).then(__webpack_require__.bind(null, 73))

// minified
()=>t.e(6).then(t.bind(null,73))

In the unminified case, the first loadFunc still matches but the second does not - meaning we'll keep trying to re-render indefinitely (endless loop). In the minified case, neither matches so there's no endless loop but modules comes back as empty.

Unless I'm missing something here, I think the regular expression could be greatly simplified by just matching the number inside a parenthetical before .then... i.e., /\(([0-9]*)\).then/

Then again, there's not a lot of tests describing what the expected values are going for this loadFunc.... in my limited testing, I wasn't able to get the block commented as system import or system import minimized to hit, despite the un-transpiled code looking something like....

<Switch>
{asyncRoute('/', () => System.import('./home'))}
</Switch>