Revert behaviour of code that was using nullish coalescing operator.#39686
Revert behaviour of code that was using nullish coalescing operator.#39686jonathansadowski merged 2 commits intotrunkfrom
Conversation
|
Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: ffe15d0
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
jonathansadowski
left a comment
There was a problem hiding this comment.
Nice job. Fixes the issue at hand and maintains the previous desired behavior. Thanks for the quick fix!
…39686) * Revert behaviour of code that was using nullish coalescing operator. * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <[email protected]>
* Revert behaviour of code that was using nullish coalescing operator. (#39686) * Revert behaviour of code that was using nullish coalescing operator. * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <[email protected]> * Prep for cherry pick 39686 --------- Co-authored-by: Sam Seay <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: WooCommerce Bot <[email protected]>
|
I think the code is unreadable now (and, let's be honest, over twice as slow). What's wrong with the following? $( this ).data( 'minimum_input_length' ) ?? '3' |
|
@sybrew Thank you that's good input. Absolutely I did consider making the change back to I did also consult caniuse at that time but because I was in a hurry I did not cross-check with WP browser support, I just saw that edge up to 80 was not supported and took the safe route, but now looking at it, WP only supports last 2 edge versions so we can safely make this change. I think we can revert back to |
|
Cheers! I'm unfortunately inundated with other projects, so I'll leave the PR to you. Please note that the file has three more instances that could benefit from the current patch's change. Those all look like this: minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3',When stumbling upon this kind of code, if you wish to prevent performance issues altogether where neither const mil = $( this ).data( 'minimum_input_length' ); // Write getter to variable/const.
var something = {
# code here ...
minimumInputLength: +mil ? mil : '3', // read variable without needing to invoke expensive jQuery calls
}
# code here ...Here's another workaround that just came to mind: minimumInputLength: ( +$( this ).data( 'minimum_input_length' ) || '3' ).toString(), |
Changes proposed in this Pull Request:
A while back we removed 2 uses of nullish coalescing operator because we did not have es6 to build the legacy JS.
Unfortunately the replacement code was not functionally equivalent.
??checks if a value is null or undefined, whereas?:ternary checks for falsy value. For example''is falsy. I'm not exactly sure what the intended behaviour is in this code, but it causes this bug: #39667Closes #39667
How to test the changes in this Pull Request:
Use the repro steps from the bug:
Changelog entry
Details
Significance
Type
Message
Fix an issue which was causing some attributes to default to a minimum length of 3.
Comment