Skip to content

fix: Memoize route component to avoid double render for incoming async routes#72

Merged
rschristian merged 2 commits intomainfrom
fix/double-render
Mar 2, 2025
Merged

fix: Memoize route component to avoid double render for incoming async routes#72
rschristian merged 2 commits intomainfrom
fix/double-render

Conversation

@rschristian
Copy link
Member

@rschristian rschristian commented Feb 26, 2025

Similar-ish to #69, #12 seems to cause a lot of unnecessary renders which @sbesh91 and I have been working out.

Not sure it's ideal but covers the simple cases anyhow. For the more complex, see comment below I suppose?

rschristian and others added 2 commits February 25, 2025 21:06
Co-authored-by: Steven Beshensky <s.beshensky@gmail.com>
}
return false;
}, [url]);
}, [url, JSON.stringify(matchProps)]);
Copy link
Member Author

@rschristian rschristian Feb 27, 2025

Choose a reason for hiding this comment

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

@JoviDeCroock Have any opinions on what we do here? Obviously JSON.stringify ain't ideal though I'm not sure if we want to start doing deep comparisons ourselves or with a dep either.

As the updated test cases show, your changes in #12 have us rendering routes more often than we should, but to not regress we'd need a dependency on the user-passed props.

@rschristian rschristian marked this pull request as ready for review February 28, 2025 00:44
await sleep(10);

expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
expect(B).to.have.been.calledOnce;
Copy link
Member Author

Choose a reason for hiding this comment

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

Prior to this, B (or any async route) would be called twice after route change.

@rschristian rschristian requested a review from JoviDeCroock March 1, 2025 20:19
@rschristian rschristian changed the title fix: Try to fix unnecessary double-render fix: Memoize route component to avoid double render for incoming async routes Mar 2, 2025
@rschristian rschristian merged commit 89140b7 into main Mar 2, 2025
1 check passed
@rschristian rschristian deleted the fix/double-render branch March 2, 2025 09:00
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.

2 participants