refactor: migrate to React Query and enhance content script architecture#102
Merged
Conversation
saisanthoshpentakota
requested review from
amey-contentstack,
anupsingh244,
asthamishra-cs,
ishaanB3006,
kaustubhjadhav-cs,
markhayden,
onkarj-47,
prosdev,
vedant-contentstack and
vishy1618
as code owners
October 27, 2025 06:04
onkarj-47
approved these changes
Oct 28, 2025
saisanthoshpentakota
force-pushed
the
issue/53
branch
from
October 28, 2025 08:48
d47523e to
92cbbae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR modernizes the extension’s data fetching architecture, modularizes the content script, and adds comprehensive test coverage across critical components for improved maintainability, performance, and reliability.
Changes Overview
1. React Query Integration for Data Fetching
Replaced manual storage polling with React Query for reactive state management in
SidePanel.Added custom hooks for data fetching:
useTagConfig: Queries tag configuration from the background script via the message broker.useCurrentTab: Manages current active tab information.Enhanced message broker with query support for background-to-UI communication.
Simplified
SidePanelcomponent by removing manual polling logic (~71 lines reduced).2. Content Script Modularization
Extracted the monolithic content script into focused, maintainable modules:
autoDetection.ts: Handles automatic domain detection logic.eventHandler.ts: Manages event handling and delegation.messageHandler.ts: Centralizes message broker communication.scriptInjection.ts: Isolates script injection functionality.Reduced complexity in
app.tsxby 87% (from 331 lines → 43 lines of actual logic).Improved separation of concerns for better testability and maintainability.
3. Comprehensive Test Coverage
Added 1,200+ lines of test coverage across:
Content script modules:
autoDetection.test.tseventHandler.test.tsmessageHandler.test.tsscriptInjection.test.tsMessage broker:
broker.test.ts(enhanced with 300+ lines of additional tests)SidePanel component:
SidePanel.test.tsx(138 lines)Enhanced test utilities in
vitest.setup.tsfor better Chrome API mocking.Validates data fetching patterns, module interactions, and component behavior.
⚙️ Technical Details
Dependencies Added
Files Changed
13 files modified in the most recent commit:
Net Result:
Benefits
✅ Better Performance: React Query handles caching, deduplication, and background updates automatically.
✅ Improved Maintainability: Modular content scripts are easier to test and modify.
✅ Enhanced Reliability: Comprehensive test coverage ensures stable functionality.
✅ Better Developer Experience: Cleaner code structure and reactive data fetching patterns.
✅ v2 Migration Compliance: Follows modern React patterns per project standards.
Testing
🧭 Migration Notes
Summary:
This PR modernizes core architecture with React Query, modular content scripts, and robust testing, paving the way for more maintainable and scalable extension development.
Related issues: #59