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

fix: Last, not first, non-external script in HTML should have prerender() #905

Merged
merged 3 commits into from
Mar 30, 2022
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
5 changes: 5 additions & 0 deletions .changeset/pink-turtles-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

First script tag in HTML should be assumed to have prerender(), not last
4 changes: 2 additions & 2 deletions packages/wmr/src/lib/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function workerCode({ cwd, out, publicPath, customRoutes }) {
// Grab the generated HTML file, which we'll use as a template:
const tpl = await fs.readFile(path.resolve(cwd, out, 'index.html'), 'utf-8');

// The first script in the file that is not external is assumed to have a
// The last script in the file that is not external is assumed to have a
// `prerender` export
let script;
const SCRIPT_TAG = /<script(?:\s[^>]*?)?\s+src=(['"]?)([^>]*?)\1(?:\s[^>]*?)?>/g;
Expand Down Expand Up @@ -103,7 +103,7 @@ async function workerCode({ cwd, out, publicPath, customRoutes }) {
// const App = m.default || m[Object.keys(m)[0]];

if (typeof doPrerender !== 'function') {
throw Error(`No prerender() function was exported by the first <script src="..."> in your index.html.`);
throw Error(`No prerender() function was exported by the last non-external <script src="..."> in your index.html.`);
}

/**
Expand Down