[No QA] Document when Onyx.connectWithoutView is acceptable - #95207
Conversation
|
@thelullabyy Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
This PR adds a new |
|
No need for C+ review |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
|
||
| ### Reading Onyx data (`useOnyx` vs `Onyx.connectWithoutView`) | ||
| Read Onyx data in this order of preference, always choosing the earliest that fits: | ||
| 1. A **pure function** that receives the data as parameters — no Onyx connection. |
There was a problem hiding this comment.
Same as above. I don't understand how Pure Function reads the onyx data. It has to be the useOnyx that does it and then passes it to Pure Function.
| ### - Library files that are not connected or associated to any UI SHOULD use `Onyx.connectWithoutView()` to subscribe to changes in Onyx data | ||
| Library files are located in `/src/lib` but excluding the actions in `/src/lib/actions` which have their own rule below. | ||
|
|
||
| `Onyx.connectWithoutView()` is not the default, even in a library file: first prefer a pure function that receives the data as parameters, and reach for `Onyx.connectWithoutView()` only when the library genuinely needs to react to Onyx changes outside of render. Never add one just because nearby code uses it. See [Reading Onyx data: `useOnyx` vs `Onyx.connectWithoutView`](/contributingGuides/philosophies/ONYX-DATA-MANAGEMENT.md#reading-onyx-data-useonyx-vs-onyxconnectwithoutview) for the full rules. |
There was a problem hiding this comment.
Can we add examples to clarify this?
| Do not add a new `Onyx.connectWithoutView` just because nearby code uses it. Justify each new use on its own against the rule above; when in doubt, use a pure function or `useOnyx`. | ||
|
|
||
| ### - Using `Onyx.connectWithoutView` in a component for performance REQUIRES @frontend-performance approval | ||
| In rare cases a component that subscribes to multiple large collections through `useOnyx` suffers a significant performance regression. Reaching for `Onyx.connectWithoutView` to avoid that is an explicit exception, not a self-serve option: it MUST be approved by the `@frontend-performance` team on Slack, and the PR description MUST link to that discussion. |
Co-authored-by: Tim Golen <tgolen@gmail.com>
Co-authored-by: Tim Golen <tgolen@gmail.com>
|
@tgolen @luacmartins @mountiny this is ready again for review 🙏 |
mountiny
left a comment
There was a problem hiding this comment.
Thanks! I think I will merge this now but @tgolen @luacmartins feel free to leave comments when you are back from Ooo
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.50-0 🚀
|
|
🚀 Deployed to production by https://github.com/arosiclair in version: 9.4.50-3 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Contributors and AI agents have been adding
Onyx.connectWithoutViewby copying existing usage, instead of preferring pure functions /useOnyx. This documents the rules: pure functions take precedence,useOnyxis the default in components, andconnectWithoutViewis only for non-render logic (and existing usage is not a template to copy). The rare performance exception requires@frontend-performancesign-off on Slack. It adds the authoritative section toONYX-DATA-MANAGEMENT.md, reconciles the library-files rule inDATA-BINDING.md, and adds a short agent-facing summary toCLAUDE.md.Fixed Issues
$ #93692
PROPOSAL: N/A (internal task)
Tests
N/A — documentation only.
Offline tests
N/A — documentation only.
QA Steps
N/A — documentation only.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.