refactor: decouple discussions data-fetching from trigger into widget prefetch lifecycle#1895
Open
awais-ansari wants to merge 1 commit intoopenedx:masterfrom
Open
refactor: decouple discussions data-fetching from trigger into widget prefetch lifecycle#1895awais-ansari wants to merge 1 commit intoopenedx:masterfrom
awais-ansari wants to merge 1 commit intoopenedx:masterfrom
Conversation
… prefetch lifecycle
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1895 +/- ##
=======================================
Coverage 91.27% 91.27%
=======================================
Files 343 343
Lines 5766 5768 +2
Branches 1387 1384 -3
=======================================
+ Hits 5263 5265 +2
Misses 484 484
Partials 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Decouples the discussions widget's data-fetching side effect from
DiscussionsTriggerinto the widget's
prefetchlifecycle hook, whichSidebarContextProvidercalls on mount.Motivation
Previously,
DiscussionsTriggerowned its ownuseEffectto dispatchgetCourseDiscussionTopics. This had two problems:marked unavailable), topics were never loaded.
discussionsIsAvailablechecked unit-level topic data(
unit?.id && unit?.enabledInContext), causing the DISCUSSIONS widget to toggleavailability on every unit navigation and triggering the priority cascade
(COURSE_OUTLINE fallback → switch back).
Changes
widgets/discussions/widgetConfig.jsprefetchfunction; changeisAvailableto course-level check (baseUrl && hasDiscussionTab)widgets/discussions/DiscussionsTrigger.jsxuseEffect,useDispatch,getConfig,ensureConfig,useMemo— trigger is now a pure render componentsidebar/SidebarContextProvider.jsxuseEffectto callwidget.prefetch()on mount; adduseDispatch; removeunitfromgetAvailableWidgetscontextsidebar/SidebarContextProvider.test.jsxreact-redux,@edx/frontend-platform, andthunkswidgets/discussions/DiscussionsTrigger.test.jsxgetCourseDiscussionTopicsinbeforeEach; fix async assertionssidebar/hooks/useSidebarSync.jsFunction→Objectfor ref paramssidebar/hooks/useResponsiveBehavior.jsFunction→Objectfor ref paramsidebar/README.mdprefetchto widget structure; update context object (removeunit); add prefetch docssidebar/ARCHITECTURE.mdwidgets/discussions/README.mdisAvailablesignature; add prefetch section; document two-tier availabilityBehavioral Change
isAvailablescope: Unit-level → course-level. The DISCUSSIONS trigger staysvisible across the entire course. The trigger/sidebar components still check
topic?.id && topic?.enabledInContextat render time, showing nothing for unitswithout a topic.
prefetchis optional.Testing