fix: parse Image srcSet densities consistently#56890
Conversation
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D105689719. |
| ); | ||
| } else { | ||
| const scale = parseInt(xScale.split('x')[0], 10); | ||
| const scale = Number(xScale.slice(0, -1)); |
There was a problem hiding this comment.
Number('') returns 0 (not NaN), so a bare 'x' descriptor (no preceding number) now silently produces scale: 0 instead of being filtered by the isNaN check.
Maybe use parseFloat() instead of Number()? parseFloat('') returns NaN (matching the old guard behavior) while parseFloat('1.5') still correctly returns 1.5.
There was a problem hiding this comment.
Good catch, thanks. I switched this to parseFloat and added a regression case for the bare x descriptor so it stays filtered out.
I also fixed the changelog heading in the PR body.
Validated with:
yarn jest packages/react-native/Libraries/Image/__tests__/ImageSourceUtils-test.js --runInBandnpx prettier --check packages/react-native/Libraries/Image/ImageSourceUtils.js packages/react-native/Libraries/Image/__tests__/ImageSourceUtils-test.jsyarn flow-check
Updated commit: 5c47a49
07f60e3 to
5c47a49
Compare
|
This pull request was successfully merged by @ya-nsh in e4cf0a1 When will my fix make it into a release? | How to file a pick request? |
Summary
srcSetentries even when there is no space after the comma1.5xxdescriptors out of the source listChangelog:
[General] [Fixed] - Parse Image srcSet density descriptors consistently
Test Plan
yarn jest packages/react-native/Libraries/Image/__tests__/ImageSourceUtils-test.js --runInBandnpx prettier --check packages/react-native/Libraries/Image/ImageSourceUtils.js packages/react-native/Libraries/Image/__tests__/ImageSourceUtils-test.jsyarn flow-check