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

(preact-iso) - avoid calling onLoadEnd on every render #864

Merged
merged 9 commits into from
Sep 9, 2021

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Sep 8, 2021

Fixes #836

Ref solution: d6c87e3 (ties into the effect on every render)
State solution: 9603647 (avoids using effect on every render)

@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2021

🦋 Changeset detected

Latest commit: 7e28300

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-iso Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -176,7 +178,8 @@ export function Router(props) {

// The route is loaded and rendered.
if (wasPush) scrollTo(0, 0);
if (props.onLoadEnd) props.onLoadEnd(url);
if (props.onLoadEnd && isLoading.current) props.onLoadEnd(url);
isLoading.current = false;
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bigger issue is here as we're basically calling this layout-effect on ever single render rather than when it's needed, as this effect is inherently built on refs it's hard to give a reliable deps array, a reliable way would be to use a state for the loading times

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - that behavior is intentional though - the effect callback runs after every render to check whether that render suspended or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but suspending should be part of the observed state else you're hoping that the render cycle of your top-level router ties in with your suspended boundary, this implies that your useReducer and lazy.setState happen correctly

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2021

Size Change: +126 B (+2%)

Total Size: 6.32 kB

Filename Size Change
packages/preact-iso/.dist/index.********.js 1.72 kB +52 B (+3%)
packages/preact-iso/.dist/prerender.********.js 348 B -2 B (-1%)
packages/preact-iso/router.js 2.54 kB +76 B (+3%)
ℹ️ View Unchanged
Filename Size
packages/preact-iso/hydrate.js 290 B
packages/preact-iso/index.js 195 B
packages/preact-iso/lazy.js 594 B
packages/preact-iso/prerender.js 629 B

compressed-size-action

@developit
Copy link
Member

If we land this, I feel like we should also land a callback that fires after every successful route (sync or async), like onDidRoute. I often want to register a callback to do stuff like change title/reset scroll/etc

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Love the tests! Thank you so much 🙌

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

Successfully merging this pull request may close these issues.

onLoadEnd fires on every render on preact-iso's Router
3 participants