Stub out react-native-svg fetchData on web to drop buffer polyfill#11097
Stub out react-native-svg fetchData on web to drop buffer polyfill#11097mozzius wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Claude finished @mozzius's task in 1m 33s —— View job PR ReviewI read the repo This PR looks good. The approach is sound and the reasoning in the description holds up. No blocking findings. What I checked:
One non-blocking note (not a defect): the alias key hard-codes the internal path |
|
|
Claude finished @mozzius's task in 1m 34s —— View job PR Review
This is a web-only build-config change ( What I checked:
One non-blocking note (unchanged from the prior review, not a defect): the alias key hard-codes Note: |
Why
The
bufferpolyfill (~55KB stat size, plusbase64-js+ieee754) was landing in the initial web bundle. The only importer isreact-native-svg'sutils/fetchData.js, which usesBuffer.from(x, 'base64')to decode base64 data URIs forSvgUri/SvgXmlremote loading – a feature we don't use anywhere. The package has nosideEffectsfield, so webpack can't tree-shake it out of the barrel export. (It also doesn't declarebufferas a dependency – it only resolves via hoisting from unrelated packages.)How
react-native-svg/lib/module/utils/fetchDatatofalseinwebpack.config.js. The key must be an absolute path because the package imports it via a relative path internally. Webpack replaces the module with an empty stub, sofetchTextbecomesundefined– ifSvgUri/SvgXmlremote loading ever sneaks in, it throws immediately rather than silently bloating the bundle.webpack.config.jsincache.buildDependencies.config. Expo only registers its own internal config, so edits to ours (like this alias) didn't invalidate the persistent filesystem cache and the alias was silently ignored on cached rebuilds.webpack.config.jsto the ESLint ignore list (Node.js config file, was never linted before the flat-config migration and failsno-nodejs-modules+ type-checked rules).Verification
Built with
EXPO_PUBLIC_GENERATE_STATS=1and confirmed viastats.json:buffer,base64-js, andieee754are gone;fetchDatashows as a 15-byte(ignored)module. Also grepped the emitted chunks for the polyfill's signature strings – no matches.🤖 Generated with Claude Code