Skip to content

Commit

Permalink
Pass ssr: false to useMediaQuery
Browse files Browse the repository at this point in the history
Otherwise we needlessly render assuming false which causes rerenders
with visual change at start-up and on language change.

Not Vite related, we need to rescue this if we abandon the PR.
  • Loading branch information
microbit-matt-hillsdon committed Mar 14, 2024
1 parent f1cc2e4 commit d4313dd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/documentation/common/DocumentationTopLevelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const DocumentationTopLevelItem = ({
type,
}: DocumentationTopLevelItemProps) => {
const intl = useIntl();
const [isShortWindow] = useMediaQuery(heightMd);
const [isWideScreen] = useMediaQuery(widthXl);
const [isShortWindow] = useMediaQuery(heightMd, { ssr: false });
const [isWideScreen] = useMediaQuery(widthXl, { ssr: false });
return (
<DocumentationListItem
onClick={onForward}
Expand Down Expand Up @@ -92,8 +92,8 @@ const DocumentationListItem = ({
type,
...props
}: DocumentationListItemProps) => {
const [isShortWindow] = useMediaQuery(heightMd);
const [isWideScreen] = useMediaQuery(widthXl);
const [isShortWindow] = useMediaQuery(heightMd, { ssr: false });
const [isWideScreen] = useMediaQuery(widthXl, { ssr: false });
const my =
type === "reference"
? isShortWindow || !isWideScreen
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const EditorArea = React.forwardRef(
simulatorButtonRef: ForwardedRef<HTMLButtonElement>
) => {
const intl = useIntl();
const [isWideScreen] = useMediaQuery(widthXl);
const [isWideScreen] = useMediaQuery(widthXl, { ssr: false });
return (
<Flex
height="100%"
Expand Down
2 changes: 1 addition & 1 deletion src/project/ProjectActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ProjectActionBar = React.forwardRef(
{ sendButtonRef, ...props }: ProjectActionBarProps,
ref: ForwardedRef<HTMLButtonElement>
) => {
const [isWideScreen] = useMediaQuery(widthXl);
const [isWideScreen] = useMediaQuery(widthXl, { ssr: false });
const size = "lg";
return (
<HStack
Expand Down
4 changes: 3 additions & 1 deletion src/workbench/Workbench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const Workbench = () => {
handleSidebarCollapse();
}
}, [handleSidebarCollapse]);
const [hideSideBarMediaQueryValue] = useMediaQuery(hideSidebarMediaQuery);
const [hideSideBarMediaQueryValue] = useMediaQuery(hideSidebarMediaQuery, {
ssr: false,
});
useEffect(() => {
if (hideSideBarMediaQueryValue) {
handleSidebarCollapse();
Expand Down
2 changes: 1 addition & 1 deletion src/workbench/connect-dialogs/ConnectHelpDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import selectMicrobit from "./select-microbit.png";

const ConnectHelpDialogBody = () => {
const intl = useIntl();
const [isDesktop] = useMediaQuery("(min-width: 768px)");
const [isDesktop] = useMediaQuery("(min-width: 768px)", { ssr: false });
return (
<VStack
width="auto"
Expand Down

0 comments on commit d4313dd

Please sign in to comment.