You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds `inactiveBehavior` option to `@lifecycleBound` to control what
happens to a graph when its host component is hidden inside a React 19
`<Activity>` tree. Also fixes `useObservable` hooks so they re-apply
when the component is unpaused.
- New `inactiveBehavior: 'unmount' | 'retain'` option on
`@lifecycleBound` (default: `'retain'`)
- When `retain`, a sentinel DOM node detects whether the cleanup effect
fired due to an Activity pause vs a real unmount — skipping graph
teardown in the former case
- When `unmount`, the graph is cleared on every unmount as before
- `useObservable` hooks are now re-applied when a component resumes from
an Activity pause (previously observers were not re-registered after
unpause)
- Bump `react`/`react-dom` devDependencies to 19.2.4 (Activity API;
consumer peerDep range `>=16.8.0` unchanged)
- Document the new option in Graphs.mdx
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: guyca <12352397+guyca@users.noreply.github.com>
Copy file name to clipboardExpand all lines: packages/documentation/docs/documentation/usage/Graphs.mdx
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
sidebar_position: 1
3
-
tags: [Graph, Lifecycle-bound]
3
+
tags: [Graph, Lifecycle-bound, Inactive-behavior]
4
4
---
5
5
6
6
importTabsfrom'@theme/Tabs';
@@ -175,6 +175,28 @@ class HomeGraph extends ObjectGraph<HomeScreenProps> {
175
175
#### The lifecycle of a lifecycle-bound graph
176
176
Lifecycle-bound graphs are created when they are requested and are destroyed when the last component or hook that requested them is unmounted. This means that the dependencies provided by a lifecycle-bound graph are shared between components and hooks within the same UI scope and are destroyed when the UI scope is destroyed.
177
177
178
+
#### Inactive behavior
179
+
By default, lifecycle-bound graphs are retained during transient `useEffect` cleanups — such as React Native activity pauses or React StrictMode remounts — and only cleared when the component is actually removed from the tree. This prevents the graph from being destroyed and recreated unnecessarily.
180
+
181
+
Setting `inactiveBehavior` to `'unmount'` reverts to eager cleanup, where the graph is cleared on every `useEffect` cleanup regardless of whether the component has truly unmounted.
182
+
183
+
```ts title="A lifecycle-bound graph with eager cleanup"
|`'retain'` (default) | Graph retained during transient cleanups; cleared only on real unmount |
198
+
|`'unmount'`| Graph cleared on every `useEffect` cleanup |
199
+
178
200
## Graph composition
179
201
Graph composition is a powerful feature that allows you to create complex dependency graphs by combining smaller graphs. Composing graphs is useful when you want to reuse a graph in multiple places. For example, you might have a singleton graph that provides application-level dependencies. You might also have a lifecycle-bound graph that provides dependencies for a specific UI flow. You can compose these graphs together so that the lifecycle-bound graph can also inject the dependencies provided by the singleton graph.
0 commit comments