Open resolritter opened 1 year ago
Latest commit: d4f8dd9af2cafbb377cc7797cb991f0a0135ca49
The changes in this PR will be included in the next version bump.
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
Problem
Due to some unknown issue with
lazy
, theprerender
function was not working as intended for my components. I eventually overcame that problem, but I did not know it was was happening in the first plac until I looked into the generated HTML and noticed it was wrong. In other words, theprerender
is failing silently since the error path is not being handled correctly, as I'll explain below.The problem is related to this line:
https://github.com/preactjs/wmr/blob/3c5672ecd2f958c8eaf372d33c084dc69228ae3f/packages/preact-iso/prerender.js#L49
The
render
function was returningundefined
because my components could not be rendered correctly. Then we go into the next line:https://github.com/preactjs/wmr/blob/3c5672ecd2f958c8eaf372d33c084dc69228ae3f/packages/preact-iso/prerender.js#L50
Since
html
wasundefined
, the generated HTML would becomeundefined<script type="isodata"></script>
, which is not what I want.Solution
There should be a way of generating an exception in case the components cannot be rendered correctly. For that, this PR introduces the
throwOnFailure
option which controls what happens in case rendering fails. It defaults to a falsy value for preservingprerender
's current behavior, but arguably it should be true.