Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try prerender-trigger event only after body has been updated to make sure Elm has rendered. #61

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generator/src/add-files-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = class AddFilesPlugin {
};
});

this.filesToGenerate.forEach(file => {
(this.filesToGenerate || []).forEach(file => {
// Couldn't find this documented in the webpack docs,
// but I found the example code for it here:
// https://github.com/jantimon/html-webpack-plugin/blob/35a154186501fba3ecddb819b6f632556d37a58f/index.js#L470-L478
Expand Down
10 changes: 6 additions & 4 deletions generator/src/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ function webpackOptions(
},
resolve: {
modules: [
path.resolve(process.cwd(), `./node_modules`),
path.resolve(process.cwd(), `./node_modules`),
// TODO: find a cleaner way to do this.
// This line just needs a way to point to the `node_modules` directory
// for the library bin (not the user's node_modules, which is the
// for the library bin (not the user's node_modules, which is the
// process.cwd prefixed node_modules above).
path.resolve(path.dirname(require.resolve('webpack')), '../../'),

Expand Down Expand Up @@ -306,7 +306,9 @@ function webpackOptions(
new PrerenderSPAPlugin({
staticDir: path.join(process.cwd(), "dist"),
routes: routes,
renderAfterDocumentEvent: "prerender-trigger"
renderer: new PrerenderSPAPlugin.PuppeteerRenderer({
renderAfterDocumentEvent: "prerender-trigger",
})
})
],
module: {
Expand Down Expand Up @@ -334,7 +336,7 @@ function webpackOptions(
new webpack.NamedModulesPlugin(),
// Prevents compilation errors causing the hot loader to lose state
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin()
new webpack.HotModuleReplacementPlugin()
],
module: {
rules: [
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ function loadContentAndInitializeApp(/** @type { init: any } */ mainElmModule)
headTags.forEach(headTag => {
appendTag(headTag);
});

new MutationObserver(function() {
document.dispatchEvent(new Event("prerender-trigger"));
}).observe(document.body, { attributes: true, childList: true, subtree: true});

} else {
setupLinkPrefetching();
}

document.dispatchEvent(new Event("prerender-trigger"));
});

return app
Expand Down