-
Notifications
You must be signed in to change notification settings - Fork 106
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
Min/max aspect ratios should be be rounded to a fixed nearest decimal #1765
Comments
Just thinking out loud here... When exploring potential solutions, one idea that came to mind was to convert the float values to strings before JSON encoding. Then on the client side, we could convert them back to numbers when needed. This approach seems straightforward, though it introduces an extra step in handling these values. I also came across another potential solution involving PHP's $original_precision = ini_get( 'serialize_precision' );
ini_set( 'serialize_precision', -1 );
// ... wp_json_encode( $detect_args ) ...
ini_set( 'serialize_precision', $original_precision ); This seems to address the issue as well, but I'm not entirely sure about the potential pitfalls of changing configuration values at runtime. It doesn’t feel like the cleanest approach. |
Another option would be simply to export the |
@westonruter confused by your comment |
@pbearne well, I see you closed your PR so I assumed it hadn't worked. |
no, my mistake Create new pull request |
Well, I tested it and now I'm getting the desired output:
But I'm now seeing the same on |
@westonruter I did some testing and found that this behavior seems to depend on the environment configuration. When using {"minViewportAspectRatio":0.4,"maxViewportAspectRatio":2.5} However, I set up another site using LocalWP and noticed the output was different. After investigating, I discovered that the root cause is tied to the According to the PHP documentation:
This means that environments running PHP 7.1 or later should not encounter this issue unless As for the use of Given this, it might not be necessary to take any specific action, as the default configuration ( |
Looking at a site in the wild I see the following in the page source:
This is a laughable
minViewportAspectRatio
. Nevertheless, the values0.4
and2.5
are what show up in the source:performance/plugins/optimization-detective/storage/data.php
Line 313 in ebec285
performance/plugins/optimization-detective/storage/data.php
Line 335 in ebec285
Aren't floating point numbers fun.
I'm not sure how having such a long decimal would be prevented, as the return value of the functions there is sent straight to be exported as JSON here:
performance/plugins/optimization-detective/detection.php
Lines 91 to 93 in ebec285
performance/plugins/optimization-detective/detection.php
Line 122 in ebec285
Not a big issue.
The text was updated successfully, but these errors were encountered: