diff --git a/AGENTS.md b/AGENTS.md index f93074d868..2afac23f5f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -196,6 +196,8 @@ When adding a customizable component: add it to `DEFAULT_COMPONENTS`, then read `state-store/` holds `useSyncExternalStore`-based stores consumed with `useStateStore(store, selector)` for fine-grained subscriptions outside the context system. Define selectors at module scope so they stay referentially stable — an inline selector re-subscribes on every render. +**Always pass a selector, and make it declare what the caller reads.** `@stream-io/state-store` 1.4.0 lets `useStateStore(store)` run without one and return the whole state. Do not use that form here. A selector picks the fields the component actually reads (`({ selectedPicker }) => ({ selectedPicker })`), so the subscription says what it depends on and re-renders only when those fields change. Pick specific fields even when the hook returns them to callers. When a caller genuinely needs every change, such as a re-render trigger on `editingAuditState` or a hook whose contract is the whole state, write an explicit identity selector at module scope (`const editingAuditStateSelector = (state: EditingAuditState) => state;`) so the choice is visible in code review. + ### Native module abstraction `package/src/native.ts` declares TypeScript interfaces for every platform-specific capability (image picking, compression, haptics, audio/video, clipboard, share). Implementations are injected at runtime via `registerNativeHandlers()`: `stream-chat-expo` supplies Expo implementations, `stream-chat-react-native` supplies bare-RN ones. Calling an unregistered handler throws with a message naming the package to import. @@ -239,7 +241,7 @@ Native pieces live in `package/shared-native/`: the Android-only `PerfText` Fabr 1. **Edit generated or synced files** (see below) — regenerate them instead. 2. **Key on `channel.cid` where you mean the channel instance** — depend on `channel` itself. A disposed channel comes back as a new instance under the same cid, so anything bound to the instance (a context value holding it, a `useStateStore` subscription, a listener, `watch()`) must rebuild when `channel` changes. Use `cid` only when you mean the conversation. 3. **Mutate `channel.state.messages` directly** — go through the `stream-chat` client's state API. -4. **Inline a `useStateStore` selector** — define it at module scope. +4. **Inline a `useStateStore` selector, or omit it** — define it at module scope, and always pass one (see [State stores](#state-stores)). 5. **Use unguarded web-only APIs in shared code** — it runs on Hermes, not a browser. 6. **Bypass lint or type errors** with broad disables or force merges. diff --git a/examples/SampleApp/package.json b/examples/SampleApp/package.json index 649e21bf4e..9086f4e34d 100644 --- a/examples/SampleApp/package.json +++ b/examples/SampleApp/package.json @@ -44,7 +44,7 @@ "@react-navigation/native": "^7.5.0", "@react-navigation/native-stack": "^7.20.0", "@shopify/flash-list": "^2.3.3", - "@stream-io/state-store": "^1.3.1", + "@stream-io/state-store": "^1.4.0", "dayjs": "^1.11.23", "emoji-mart": "^5.6.0", "lodash.mergewith": "^4.6.2", diff --git a/package/package.json b/package/package.json index aafa32c1ba..46b702f40c 100644 --- a/package/package.json +++ b/package/package.json @@ -74,7 +74,7 @@ "@gorhom/bottom-sheet": "^5.2.14", "@legendapp/list": "^3.7.1", "@stream-io/i18n": "^1.1.0", - "@stream-io/state-store": "^1.3.1", + "@stream-io/state-store": "^1.4.0", "@ungap/structured-clone": "^1.3.0", "dayjs": "^1.11.23", "emoji-regex": "^10.4.0", diff --git a/yarn.lock b/yarn.lock index 41431783a4..90c9d31d28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6804,9 +6804,9 @@ __metadata: languageName: node linkType: hard -"@stream-io/state-store@npm:^1.2.0, @stream-io/state-store@npm:^1.3.1": - version: 1.3.1 - resolution: "@stream-io/state-store@npm:1.3.1" +"@stream-io/state-store@npm:^1.2.0, @stream-io/state-store@npm:^1.3.1, @stream-io/state-store@npm:^1.4.0": + version: 1.4.0 + resolution: "@stream-io/state-store@npm:1.4.0" peerDependencies: react: ^17 || ^18 || ^19 use-sync-external-store: ^1.5.0 @@ -6815,7 +6815,7 @@ __metadata: optional: true use-sync-external-store: optional: true - checksum: 10c0/20d58fb89e1bca05ecd4a7d74bcdf01290053d3ddafb4ce4716279bbf68272f393e25ece4e7152adfe031ad582d3e8bce080901b6b66694663212dd8c55cf46f + checksum: 10c0/1ffdda249568297361688f0be77056b6654ee5216ef64b21ce0f0d6e4baccc210506ce815716c7bb46948c623786990e411736056d3c40d2fee7b218002f6ef6 languageName: node linkType: hard @@ -19730,7 +19730,7 @@ __metadata: "@react-navigation/native-stack": "npm:^7.20.0" "@rnx-kit/metro-config": "npm:^2.2.6" "@shopify/flash-list": "npm:^2.3.3" - "@stream-io/state-store": "npm:^1.3.1" + "@stream-io/state-store": "npm:^1.4.0" "@stream-io/typescript-config": "workspace:^" "@types/lodash.mergewith": "npm:^4.6.9" "@types/react": "npm:^19.3.0" @@ -20563,7 +20563,7 @@ __metadata: "@shopify/flash-list": "npm:^2.3.3" "@shopify/react-native-skia": "npm:^2.13.0" "@stream-io/i18n": "npm:^1.1.0" - "@stream-io/state-store": "npm:^1.3.1" + "@stream-io/state-store": "npm:^1.4.0" "@stream-io/typescript-config": "workspace:^" "@testing-library/jest-native": "npm:^5.4.3" "@testing-library/react-native": "npm:13.2.0"