Repository navigation
refactor: port the route wrappers to frontend-base as layout routes - #2261
Draft
brian-smith-tcril wants to merge 1 commit into
Draft
brian-smith-tcril wants to merge 1 commit into
brian-smith-tcril wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## bsmith/courseware-data #2261 +/- ##
=======================================================
Coverage 97.15% 97.16%
=======================================================
Files 525 527 +2
Lines 8221 8241 +20
Branches 1910 1917 +7
=======================================================
+ Hits 7987 8007 +20
Misses 222 222
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 18, 2026
DecodePageRoute and PathFixesProvider move to the same paths under frontend-base/src and become layout routes in the route array. PathFixesProvider is the element of a pathless route holding every child of the learning route, since master wraps all of its routes with it. DecodePageRoute is the element of the course/:courseId and preview/course/:courseId routes, which rendered a bare Outlet. Both keep their children prop and take an Outlet from routes.tsx. DecodePageRoute decodes every segment of the pathname and reads no route list. master matches the pathname against DECODE_ROUTES, the list its router is built from, decodes the matched params and rebuilds the path with generatePath. The package's router is built from the route array, so the port has to find the params another way; splitting the pathname on its slashes and decoding each segment with decodeUrl needs no list. Two things differ from master. An escaped character in a fixed segment, such as c%6Furse, is decoded and redirected too, where master leaves the address as typed; the page renders either way. A course URL with a trailing slash is left as it is, where master's rebuilt path dropped the slash. The wrapper keeps PageWrap, now frontend-base's, so every course route sends the page event once per pathname. The dates, progress and outline tabs sent none until now. decodeRoutes.test.tsx keeps its table of thirteen routes and ten spellings of the course key and renders it through the route array, with each page swapped for a probe that prints the pathname; every row lands where master lands it, under /learning. The row with an encoded space lands on the plus-signed key, since PathFixesProvider is in the tree as it is in master's app. index.test.jsx renders the route array too: its case holding an escaped fixed segment in place goes with that behavior, and new cases cover the preview route, four escaped fixed segments, the trailing slash, a route outside the course routes and the page event. PathFixesProvider.test.jsx gains a route outside the course routes. Part of #2195. Co-Authored-By: Claude <[email protected]>
brian-smith-tcril
force-pushed
the
bsmith/courseware-route-wrappers
branch
from
November 18, 2026 19:38
e0cef2b to
aa5cc29
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.
Summary
Learning's two route wrappers now run in its frontend-base package, as layout routes:
PathFixesProvider, which turns spaces in a course URL into plus signs, around every Learning route, andDecodePageRoute, which decodes a percent-encoded course URL, around the course routes. WithDecodePageRoutecomes itsPageWrap, so the dates, progress and outline tabs send the page event again. No user-facing change onmaster: the legacy tree undersrc/is untouched.Part of #1905. Part of #2195. Stacked above #2260; the container with its redirects (#2262) follows.
Note
For reviewers: the ported files are added under
frontend-base/src/as new files, so this diff cannot show what changed frommaster. Theport-diffscript in #2234's description prints that diff, fromfrontend-base/manifest.tsv.generic/path-fixes/index.jsis identical tomaster's, andPathFixesProvider.jsxdiffers in one import line.What changed
routes.tsx.PathFixesProvideris the element of a new pathless route,org.openedx.frontend.route.learning.pathFixes, holding every child of thelearningroute, sincemasterwraps all of its routes with it.DecodePageRouteis the element of thecourse/:courseIdandpreview/course/:courseIdroutes, which rendered a bare<Outlet />. Both keep theirchildrenprop and are given an<Outlet />.DecodePageRoutedecodes every segment of the pathname and reads no route list.mastermatches the pathname againstDECODE_ROUTES, the list its router is also built from, decodes the matched params and rebuilds the path withgeneratePath. The package's router is built from the route array, so the port has to find the params another way either way; splitting the pathname on/and passing each segment throughdecodeUrl, which is unchanged, needs no second list of the course routes.DECODE_ROUTESis not ported. The alternatives weighed and the history of decoding only the params are in Port the courseware container and redirects to frontend-base #2195.PageWrap, now frontend-base's: one event for each pathname of a course route. The three tabs ported so far sent none.tests/render.tsxgainsreplacePages(routes, page), which returns the route array with each page replaced, so a test renders the real layout routes and no page's requests.Known differences from
masterBoth are in how an oddly spelled course URL is tidied in the address bar; the same page renders either way.
/learning/c%6Furse/…is rewritten to/learning/course/…, wheremasterleaves the address as typed.masterredirects to the form without it, a side effect of rebuilding the path from its params.Testing
In
frontend-base/: lint, the tests,buildandbuild:cipass. 46 suites, 792 tests passed and 11 skipped (all skipped in earlier layers). Lint ran with the package's.jsxfiles included (openedx/frontend-base#327).master's tests, rendered through the route array under/learningwith each page swapped for a probe that prints the pathname:decodeRoutes.test.tsx:master's table of thirteen route templates against ten spellings of the course key, and its four other rows. All 134 rows land wheremasterlands them. One row's landing is written differently: an encoded space lands on the plus-signed key, sincePathFixesProvideris in the tree here as it is inmaster's app, wheremaster's test mounts the decode wrapper alone.decode-page-route/index.test.jsx:master's three wrapper cases keep their shape and assert on a spy of the router'snavigatewheremasterasserts on a mockedNavigate. The case "should only decode the url params and not the entire url" goes with the behavior it asserts. ThedecodeUrlcases aremaster's.PathFixesProvider.test.jsx:master's three cases.New cases: a preview URL decoded; an escaped character in each of
learning,course,previewandhome; a trailing slash left as it is; a route outside the course routes fixed for a space, not decoded, and sending no page event; one page event for each pathname of a course route.Coverage. The package is at 100% of lines at this layer, against its 96.15% bar. Counted as codecov counts a patch, against #2260's head, the layer adds 20 lines with none missed and none partly covered.
Manual testing on the package's dev site against tutor dev, with one enrolled learner in the demo course: a course URL with an encoded course key and one with spaces in the key, each pasted into the address bar, settle on the clean address with the page rendered; the course bar's tabs switch pages; the console. The page event is left to the suite, since seeing it by hand needs an analytics key on the site. The record is below, in the section "The route wrappers".
Decisions
What was decided while building this layer; the scope, the alternatives weighed for the decode and its history are in #2195.
Full decision log
Decisions: the route wrappers (#2261)
Decisions made while building this layer of #2195. The scope, the
history of the params-only decode and the alternatives weighed are in
#2195's plan and are not repeated.
The middle layer of three, one commit. The courseware data
module (refactor: port the courseware data module to frontend-base #2260) is below it and the container with its redirects
(refactor: port the courseware container and redirects to frontend-base #2262) above.
Both wrappers keep their
childrenprop.routes.tsxgives eachan
<Outlet />:<PathFixesProvider><Outlet /></PathFixesProvider>and
<DecodePageRoute><Outlet /></DecodePageRoute>. The componentsstay what they are on
master, a wrapper around whatever they aregiven, and
PathFixesProvider.jsxchanges in one import only.PathFixesProvideris a pathless layout route around every childof
learning.masterwraps all of its routes with it, the threeoutside the course routes included. The route has the id
org.openedx.frontend.route.learning.pathFixes, as thecourseandpreviewlayout routes have theirs. It sits inside the providersMainrenders, wheremasterhas it outsideNoticesProvider; afixed path replaces the location under providers that stay mounted,
so nothing is requested twice.
app.test.tsreads the course andpreview routes through the new route.
DecodePageRoutesplits the pathname on/, passes each segmentthrough
decodeUrland rejoins.decodeUrlis unchanged. Thewrapper reads no route list, so
DECODE_ROUTESis not ported.master's landing table lands wheremasterlandsit. The table (thirteen route templates, ten spellings of the
course key, four more rows) runs through the route array under
/learning, 134 cases.Four cases:
l%65arning,c%6Furse,pr%65view,h%6Fme.By reading
master's wrapper, not by running it: it leaves thefirst three as typed, and already decodes the fourth through its
:sequenceIdpattern.master's does:<Navigate to={newUrl}>is given a pathname.PageWrapis frontend-base's, and the page event is back on thecourse routes. One event for each pathname: none for the encoded
address a redirect leaves, none for a change of query string, one
more on moving to another tab. The dates, progress and outline tabs
sent none before this layer. On
masterthe routes outside thecourse routes (
goal-unsubscribe,redirect,preferences-unsubscribe) are wrapped inPageWrapinindex.jsxitself; those pages are stubs here, and their ports (Port the course access redirects to frontend-base #2205, Port the goal unsubscribe page to frontend-base #2206,
Port the preferences unsubscribe page to frontend-base #2207) bring the event with them. A case pins that a route outside
the course routes sends none and is not decoded.
The tests render the route array with each page swapped for a
probe.
replacePages(routes, page)intests/render.tsxreturnsthe array with every page's
element,lazyandloaderreplaced: a route with children is a layout and stays, with the
pages under it replaced; a route without is a page. So a test
renders
Main,PathFixesProviderandDecodePageRoutewhere theapp has them, and no page's requests.
master's landing test buildsthe same thing from
DECODE_ROUTES: the wrapper on each patternaround a probe, and a catch-all probe.
decodeRoutes.test.tsx: the rows aremaster's. The harness adds/learning, as a literal, to each URL and landing. One landingchanges: the
row "mangled url with an encoded space" lands on
course-v1:edX+Demo+Run, wheremaster's test, which mounts thewrapper alone, lands on the key with a space. In
master's appPathFixesProviderturns the%20into+first, as it doeshere.
index.test.jsx:master's wrapper cases mock../constants,matchPathandNavigate, none of which describe the wrapper anymore. Where
masterasserts on its mockedNavigate, the casesassert on a spy of the router's own
navigate, which the realNavigatecalls: not called when nothing needs decoding, calledwith the decoded pathname and
replace: truewhen somethingdoes.
master's three cases keep their shape: each builds itspropswithmatchPathand callsrenderPage(props), whichrenders at
/learningand the props' pathname, so the caseschange in the lines that assert and nowhere else. The new cases
render at a full path through
renderAt. The case "should onlydecode the url params and not the entire url" goes with the
behavior it asserts. The
decodeUrlcases aremaster's.PathFixesProvider.test.jsx:master's three cases under/learning, and a fourth for an encoded space ongoal-unsubscribe.A path the browser re-encodes renders nothing, here and on
master. After aNavigate, bothmaster'sBrowserRouter(itreads
window.location) and the shell's data router(
encodeLocation) hold the pathname as the URL parser writes it,so a decoded character the parser escapes again leaves the pathname
different from its decoded form, and the wrapper returns
Navigateagain with no page. Spaces never reach it, since
PathFixesProviderruns first. A non-ASCII letter does: run once in jsdom under a
browser router, in a case that was not kept, a course key spelled
course-v1:Org+Caf%C3%A9+Runrendered nothing with this layer'swrapper and with
master's. Course keys made in Studio are ASCIIby default: Studio rejects other characters unless
ALLOW_UNICODE_COURSE_IDis set(
course.py),and the setting is
Falseincms/envs/common.py.Not seen in a real browser here, and not introduced here. The
package's suites run under a memory router, which does not
re-encode, so no kept case sees it.
Checks (2026-11-18).
npm run lintclean, with the package's.jsxfiles included (openedx lintdoes not lint.jsxfiles frontend-base#327);npm test, 46suites, 792 passed, 11 skipped (all from earlier layers); 100% of
lines for the package.
npm run buildandnpm run build:cipass.Counted as codecov counts a patch, against refactor: port the courseware data module to frontend-base #2260's head: 20 added
lines, none missed and none partly covered.
Manual testing
Manual testing — the courseware container and redirects (#2195)
One section per layer of the stack. A layer's section asks only for what that layer changes
and a test cannot see, and says what each step needs beyond the page itself.
Drafted 2026-11-18 before the pass. The boxes are Brian's ticks; what was and was not
observed goes under each section's Record.
Setup, for both sections
The same as for the outline tab; nothing new.
cd frontend-base && nvm use && npm ci && npm run dev, served athttp://apps.local.openedx.io:2000/learning/, with tutor dev'smfeservice stopped sothe port is free.
LEARNING_MICROFRONTEND_URLpointing atapps.local.openedx.io:2000/learning, as for Port the dates tab to frontend-base #2189.course-v1:OpenedX+DemoX+DemoCourse.The courseware data module
Nothing to do. No route renders this layer's code until the container layer.
The route wrappers
On
bsmith/courseware-route-wrappers.What needs eyes: a real browser's address bar going through the two redirects and the page
rendering after them, the shell's course bar with the two new layout routes in the tree,
and a real browser's console. The suite runs the wrappers in jsdom.
http://apps.local.openedx.io:2000/learning/course/course-v1%3AOpenedX%2BDemoX%2BDemoCourse/homeinto the address bar. The address becomes
…/learning/course/course-v1:OpenedX+DemoX+DemoCourse/homeand the outline tabrenders.
Why here:
DecodePageRouteis back, as the layout route of the course routes. Itnow decodes every segment of the path.
http://apps.local.openedx.io:2000/learning/course/course-v1:OpenedX DemoX DemoCourse/dates.The address becomes
…/course/course-v1:OpenedX+DemoX+DemoCourse/datesand the datestab renders.
Why here:
PathFixesProvideris back, as a layout route around all of Learning'sroutes.
turn. Each opens with no page load (the Network tab shows no document request), and
the course bar stays in place.
Why here: the route tree gained a pathless route and the two course routes render
a wrapper where they rendered a bare outlet; the shell reads the course from the
matched routes, which no test of Learning's renders.
warnings from Learning's code.
Record
2026-11-18, Brian, on the dev site, on
bsmith/courseware-route-wrappers(e0cef2b8).Network tab was watched for a document request on each tab click (step 3), and
whether the console held warnings that are not Learning's (step 4).
Checked without you
jsdom's browser router, which encodes an address as a browser does, started at an encoded
course key, at a key with spaces, and at
c%6Furse. Each settled on the clean address andrendered the page. Steps 1 and 2 are the same thing in a real browser.
master. In the samethrowaway case, started at
…/course-v1:Org+Caf%C3%A9+Run/home, nothing rendered: thebrowser holds the address encoded, the wrapper decodes it to
é, the two never match, andthe wrapper keeps redirecting.
master's wrapper underBrowserRouterin jsdom did thesame, so this layer does not introduce it. Not seen in a real browser.
Left to the suite
decodeRoutes.test.tsxlearning,course,previeworhomedecode-page-route/index.test.jsx, "should decode an escaped character in the fixed segment"index.test.jsx, "should leave a trailing slash as it is"index.test.jsx, "should decode a preview url"PathFixesProvider.test.jsx,index.test.jsxindex.test.jsx, "should send one page event for each pathname of a course route". Seeing it by hand needs an analytics key on the site.The container and redirects
On
bsmith/courseware-container.What needs eyes: the redirect rules against the real responses (the resume position, the
sequence, the error a unit id draws from the sequence endpoint, the outline), the course bar
on a courseware page, the earlier tabs' links reaching a unit, and a real browser's console.
The suite answers every request itself.
The page is a stub until #2196: it reads "course: not yet ported" and lists
courseId=…,sequenceId=…andunitId=…. "The stub matches" below means those three equal the ids inthe address.
http://apps.local.openedx.io:2000/learning/course/course-v1:OpenedX+DemoX+DemoCourse.The address settles on
…/course/<course>/<sequence>/<unit>and the stub matches.Why here: the container and its redirects replace the stub page on the courseware
routes; this is the resume lookup and the outline for real.
Enter. The address goes back to a unit of that sequence and the stub matches.
unit follows the course key, and press Enter. The address settles on
…/<sequence>/<unit>again and the stub matches.Why here: the sequence endpoint's real answer to a unit id, and the lookup of the
unit's parent, both of which the suite stands in for.
…/learning/course/course-v1:OpenedX+DemoX+DemoCourse/block-v1:OpenedX+DemoX+DemoCourse+type@sequential+block@nothing.The address goes to the course root and on to where step 1 settled.
Why here: the sequence endpoint's real answer to an id it does not know.
/previewafter
/learningand press Enter. The address loses/previewand the stub matches.Why here:
useIsPreviewnow compares against/learning/preview.then go back: each opens with no page load.
Why here: the shell picks the selected tab from the address, and this is the first
Learning page whose address is under none of the tabs' own.
any. Nothing is expected here; what shows is recorded below.
sequence title; on the Progress tab, click a subsection's title. Each lands on a unit
with the stub matching, with no page load.
Why here: those links landed on the stub page of Add frontend-base route tree with stub pages, roles and provides #2188 until now.
Learning's code.
Record
2026-11-18, Brian, on the dev site, on
bsmith/courseware-container(53eaf560).On
masterthe Course tab is selected there: the container renders the tab page withactiveTabSlug="courseware", the Course tab's id from thecourse_metadataresponse iscourseware, andisActiveTabselects the tab whose id equals the slug. The shell'scourse bar does not take a slug from the page: it selects the tab whose URL is the
longest prefix of the address (
findActiveTab), the Course tab's URL ends in/home,and a unit's address is
…/course/<course>/<sequence>/<unit>, under none of the tabs'.So this is the shell's rule and not something this layer's code sets; it is a difference
from
masterthat a learner sees.tab was watched for a document request (steps 6 and 7), which sequence and subsection
were clicked (step 7), and whether the console held warnings that are not Learning's
(step 8).
Checked without you
Left to the suite
CoursewareContainer.test.jsx, "when the URL contains a section ID…" (needs a section's id, which no page shows)firstandlastmarkersCoursewareContainer.test.jsx, "when the sequence has no units", "when the URL contains a unit marker"CoursewareContainer.test.jsx, "when the URL has the /preview prefix" (needs a staff user)CoursewareContainer.test.jsx, "when the learning-sequences outline fails"CoursewareContainer.test.jsx, "when receiving a course_access error_code"CoursewareContainer.test.jsx, "the addresses a redirect passes through"CoursewareContainer.test.jsx, "the position save" (the stub has no navigation to move with)CoursewareContainerHandlers.test.tsx🤖 Generated with Claude Code