SSR: tolerate floating point imprecision #220
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I encountered a weird bug during SSR hydration on the client. I discovered the cause to be
Math.cos
withinlat2tile
not yielding the same results on the server and in my browser, a difference not bigger than floating point imprecision.It appears the issue is related to the problem described here: https://stackoverflow.com/questions/26570626/math-log2-precision-has-changed-in-chrome
Without these changes, the following mismatched diff causes the hydration error.
Note how the diff indicates that the
transition
property also indicates a problem (explicit vs. compact definition), but NextJS is actually able to understand that there is no issue in this case; the problem is solely caused by the arguably differenttransform
values. This is why I believe this might be relevant for #168.I also did some dogfood while I was on it, let me know what you think! And thank you for this awesome library 🚀
Node version: 20.18.1
React version: 19.0.0
NextJS version: 15.1.6
Client browser: Chrome 132