-
-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Marvin Hagemeister <[email protected]>
- Loading branch information
1 parent
e786c70
commit 31b07e7
Showing
66 changed files
with
1,305 additions
and
1,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
diff --git a/node_modules/preact-cli/src/lib/webpack/prerender.js b/node_modules/preact-cli/src/lib/webpack/prerender.js | ||
index 945a4e0..e8323d3 100644 | ||
--- a/node_modules/preact-cli/src/lib/webpack/prerender.js | ||
+++ b/node_modules/preact-cli/src/lib/webpack/prerender.js | ||
@@ -2,7 +2,7 @@ const { red, yellow } = require('kleur'); | ||
const { resolve } = require('path'); | ||
const { readFileSync } = require('fs'); | ||
const stackTrace = require('stack-trace'); | ||
-const URL = require('url'); | ||
+const { URL } = require('url'); | ||
const { SourceMapConsumer } = require('source-map'); | ||
|
||
module.exports = async function (config, params) { | ||
@@ -11,14 +11,14 @@ module.exports = async function (config, params) { | ||
let entry = resolve(config.dest, './ssr-build/ssr-bundle.js'); | ||
let url = params.url || '/'; | ||
|
||
- global.history = {}; | ||
- global.location = { ...URL.parse(url) }; | ||
+ global.history = /** @type {object} */ ({}); | ||
+ global.location = /** @type {object} */ (new URL(url, 'http://localhost')); | ||
|
||
try { | ||
let m = require(entry), | ||
- app = (m && m.default) || m; | ||
+ vnode = (m && m.default) || m; | ||
|
||
- if (typeof app !== 'function') { | ||
+ if (typeof vnode !== 'function') { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'Entry does not export a Component function/class, aborting prerendering.' | ||
@@ -29,7 +29,23 @@ module.exports = async function (config, params) { | ||
const renderToString = require(require.resolve('preact-render-to-string', { | ||
paths: [config.cwd], | ||
})); | ||
- return renderToString(preact.h(app, { ...params, url })); | ||
+ | ||
+ vnode = preact.h(vnode, { ...params, url }); | ||
+ | ||
+ // Slightly modified version of preact-iso's `prerender()` | ||
+ let tries; | ||
+ const maxDepth = 10; | ||
+ const render = () => { | ||
+ if (++tries > maxDepth) return; | ||
+ try { | ||
+ return renderToString(vnode); | ||
+ } catch (e) { | ||
+ if (e && e.then) return e.then(render); | ||
+ throw e; | ||
+ } | ||
+ }; | ||
+ | ||
+ return await render(); | ||
} catch (err) { | ||
let stack = stackTrace.parse(err).filter(s => s.getFileName() === entry)[0]; | ||
if (!stack) { |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.