@@ -17,37 +17,31 @@ const config = {};
1717
1818module .exports = withThreadedRuntime (
1919 mergeConfig (getDefaultConfig (__dirname ), config),
20- {
21- roots: [' App.tsx' , ' src' ],
22- generatedDir: ' .threaded-runtime' ,
23- generatedEntry: ' entry.js' ,
24- },
2520);
2621```
2722
2823## Options
2924
3025| Option | Default | What it controls |
3126| --- | --- | --- |
32- | ` roots ` | ` ['App.tsx', 'src'] ` | Files and folders Metro scans for ` OnRuntime ` , ` threadedComponent ` , ` runtimeFunction ` , and directive functions. |
33- | ` generatedDir ` | ` .threaded-runtime ` | Where the generated entry and the registration tables are written. Add this folder to ` .gitignore ` . |
27+ | ` roots ` | ` ['App.tsx', 'src'] ` | Files and folders scanned for ` OnRuntime ` , ` threadedComponent ` , ` runtimeFunction ` , and directive functions. |
28+ | ` generatedDir ` | ` .threaded-runtime ` | Where the generated entry is written. Add this folder to ` .gitignore ` . |
3429| ` generatedEntry ` | ` entry.js ` | Filename of the generated entry inside ` generatedDir ` . |
30+ | ` projectRoot ` | Metro's ` projectRoot ` | Base directory for scanning and for generated ids. |
3531
3632## Loading the generated entry
3733
3834The generated entry registers component loaders, runtime functions, and the
39- ` ThreadedRuntimeHost ` root. It must be loaded ** only inside secondary
40- runtimes ** , never on the main runtime:
35+ ` ThreadedRuntimeHost ` root. Require it at the top of ` index.js ` so it runs in
36+ ** every ** runtime:
4137
4238``` js title="index.js"
43- if (global .__THREADED_RUNTIME_ENV__ || global ._is_it_a_list_env === true ) {
44- require (' ./.threaded-runtime/entry' );
45- }
39+ require (' ./.threaded-runtime/entry' );
4640```
4741
48- The two globals exist for backwards compatibility — both indicate the bundle
49- is being evaluated in a secondary runtime. New code should rely on
50- ` __THREADED_RUNTIME_ENV__ ` .
42+ Component registrations are lazy ( ` () => require(...) ` ), so this adds nothing
43+ to main-runtime startup. Loading it on main is required for the JSI function
44+ dispatch mechanism, which enables calling functions on secondary runtimes .
5145
5246## .gitignore
5347
@@ -66,12 +60,12 @@ root-level file with the runtime's name:
6660index.background.ts
6761```
6862
69- The Metro plugin discovers files matching ` index.<runtime>.ts(x) ` in the
70- project root and emits a static conditional require. When native starts a
71- runtime named ` background ` , the generated entry loads ` index.background.ts `
72- inside that runtime only .
63+ The Metro plugin discovers files matching ` index.<runtime>.ts ` in the project
64+ root and emits a static conditional require. The generated entry loads
65+ ` index. background.ts ` only inside runtimes whose ** name or kind ** is
66+ ` background ` .
7367
74- ``` tsx title="index.background.ts"
68+ ``` ts title="index.background.ts"
7569import { registerThreadedHeadlessTask } from ' @react-native-runtimes/core' ;
7670import { business } from ' ./src/businessStore' ;
7771
@@ -80,6 +74,7 @@ registerThreadedHeadlessTask<{ reason: string }>(
8074 async ({ payload }) => {
8175 await business .hydrate ();
8276 await business .update (state => ({
77+ ... state ,
8378 lastRefreshReason: payload .reason ,
8479 refreshCount: state .refreshCount + 1 ,
8580 }));
@@ -108,11 +103,6 @@ index.sync-engine.ts
108103
109104## Troubleshooting
110105
111- <Callout type = " warn" title = " Metro picks up the generated entry on the main runtime" >
112- Double-check the ` if (global.__THREADED_RUNTIME_ENV__ ...) ` guard in your
113- ` index.js ` . The generated entry is large and should never load on main.
114- </Callout >
115-
116106<Callout type = " warn" title = " A threaded component isn't being registered" >
117107 Add its file to ` roots ` or place it under one of the existing roots. Files
118108 outside the configured roots are invisible to the plugin.
0 commit comments