@@ -14,7 +14,7 @@ import ExitToAppIcon from "@mui/icons-material/ExitToApp";
1414import { Box , Button , Typography } from "@mui/material" ;
1515import { useParams , usePathname , useRouter } from "next/navigation" ;
1616import * as React from "react" ;
17- import { useEffect , useState } from "react" ;
17+ import { useEffect , useRef , useState } from "react" ;
1818import { graphql , useLazyLoadQuery , useMutation } from "react-relay" ;
1919
2020const studentCourseIdQuery = graphql `
@@ -138,12 +138,25 @@ export default function CourseLayout({
138138 // This simple refresh ensures updated data (e.g. course progress).
139139 // The clean solution would be to move data fetching into the subpages,
140140 // so data refetches automatically when those components are mounted.
141+ const prevPathname = useRef ( pathname ) ;
142+
141143 useEffect ( ( ) => {
142- const chaptersPageRegex = / ^ \/ c o u r s e s \/ [ ^ \/ ] + ( \/ c h a p t e r s ) ? $ / ;
143- const coursePageRegex = / ^ \/ c o u r s e s \/ [ ^ \/ ] + $ / ;
144- if ( coursePageRegex . test ( pathname ) || chaptersPageRegex . test ( pathname ) ) {
144+ const subPages = [
145+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ f o r u m $ / ,
146+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ p r o g r e s s $ / ,
147+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ q u e s t s $ / ,
148+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ l e a d e r b o a r d $ / ,
149+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ c h a p t e r s $ / ,
150+ / ^ \/ c o u r s e s \/ [ ^ \/ ] + $ / ,
151+ ] ;
152+
153+ const wasSubPage = subPages . some ( ( regex ) => regex . test ( prevPathname . current ) ) ;
154+
155+ if ( ( ! wasSubPage && ( pathname . match ( / ^ \/ c o u r s e s \/ [ ^ \/ ] + $ / ) ) || ( ! wasSubPage && ( pathname . match ( / ^ \/ c o u r s e s \/ [ ^ \/ ] + \/ c h a p t e r s $ / ) ) ) ) ) {
145156 setRefreshKey ( ( prev ) => prev + 1 ) ;
146157 }
158+
159+ prevPathname . current = pathname ;
147160 } , [ pathname ] ) ;
148161
149162 const [ leave ] = useMutation < StudentCourseLayoutLeaveMutation > ( graphql `
0 commit comments