(exchange-persisted-fetch) - Make indirect eval call to optimize for minifiers#1744
(exchange-persisted-fetch) - Make indirect eval call to optimize for minifiers#1744kitten merged 2 commits intourql-graphql:mainfrom
Conversation
🦋 Changeset detectedLatest commit: b13b363 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The choice of not providing separate bundles is explicitly based on the currently fractioned ecosystem around That out of the way, I'll do a couple of spot checks next week to see whether this is working as intended ✌️ |
|
@nderscore Can't find any problems with this, so let's ship it 💪 Thanks for taking a look at this! |
|
shipped in |
Summary
The
@urql/exchange-persisted-fetchpackage is not currently being minified to the fullest extent and even throws warnings in some minifiers/bundlers, such as esbuild, because it contains a direct call toeval().Every minifier (including terser, which is being used to generate minified bundles of urql libraries) avoids mangling names when there is a direct
evalcall in scope. Because a direct call to eval gives the code being evaluated access to the scope from which it was called, there's no way for the minifier to know what side-effects that evaluted code has, so it avoids making optimizations.By changing it to an indirect eval, we get smaller outputs, even though more boilerplate was added to the code:
urql-exchange-persisted-fetch.min.jsshrinks from3299bto2802b2792burql-exchange-persisted-fetch.min.mjsshrinks from3281bto2828b2818bThis PR also resolves #875 which I believe was erroneously closed.
Set of changes
eval()call inexchanges/persisted-fetch/src/sha256.tswith an indirect call, guarded against errors with a try/catch.Side-note
This is probably not the ideal fix. I question whether an
evalhere is even appropriate as a means of avoiding includingcryptoin a client-side bundle.It would probably be better to generate separate builds for node and browser environments, where a direct call to
require('crypto')gets tree-shaken out of thebrowserbuild.