Revert "fix(native): load the addon on first use, not at import" - #198
Merged
Conversation
This reverts commit ec830ef. Loading on first use meant `import 'wreq-js'` could no longer throw, and that turned out to be a breaking change rather than a fix. Consumers detect an unavailable native addon by the import throwing, which is the established idiom - ws does exactly this for its own optional native accelerators: try { const bufferUtil = require('bufferutil'); module.exports.mask = /* fast path */ } catch (e) { /* keep the JS fallback */ } Our largest consumer uses the same shape and derives a feature flag from it. Measured against their code, with the addon absent: before this revert: available=true <- wrong, feature looks present after this revert: available=false <- correct, clean 501 restored The two behaviours are mutually exclusive: an import that never throws cannot also signal absence to a caller wrapping it. Every comparable package - rollup, sharp, lightningcss, @swc/core, @tailwindcss/oxide - loads eagerly at module scope for this reason, and none exposes an availability probe. `isNativeAvailable()` goes with it. It can only report something useful when the module survives a failed load; under eager loading it returns true whenever it can be called at all, which invites a fallback branch that never runs. What made a fatal import expensive was never the throw itself, it was having no addon to load. That is addressed by the two changes this keeps: the platform gating that failed installs outright is gone, and Android now has a binding instead of an "Unsupported platform" error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.