Skip to content
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

Migrate from mobx-react to mobx-react-lite / Removed mobx-utils Dependency #17759

Merged

Conversation

heorhi-deriv
Copy link
Contributor

@heorhi-deriv heorhi-deriv commented Dec 6, 2024

Migrate to mobx-react-lite

This pull request updates our project to use mobx-react-lite instead of mobx-react. The primary motivation for this change is to leverage the lightweight nature of mobx-react-lite, which is optimized for functional components. This change helps in reducing the bundle size and improving performance.


Key Changes

  • Updated import statements to use observer from mobx-react-lite.
  • Ensured all components using observer are functional components, as mobx-react-lite does not support class components.

Benefits

  • Reduced Bundle Size: The lighter library decreases the overall size of the application.
  • Improved Performance: Functional components work more efficiently with mobx-react-lite.
  • Simplified Codebase: Adopting modern React patterns results in cleaner and more maintainable code.

Bundle size after migration

Screenshot 2024-12-06 at 15 13 44

Refactor: Removed mobx-utils Dependency

This pull request removes the dependency on the mobx-utils library by replacing the usage of computedFn with a manual caching solution using MobX's core features.

Key Changes

  • Replaced computedFn with a custom implementation using observable.map from MobX.
  • Added an observable.map (getPositionByIdCache) to act as a reactive cache for the getPositionById method.
  • Cleared the cache (getPositionByIdCache) whenever positions is updated to ensure no stale data is returned.
  • Maintained all functionality of computedFn with behavior parity, including:
    • Memoization: Cached results for specific arguments (id).
    • Reactivity: Automatically recomputed when the underlying positions array changes.

Benefits

  • No External Dependency: Eliminates the need for mobx-utils, reducing the dependency footprint.
  • Maintains Performance: Preserves memoization and reactivity for efficient lookups without unnecessary recomputation.
  • Simplifies Codebase: Relies entirely on core MobX features (observable.map) for reactive caching, ensuring consistency and easier maintenance.

By removing mobx-utils and leveraging MobX's built-in features, we reduce external dependencies while maintaining reactivity and performance.

Screenshot 2024-12-06 at 16 43 40

Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
deriv-app ✅ Ready (Inspect) Visit Preview Dec 30, 2024 6:35am

@coveralls
Copy link

coveralls commented Dec 6, 2024

Pull Request Test Coverage Report for Build 12542715304

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 53.792%

Totals Coverage Status
Change from base Build 12542204007: 0.003%
Covered Lines: 33047
Relevant Lines: 57237

💛 - Coveralls

Copy link
Contributor

github-actions bot commented Dec 6, 2024

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/deriv-com/deriv-app/pull/17759](https://github.com/deriv-com/deriv-app/pull/17759)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-heorhi-deriv-mobx-multiple-instances-fix.binary.sx?qa_server=red.derivws.com&app_id=24061
    - **Original**: https://deriv-app-git-fork-heorhi-deriv-mobx-multiple-instances-fix.binary.sx
- **App ID**: `24061`

Copy link
Contributor

github-actions bot commented Dec 6, 2024

🚨 Lighthouse report for the changes in this PR:

Category Score
🔺 Performance 38
🟧 Accessibility 70
🟢 Best practices 92
🟧 SEO 77
🟧 PWA 78

Lighthouse ran with https://deriv-app-git-fork-heorhi-deriv-mobx-multiple-instances-fix.binary.sx/

@heorhi-deriv heorhi-deriv changed the title fix: 🚑 replace mobx-react with mobx-react-lite Migrate from mobx-react to mobx-react-lite Dec 6, 2024
@heorhi-deriv heorhi-deriv changed the title Migrate from mobx-react to mobx-react-lite Migrate from mobx-react to mobx-react-lite / Removed mobx-utils Dependency Dec 6, 2024
shafin-deriv
shafin-deriv previously approved these changes Dec 10, 2024
farabi-deriv
farabi-deriv previously approved these changes Dec 10, 2024
nijil-deriv
nijil-deriv previously approved these changes Dec 11, 2024
@nijil-deriv nijil-deriv merged commit 114a2e8 into deriv-com:master Dec 30, 2024
15 checks passed
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.

6 participants