Skip to content

[Architecture] Move suggested actions to React context #5490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

compulim
Copy link
Contributor

@compulim compulim commented May 30, 2025

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-context package
    • createBitContext for quickly creating a context with a single state
    • useStableStateHook for recreating a useState-hook via a stable factory function
  • Moved suggestedActions reducer to React context
    • Moved clearSuggestedActionsOnPostActivity saga to React context
  • Moved sendBoxAttachments and sendBoxValue reducer to React context
    • Migrated useSendBoxAttachments and useSendBoxValue hooks
  • Added new setRawState and <ReduxActionSinkComposer> to facilitate replication
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@compulim compulim force-pushed the feat-state-context branch from afc7def to f01d1cc Compare May 30, 2025 22:20
@compulim compulim changed the title [WIP] [Perf] One state one context [Perf] Move suggested actions to React context Jun 3, 2025
@compulim compulim changed the title [Perf] Move suggested actions to React context [Architecture] Move suggested actions to React context Jun 3, 2025
@compulim compulim marked this pull request as ready for review June 3, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants