feat(resource-fetcher): add /auto side-effect entry points#1092
Open
msluszniak wants to merge 3 commits intomainfrom
Open
feat(resource-fetcher): add /auto side-effect entry points#1092msluszniak wants to merge 3 commits intomainfrom
msluszniak wants to merge 3 commits intomainfrom
Conversation
Adds opt-in side-effect imports for both adapter packages that call
`initExecutorch({ resourceFetcher: ... })` for the user:
import 'react-native-executorch-expo-resource-fetcher/auto';
// or
import 'react-native-executorch-bare-resource-fetcher/auto';
Use it once at app entry instead of the boilerplate manual
`initExecutorch({ resourceFetcher: ExpoResourceFetcher })` call. The
manual API stays — use it when you need to register a different
adapter, swap adapters at runtime, or order the registration relative
to other side effects.
Strictly additive: existing consumers' `initExecutorch(...)` calls keep
working unchanged. The auto entries live in the adapter packages
(rather than in `react-native-executorch` itself) so the main package
doesn't need a hard dependency on either adapter implementation.
Refs #1086 (item 5).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Migrate the five demo apps (computer-vision, llm, text-embeddings,
speech, bare-rn) to the new `/auto` side-effect import added in the
previous commit. Each app drops its `initExecutorch({ resourceFetcher: ... })`
boilerplate and the corresponding `initExecutorch` / fetcher imports
in favor of:
import 'react-native-executorch-expo-resource-fetcher/auto';
// or, for bare-rn:
import 'react-native-executorch-bare-resource-fetcher/auto';
Update the user-facing docs (`01-getting-started.md`,
`02-loading-models.md`) to lead with the `/auto` pattern and present
`initExecutorch(...)` as the "more control" alternative for custom
adapters or runtime swapping. Custom-adapter and API-reference docs
are unchanged — both legitimately use the manual API.
Also fixes a pre-existing wrong import path in `02-loading-models.md`:
the bare adapter was shown as `@react-native-executorch/bare-adapter`,
which does not exist; corrected to `react-native-executorch-bare-resource-fetcher`.
Refs #1086 (item 5).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The "ResourceFetcher adapter is not initialized" error currently only
mentions the manual `initExecutorch({ resourceFetcher: ... })` path.
With the new `/auto` side-effect entry, there's a one-line fix that
the error should surface first. Update the message to lead with the
auto entry and keep `initExecutorch(...)` as the "for full control"
fallback.
Refs #1086 (item 5).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
|
Does this actually solve the problem? You still have to read the docs and do a manual thing, which is importing a specific module, we're just being less explicit about it |
Member
Author
|
Maybe we should handle this as it is done in |
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.
Description
Forgetting
initExecutorch({ resourceFetcher: ExpoResourceFetcher })(or itsBareResourceFetchercounterpart) before the first model call is a runtime footgun every Expo / bare consumer has to remember. The error message we throw is good — it directs users to the right packages — but the boilerplate itself shouldn't be needed.This PR adds an opt-in side-effect entry point in each adapter package:
The new entries live in the adapter packages (rather than in
react-native-executorchitself) so the main package doesn't need a hard dependency on either adapter implementation — bare-RN consumers don't get Expo bloat and vice versa.Introduces a breaking change?
Strictly additive. The manual
initExecutorch({ resourceFetcher: ... })API stays exactly as is — same module export, same signature. Existing consumers are unaffected. Use the manual API when you need to register a different adapter, swap adapters at runtime, or order the registration relative to other side effects; use the new/autoentry when you have nothing custom to configure.Type of change
Tested on
Pure JS plumbing — no native code touched. Verified locally that:
yarn workspace ... run prepareproduceslib/auto.{js,d.ts}artifacts in both adapter packages.yarn typecheckpasses across all workspaces.eslintandprettier --checkpass on the new files.Testing instructions
In any RNE consumer:
initExecutorch({ resourceFetcher: ExpoResourceFetcher })call with a single side-effect import at app entry:import 'react-native-executorch-expo-resource-fetcher/auto';.ResourceFetcher adapter is not initializederror should not surface (which it would have if you'd just deleted theinitExecutorchcall without the new import).initExecutorch(...)flow still works by running an app that uses it — output should be identical.Related issues
Addresses item 5 of #1086.
Checklist
Additional notes
/autoentry as the default for new projects./autofor brevity (consistent with theexpo-router/entryreference pointed at in the issue). Open to alternatives like/registeror/initif you prefer.