[Architecture] Move suggested actions to React context
Changelog Entry
Description
One issue we know for long... "our React context object is too big, one tiny change in the context object means everyone subscribing to it will need to change." This kind of problem plague React context, Redux and is everywhere inside/outside of Web Chat.
For the last few years, when we build features, we are building smaller context object than using the uber one. Now we are looking into how to make our legacy context objects update less frequent.
We will try a few approaches, currently 2 approaches we are trying:
- Atom-sized context object... one context one value, nothing else
- Context will always be stable object... and we use other ways to communicate changes
p.s. we also shop around and thought about Redux reselect approach... and in React sense, it will be HOC + memo(). But preliminary thinking tell us it doesn't sound it will improve perf better than the other 2 approaches.
Design
Specific Changes
- Added new
react-contextpackage-
createBitContextfor quickly creating a context with a single state -
useStableStateHookfor recreating auseState-hook via a stable factory function
-
- Moved
suggestedActionsreducer to React context- Moved
clearSuggestedActionsOnPostActivitysaga to React context
- Moved
- Moved
sendBoxAttachmentsandsendBoxValuereducer to React context- Migrated
useSendBoxAttachmentsanduseSendBoxValuehooks
- Migrated
- Added new
setRawStateand<ReduxActionSinkComposer>to facilitate replication
- [x] I have added tests and executed them locally
- [x] I have updated
CHANGELOG.md - [x] I have updated documentation
Review Checklist
This section is for contributors to review your work.
- [x] ~Accessibility reviewed (tab order, content readability, alt text, color contrast)~
- [x] ~Browser and platform compatibilities reviewed~
- [x] ~CSS styles reviewed (minimal rules, no
z-index)~ - [x] ~Documents reviewed (docs, samples, live demo)~
- [x] ~Internationalization reviewed (strings, unit formatting)~
- [x]
package.jsonandpackage-lock.jsonreviewed - [x] ~Security reviewed (no data URIs, check for nonce leak)~
- [x] Tests reviewed (coverage, legitimacy)