Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(whiteboard): Remove Conditionally Called Hooks Error #19915

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const Whiteboard = React.memo(function Whiteboard(props) {

clearTldrawCache();

if (!currentPresentationPage) return null;

const [tlEditor, setTlEditor] = React.useState(null);
const [isMounting, setIsMounting] = React.useState(true);
const [initialViewBoxWidth, setInitialViewBoxWidth] = React.useState(null);
Expand Down Expand Up @@ -352,6 +350,7 @@ const Whiteboard = React.memo(function Whiteboard(props) {
const currPageNum = parseInt(curPageIdRef.current);
const shapeSelected = tlEditorRef.current.selectedShapes.length > 0;
const changeSlide = (direction) => {
if (!currentPresentationPage) return;
let newSlideNum = currPageNum + direction;
const outOfBounds = direction > 0
? newSlideNum > currentPresentationPage?.totalPages
Expand Down Expand Up @@ -585,24 +584,24 @@ const Whiteboard = React.memo(function Whiteboard(props) {
}, [fitToWidth, isPresenter]);

React.useEffect(() => {
if (currentPresentationPage.scaledViewBoxWidth && !initialViewBoxWidth) {
setInitialViewBoxWidth(currentPresentationPage.scaledViewBoxWidth);
if (currentPresentationPage && currentPresentationPage?.scaledViewBoxWidth && !initialViewBoxWidth) {
setInitialViewBoxWidth(currentPresentationPage?.scaledViewBoxWidth);
}

if (!isPresenter && tlEditorRef.current && initialViewBoxWidth) {
if (!isPresenter && tlEditorRef.current && initialViewBoxWidth && currentPresentationPage) {
const viewerFitToWidth = determineViewerFitToWidth(
currentPresentationPage
);

// Calculate the effective zoom based on the change in viewBoxWidth
const effectiveZoom = calculateEffectiveZoom(
initialViewBoxWidth,
currentPresentationPage.scaledViewBoxWidth
currentPresentationPage?.scaledViewBoxWidth
);

const zoomFitSlide = calculateZoomValue(
currentPresentationPage.scaledWidth,
currentPresentationPage.scaledHeight,
currentPresentationPage?.scaledWidth,
currentPresentationPage?.scaledHeight,
true
);
const zoomCamera = (zoomFitSlide * effectiveZoom) / HUNDRED_PERCENT;
Expand Down Expand Up @@ -876,13 +875,13 @@ const Whiteboard = React.memo(function Whiteboard(props) {

const panned = prevCam.x !== nextCam.x || prevCam.y !== nextCam.y;

if (panned && isPresenter) {
if (panned && isPresenter && currentPresentationPage) {
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
editor?.viewportPageBounds.width,
editor?.viewportPageBounds?.width,
currentPresentationPage?.scaledWidth
);
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
editor?.viewportPageBounds.height,
editor?.viewportPageBounds?.height,
currentPresentationPage?.scaledHeight
);

Expand Down Expand Up @@ -979,7 +978,7 @@ const Whiteboard = React.memo(function Whiteboard(props) {
next?.id?.includes("camera") &&
(prev.x !== next.x || prev.y !== next.y);
const zoomed = next?.id?.includes("camera") && prev.z !== next.z;
if (panned) {
if (panned && currentPresentationPage) {
// // limit bounds
if (
editor?.viewportPageBounds?.maxX >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ const WhiteboardContainer = (props) => {
typeName: 'shape',
});

if (!currentPresentationPage) return;

return (
<Whiteboard
{...{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const useMouseEvents = ({ whiteboardRef, tlEditorRef, isWheelZoomRef, initialZoo
const handleMouseWheel = (event) => {
event.preventDefault();
event.stopPropagation();
if (!tlEditorRef.current || !isPresenter) {
if (!tlEditorRef.current || !isPresenter || !currentPresentationPage) {
return;
}

Expand Down
Loading