@@ -118,18 +118,34 @@ export default function CourseLayout({
118118 const router = useRouter ( ) ;
119119 const [ error , setError ] = useState < any > ( null ) ;
120120 const confirm = useConfirmation ( ) ;
121+ const [ refreshKey , setRefreshKey ] = useState ( 0 ) ;
121122
122123 const pathname = usePathname ( ) ;
123124 const noContentPaths = [ "/quiz" , "/media" , "/quiz" , "/submissions" ] ;
124125 const hideContent = noContentPaths . some ( ( path ) => pathname ?. includes ( path ) ) ;
125126
126127 const data = useLazyLoadQuery < StudentCourseLayoutCourseIdQuery > (
127128 studentCourseIdQuery ,
128- { id : courseId }
129+ { id : courseId } ,
130+ { fetchPolicy : "network-only" , fetchKey : refreshKey }
129131 ) ;
132+
130133 const course = data . coursesByIds ?. [ 0 ] ;
131134 const userId = data . currentUserInfo . id ;
132135
136+ // Force a layout remount to refetch data when navigating back.
137+ // In Next.js, layouts stay mounted between subpages, so their data requests aren't re-run.
138+ // This simple refresh ensures updated data (e.g. course progress).
139+ // The clean solution would be to move data fetching into the subpages,
140+ // so data refetches automatically when those components are mounted.
141+ 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 ) ) {
145+ setRefreshKey ( ( prev ) => prev + 1 ) ;
146+ }
147+ } , [ pathname ] ) ;
148+
133149 const [ leave ] = useMutation < StudentCourseLayoutLeaveMutation > ( graphql `
134150 mutation StudentCourseLayoutLeaveMutation($courseId: UUID!) {
135151 leaveCourse(courseId: $courseId) {
0 commit comments