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

Add dynamic height state (+ add test setup) #207

Merged
merged 18 commits into from
Aug 21, 2022
Merged

Conversation

timolins
Copy link
Owner

@timolins timolins commented Jul 15, 2022

silvenon and others added 12 commits February 14, 2022 15:29
In unit testing measuring dimensions is impossible, so toast height
evaluates to `0`, which causes Toaster to endlessly recompute the height
and update the store. Instead we're being more specific and checking
whether height is `undefined`, and memoizing the ref so that it isn't
being called on every render. This also required other tweaks like
properly memoizing handlers like `updateHeight` so that they can be used as hook
dependencies. (We only needed `updateHeight` to be memoized, though.)
* Toast height will be re-calculated `onLayoutEffect` - #133
* Memoize height ref - #107 - inspired by #154
* Restructure handlers for better memoization

Not entirely happy with the internal API yet. Might need to rework.
@vercel
Copy link

vercel bot commented Jul 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-hot-toast ✅ Ready (Inspect) Visit Preview Jul 17, 2022 at 1:58PM (UTC)

@github-actions
Copy link

github-actions bot commented Jul 15, 2022

size-limit report 📦

Path Size
dist/index.js 4.92 KB (+1.91% 🔺)
dist/index.mjs 4.62 KB (+2.25% 🔺)
headless/index.js 1.79 KB (+1.56% 🔺)
headless/index.mjs 1.5 KB (+1.86% 🔺)

@timolins timolins changed the title Add dynamic height state (+ tests) Add dynamic height state (+ add test setup) Jul 15, 2022
@themagickoala
Copy link

Am I right in thinking the only thing blocking this is the size-limit check? Anything we can do to help this along?

@timolins
Copy link
Owner Author

timolins commented Aug 21, 2022

@themagickoala Indeed, and it feels weird to block it because of it. Wanted to stay true to the "less than 5kb including styles" claim.

There is #217 which would decrease bundle size below 5kb again.

Maybe even won't even hit 5kb as the check returns only 4944 bytes (but still fails?).

That said, I think we'll just merge before blocking it any longer.

@timolins timolins merged commit 28194c5 into main Aug 21, 2022
@timolins timolins deleted the improved-height-measurement branch August 21, 2022 12:12
@themagickoala
Copy link

Thanks @timolins! Will there be a release going out with this soon? My current solution is to mock the library and test the toast method was called, and I'd love to get back to real userland testing.

@timolins
Copy link
Owner Author

timolins commented Sep 3, 2022

Hi @themagickoala – sorry for the delay! I just released 2.4.0-beta.0, which includes those changes. Let me know how it works for you.

@themagickoala
Copy link

Hi @themagickoala – sorry for the delay! I just released 2.4.0-beta.0, which includes those changes. Let me know how it works for you.

Hi @timolins just picked this up today and it looks like this does fix our tests. Thanks so much!

@themagickoala
Copy link

And thanks @silvenon for implementing this!

@silvenon
Copy link
Contributor

silvenon commented Sep 6, 2022

Yay! 🎉

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.

Toast height calculation bug
3 participants