Skip to content

Commit 39d89be

Browse files
fix: discussion sidebar loads very slow (openedx#1081)
1 parent a601e43 commit 39d89be

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

src/courseware/course/Course.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ describe('Course', () => {
117117
render(<Course {...mockData} />);
118118
expect(sessionStorage.getItem(`notificationTrayStatus.${mockData.courseId}`)).toBe('"open"');
119119
const notificationShowButton = await screen.findByRole('button', { name: /Show notification tray/i });
120-
expect(screen.queryByRole('region', { name: /notification tray/i })).toBeInTheDocument();
120+
expect(screen.queryByRole('region', { name: /notification tray/i })).not.toHaveClass('d-none');
121121
fireEvent.click(notificationShowButton);
122122
expect(sessionStorage.getItem(`notificationTrayStatus.${mockData.courseId}`)).toBe('"closed"');
123-
expect(screen.queryByRole('region', { name: /notification tray/i })).not.toBeInTheDocument();
123+
expect(screen.queryByRole('region', { name: /notification tray/i })).toHaveClass('d-none');
124124
});
125125

126126
it('handles reload persisting notification tray status', async () => {

src/courseware/course/sequence/Sequence.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ describe('Sequence', () => {
7474
);
7575

7676
await waitFor(() => expect(screen.queryByText('Loading locked content messaging...')).toBeInTheDocument());
77-
// `Previous`, `Active`, `Next` and `Prerequisite` buttons.
78-
expect(screen.getAllByRole('button').length).toEqual(4);
77+
// `Previous`, `Active`, `Next`, `Prerequisite` and `Close Tray` buttons.
78+
expect(screen.getAllByRole('button').length).toEqual(5);
7979

8080
expect(screen.getByText('Content Locked')).toBeInTheDocument();
8181
const unitContainer = container.querySelector('.unit-container');
@@ -126,7 +126,7 @@ describe('Sequence', () => {
126126
render(<Sequence {...mockData} />);
127127
expect(await screen.findByText('Loading learning sequence...')).toBeInTheDocument();
128128
// Renders navigation buttons plus one button for each unit.
129-
expect(screen.getAllByRole('button')).toHaveLength(3 + unitBlocks.length);
129+
expect(screen.getAllByRole('button')).toHaveLength(4 + unitBlocks.length);
130130

131131
loadUnit();
132132
await waitFor(() => expect(screen.queryByText('Loading learning sequence...')).not.toBeInTheDocument());
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import React, { useContext } from 'react';
2-
import SidebarContext from './SidebarContext';
3-
import { SIDEBARS } from './sidebars';
1+
import React from 'react';
2+
import { SIDEBAR_ORDER, SIDEBARS } from './sidebars';
43

5-
const Sidebar = () => {
6-
const {
7-
currentSidebar,
8-
} = useContext(SidebarContext);
9-
if (!currentSidebar) {
10-
return null;
11-
}
12-
const CurrentSidebar = SIDEBARS[currentSidebar].Sidebar;
13-
return (
14-
<CurrentSidebar />
15-
);
16-
};
4+
const Sidebar = () => (
5+
<>
6+
{
7+
SIDEBAR_ORDER.map((sideBarId) => {
8+
const SidebarToRender = SIDEBARS[sideBarId].Sidebar;
9+
return <SidebarToRender />;
10+
})
11+
}
12+
</>
13+
);
1714

1815
export default Sidebar;

src/courseware/course/sidebar/common/SidebarBase.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ const SidebarBase = ({
3434

3535
useEventListener('message', receiveMessage);
3636

37-
return currentSidebar === sidebarId && (
37+
return (
3838
<section
3939
className={classNames('ml-0 ml-lg-4 border border-light-400 rounded-sm h-auto align-top', {
4040
'bg-white m-0 border-0 fixed-top vh-100 rounded-0': shouldDisplayFullScreen,
4141
'min-vh-100': !shouldDisplayFullScreen,
42+
'd-none': currentSidebar !== sidebarId,
4243
}, className)}
4344
style={{ width: shouldDisplayFullScreen ? '100%' : width }}
4445
aria-label={ariaLabel}

src/courseware/course/sidebar/sidebars/discussions/DiscussionsSidebar.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const DiscussionsSidebar = ({ intl }) => {
3535
className="d-flex w-100 h-100 border-0"
3636
title={intl.formatMessage(messages.discussionsTitle)}
3737
allow="clipboard-write"
38+
loading="lazy"
3839
/>
3940
</SidebarBase>
4041
);

0 commit comments

Comments
 (0)