react-native-url-polyfill icon indicating copy to clipboard operation
react-native-url-polyfill copied to clipboard

Dead code in JS bundles

Open retyui opened this issue 5 months ago • 2 comments

2.65KB of useless code in my JS bundle, could please avoid importing package.json

Image

retyui avatar Jun 29 '25 11:06 retyui

I assume if developers need to get the pkg version, they can import it themselves:

require('react-native-url-polyfill/package.json').version

retyui avatar Jun 29 '25 11:06 retyui

This is used to know if the polyfill is correctly loaded and with which version, see: https://github.com/charpeni/react-native-url-polyfill/blob/f432de38c370b45e99404eb46f081f390876726d/index.js#L9

If we truly want to strip this 2.65 KB, we could use a bundler that will replace the whole import and only leave the version number as a string within the bundled code.

charpeni avatar Jun 29 '25 11:06 charpeni

This is currently documented in the README.md as a way to assert whether the polyfill was successfully applied or not. I don't expect people to commit console logs or debugging statements as such in their codebase, this is mostly a one-time call when installing.

Your search query has a scope limited to this repository (repo:charpeni/react-native-url-polyfill), which I wouldn't consider the "rest of the world." However, even with a working search query, I wouldn't consider public repositories as the "rest of the world."

Nevertheless, your issue remains valid, as mentioned above. If we want to strip out 2.65 KB from this library, we should use a bundler to optimize package.json imports by replacing them with the actual string value rather than bundling the whole JSON file.

charpeni avatar Jul 02 '25 13:07 charpeni

@charpeni I truly apologize for the tone of my comment in the GitHub issue; I now understand it came off harsher than intended. I honestly did not intend to offend or disrespect you in any way.

retyui avatar Jul 02 '25 14:07 retyui

Thanks, no offense taken.

Thank you for hunting wasted kilobytes in the React Native community. I know it's coming from good intentions. You will likely help discover multiple duplicate packages or other unnecessary elements that are bloating React Native applications.

Interestingly enough, this is the main reason why this library was created in the first place: to provide a way to use URL within React Native apps without the bloat of whatwg-polyfill (372 KB). So I definitely understand the frustration here. 🙂

charpeni avatar Jul 02 '25 14:07 charpeni

we should use a bundler to optimize package.json imports

As an alternative method, we might attempt to configure: clean-publish

retyui avatar Jul 02 '25 14:07 retyui