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

Wait for all async to settle before capturing HTML when prerendering #116

Open
lencioni opened this issue Sep 20, 2019 · 0 comments
Open

Comments

@lencioni
Copy link
Contributor

I'm not even totally sure this kind of thing would be useful, so this is more of just an idea.

I wonder if diffs could be made more stable by waiting for any in-flight async things (e.g. setTimeout) to settle before capturing the HTML when prerendering. Code that looks something like this could be used to handle setTimeout, for instance:

    const timers = new Set();
    originalSetTimeout = window.setTimeout;
    originalClearTimeout = window.clearTimeout;
    
    function deleteTimer(id) {
      timers.delete(id);
      if (timers.size === 0) {
        // Something here, like a callback maybe
      }
    }
    
    window.setTimeout = function(cb, delay) {
      const id = originalSetTimeout(() => {
        cb();
        
        deleteTimer(id);
      }, delay);
      
      timers.add(id);
      return id;
    }
    
    window.clearTimeout = function(id) {
      deleteTimer(id);      
      return originalClearTimeout(id);
    };
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

1 participant