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

Feature request - Add events for prerender phases #402

Open
gregjopa opened this issue May 2, 2022 · 5 comments
Open

Feature request - Add events for prerender phases #402

gregjopa opened this issue May 2, 2022 · 5 comments

Comments

@gregjopa
Copy link
Contributor

gregjopa commented May 2, 2022

Zoid has the following event feature for tracking when rendering completes: https://github.com/krakenjs/zoid/blob/main/docs/api/create.md#listening-to-zoid-events. These RENDER and RENDERED events work great for measuring rendering performance. However, we are missing events for knowing when the prerender phase is complete with prerenderTemplate.

To solve this problem let's add the following new events for hooking into the prerender lifecycle:

  1. onPrerender (EVENT.PRERENDER) - prerender starts
  2. onPrerendered (EVENT.PRERENDERED) - prerender finishes
    prerenderTemplate: function containerTemplate({ doc, event }) {

        event.on(EVENT.PRERENDERED, () => {
            performance.mark('prerender-complete');
        });
        // rest of the prerenderTemplate code...
    }
@bluepnume
Copy link
Collaborator

bluepnume commented May 2, 2022

Totally possible, but remember prerender is completely synchronous, so you can just do:

    prerenderTemplate: function containerTemplate({ doc, event }) {
        log('START_PRERENDER');
        
        // do the prerender
        
        log('END_PRERENDER');
    }

That said -- this won't be that useful since:

  1. Prerender start will be virtually the same time as the 'render' event time, since prerender and render are kicked off at the same time
  2. Prerender end will be virtually the same time as prerender start, since it's a synchronous function (always)

@gregjopa
Copy link
Contributor Author

gregjopa commented May 2, 2022

  1. Prerender end will be virtually the same time as prerender start, since it's a synchronous function (always)

What about the time it takes to insert the prerenderFrame into the DOM? Here's the code I'm referring to.

writeElementToWindow(prerenderWindow, el);
. My thought is we need EVENT.PRERENDERED to include that cost.

@bluepnume
Copy link
Collaborator

Aaah that's fair. Yeah it's still synchronous; but definitely wouldn't hurt to measure. No objections!

@gregjopa
Copy link
Contributor Author

gregjopa commented May 2, 2022

Sweet thanks for the review @bluepnume!

@jmichaelterenin
Copy link

@gregjopa Are we able to pull this version (with PRERENDER/ED)? it's not available on the Cloudflare CDN and I can't get npm to install v10.1.0, as either a version or tag. Please help if you have a moment

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

3 participants