Skip to content

fix: stop the course outline scrolling back while you work in it [backport to verawood] - #3214

Open
ihor-romaniuk wants to merge 1 commit into
openedx:release/verawoodfrom
raccoongang:ihor-romaniuk/outline-scroll-jump-verawood
Open

fix: stop the course outline scrolling back while you work in it [backport to verawood]#3214
ihor-romaniuk wants to merge 1 commit into
openedx:release/verawoodfrom
raccoongang:ihor-romaniuk/outline-scroll-jump-verawood

Conversation

@ihor-romaniuk

@ihor-romaniuk ihor-romaniuk commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #3213 to release/verawood.

Open a course outline through a link that points at one of its blocks — the kind Studio search and "view in outline" produce, with ?show=<block> in the address — and the page starts snapping back to that block. Opening the menu on any section is enough to be thrown back to it, which makes the outline hard to work in at all. The block stays highlighted for as long as the link is in the address bar, and the outline reads that as "scroll to it" every time it re-renders.

The outline now scrolls to the highlighted block when you arrive and then leaves the page alone.

Implementation notes
  • createGlobalState in src/data/apiHooks.ts returned setData and resetData as plain functions declared in the hook body, so both got a new identity on every render.
  • SectionCard, SubsectionCard and UnitCard list resetScrollState among the dependencies of the effect that calls scrollToElement, so that effect ran on every render. While ?show= names the card, its guard isScrolledToElement stays true, so every render scrolled. The effect also calls resetScrollState(), which invalidates the query and causes another render — hence repeated jumps rather than one.
  • The fix is in the hook rather than in the three cards: a hook whose callbacks are read as dependencies has to keep their identity, the way useQuery's refetch does. queryKey is memoised on queryKeyArgs so the callbacks can depend on it honestly, without a ref.
  • Fixing the three dependency arrays instead would also work, but it leaves the same trap in place for every other caller of createGlobalState.

Screenshot/Video

Before

before.mov

After

after.mov

Testing

Preconditions: a course with several sections, a staff user.

  1. Open the course outline with a block in the address, for example <AUTHORING>/course/<courseId>?show=<sectionId>.
  2. Expected: the page scrolls to that section and highlights it — unchanged.
  3. Scroll away from the highlighted section.
  4. Open the menu on any other section.
  5. Expected: the menu opens and the page stays where you left it. Before this change it scrolled back to the highlighted section.
  6. Rename a section, then open and close a few menus.
  7. Expected: the page stays put throughout.
  8. Open the outline without ?show= and repeat.
  9. Expected: unchanged.

Verified locally

Check Result
Outline with ?show=<section>, scrolled to 6000px, section menu opened page stays at 6000px; before the fix it scrolled to 3654px, a jump of 2346px
Arrival behaviour still scrolls to the block and highlights it — one highlighted card, page settles at its top
Section menu opens as before: aria-expanded flips and the dropdown renders
jest src/course-outline 32 suites, 357 tests
jest src/data/apiHooks.test.tsx 5 tests, including two new ones for the hook
Red/green restoring the plain functions fails the new identity test
tsc, dprint, oxlint clean
Not verified One browser at 1440×863. The three card effects were left as they are, so the fix rests on the hook keeping its callbacks stable.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Aug 27, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @ihor-romaniuk!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Aug 27, 2026
@ihor-romaniuk
ihor-romaniuk force-pushed the ihor-romaniuk/outline-scroll-jump-verawood branch from 61f7e03 to 7ac1868 Compare August 27, 2026 10:04
Opening a course outline through a link that points at one of its blocks left
the page snapping back to that block on almost every interaction — opening a
section menu was enough. The block stays highlighted for as long as the link is
in the address bar, and the outline reads that as "scroll to it" again each time
it re-renders.

The global-state hook handed out a new pair of callbacks on every render, and
the cards that scroll to the highlighted block list one of those callbacks among
the dependencies of the effect that scrolls. The callbacks now keep their
identity, so the effect runs when the highlighted block changes rather than on
every render. Scrolling to the block on arrival is unchanged.
@ihor-romaniuk
ihor-romaniuk force-pushed the ihor-romaniuk/outline-scroll-jump-verawood branch from 7ac1868 to 70d7567 Compare August 27, 2026 10:06
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/verawood@99ca9c9). Learn more about missing BASE report.

Additional details and impacted files
@@                 Coverage Diff                 @@
##             release/verawood    #3214   +/-   ##
===================================================
  Coverage                    ?   95.60%           
===================================================
  Files                       ?     1392           
  Lines                       ?    33141           
  Branches                    ?     7473           
===================================================
  Hits                        ?    31685           
  Misses                      ?     1403           
  Partials                    ?       53           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ihor-romaniuk ihor-romaniuk added the backport PR backports a change from main to a named release. label Aug 27, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Aug 27, 2026
@arbrandes
arbrandes removed their request for review August 28, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport PR backports a change from main to a named release. core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

5 participants