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

Weird empty sheet on first (pre)render #2

Open
danielweck opened this issue Mar 11, 2021 · 1 comment
Open

Weird empty sheet on first (pre)render #2

danielweck opened this issue Mar 11, 2021 · 1 comment

Comments

@danielweck
Copy link
Member

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 :)

@sastan
Copy link
Collaborator

sastan commented Mar 11, 2021

The async rendering stuff can be tricky. That is one of the reasons we are thinking about refactoring this API into something like const result = await sheet.collectStyles(() => prerender(app))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants