Skip to content

Revert "fix(native): load the addon on first use, not at import" - #198

Merged
sqdshguy merged 1 commit into
masterfrom
fix/drop-lazy-native-loading
Aug 23, 2026
Merged

Revert "fix(native): load the addon on first use, not at import"#198
sqdshguy merged 1 commit into
masterfrom
fix/drop-lazy-native-loading

Conversation

@sqdshguy

Copy link
Copy Markdown
Owner

No description provided.

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.
@sqdshguy
sqdshguy merged commit 49ad8c2 into master Aug 23, 2026
9 checks passed
@sqdshguy
sqdshguy deleted the fix/drop-lazy-native-loading branch August 23, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant