Skip to content

Commit

Permalink
Adding time-slicing with startTransition to prevent hydration from …
Browse files Browse the repository at this point in the history
…blocking the main thread for too long for those users who immediately scroll. (#4313)

* Adding timeslicing for hydrating  :)

* update
  • Loading branch information
sanjaiyan-dev authored Aug 25, 2022
1 parent 1aa5208 commit 3b5f34d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/integrations/react/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement } from 'react';
import { createElement, startTransition } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import StaticHtml from './static-html.js';

Expand Down Expand Up @@ -27,7 +27,11 @@ export default (element) =>
delete element[rootKey];
}
if (client === 'only') {
return createRoot(element).render(componentEl);
return startTransition(() => {
createRoot(element).render(componentEl);
})
}
return hydrateRoot(element, componentEl);
return startTransition(() => {
hydrateRoot(element, componentEl);
})
};

0 comments on commit 3b5f34d

Please sign in to comment.