Skip to content

Weird empty sheet on first (pre)render #2

@danielweck

Description

@danielweck

Interesting! In my tests, I can reliably reproduce sheet.target.length === 0 on the very first invocation of prerender (typically: index.html), UNLESS I yield CPU cycles immediately after sheet.reset() (before prerender()). I presume this gives the message pump some time to flush (async_hook -related behaviour?)

sheet.reset()
const result = await prerender(app)

This works
await new Promise((res) => setTimeout(res, 0));
...at first I tried 1s, and realised it only needed a "defer" with zero delay), so I used this instead:
await new Promise((res) => process.nextTick(res));

I only do this on first render, and I throw an exception if !sheet.target.length immediately after prerender().

Fun edge cases :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions