preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.92k stars 109 forks source link

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

Closed rschristian closed 2 years ago

rschristian commented 2 years ago

The first script tag in the file should be assumed to have a prerender(), however, due to the loop continuing even after the first non-external script tag is found, it was actually the last script tag that was used and would need to have prerender().

It should be noted that this behavior has existed for the past 9 months, and fixing it could potentially cause someone's setup to break. We could just flip the error message/comments instead?

https://github.com/preactjs/wmr/blob/039f79925ecab2e277d32e1f4f7341d38a222b59/packages/wmr/src/lib/prerender.js#L106

changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: 4494e19a52e1cf11c1849b6d66ebc2181dab001d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---- | ----- | | wmr | Patch |

Not sure what this means? Click here to learn what changesets are.

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/preactjs/wmr/new/fix/script-tag-prerender?filename=.changeset/perfect-apes-tell.md&value=---%0A%22wmr%22%3A%20patch%0A---%0A%0Afix%3A%20First%2C%20not%20last%2C%20non-external%20script%20in%20HTML%20should%20have%20prerender()%0A)

developit commented 2 years ago

oooof, yeah. TBH that's a solid argument in favor of flipping the error message. I can think of cases where first script is likely not the correct one (polyfills), but I can also think of cases where the last script is incorrect (analytics).

github-actions[bot] commented 2 years ago

Size Change: +4 B (0%)

Total Size: 806 kB

Filename Size Change
packages/wmr/wmr.cjs 767 kB +4 B (0%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `examples/demo/dist/about/index.html` | 721 B | | `examples/demo/dist/alias-outside/index.html` | 697 B | | `examples/demo/dist/assets/Calendar.********.css` | 694 B | | `examples/demo/dist/assets/style.********.css` | 624 B | | `examples/demo/dist/chunks/alias-outside.********.js` | 138 B | | `examples/demo/dist/chunks/class-fields.********.js` | 211 B | | `examples/demo/dist/chunks/compat.********.js` | 15.7 kB | | `examples/demo/dist/chunks/hoofd.module.********.js` | 1.48 kB | | `examples/demo/dist/chunks/index.********.js` | 201 B | | `examples/demo/dist/chunks/json.********.js` | 239 B | | `examples/demo/dist/chunks/meta-tags.********.js` | 297 B | | `examples/demo/dist/chunks/prerender.********.js` | 2.47 kB | | `examples/demo/dist/class-fields/index.html` | 709 B | | `examples/demo/dist/compat/index.html` | 1.62 kB | | `examples/demo/dist/env/index.html` | 783 B | | `examples/demo/dist/error/index.html` | 714 B | | `examples/demo/dist/files/index.html` | 744 B | | `examples/demo/dist/index.********.js` | 7.8 kB | | `examples/demo/dist/index.html` | 775 B | | `examples/demo/dist/json/index.html` | 719 B | | `examples/demo/dist/lazy-and-late/index.html` | 723 B | | `examples/demo/dist/meta-tags/index.html` | 789 B |

compressed-size-action

rschristian commented 2 years ago

Will do that instead (only thought of it after I pushed, whoops).

Analytics will probably end up being external more often than not, ensuring they get skipped. So long as the error messages matches the behavior it should be an easy and quick correction anyways.