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 screen flashing when switching to editor #5073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions app/components-react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ export function useRenderInterval(callback: () => void, delay: number, condition
}, [tick, condition]);
}

/**
* Sets up a useEffect scenario that will only fire after the first render
* instead of the normal case that fires during the first render in addition to after
* dependency changes.
* @param callback Function to handle the desired effect
* @param deps If present, effect will only activate if the values in the list change
*/
export function useUpdateEffect(callback: React.EffectCallback, deps?: React.DependencyList) {
const hasRendered = useRef(false);

useEffect(() => {
if (hasRendered.current) {
callback();
} else {
hasRendered.current = true;
}
}, deps);
}

/**
* Useful for firing off an async request when the component mounts, but
* the result will be automatically discarded if the component unmounts
Expand Down
4 changes: 3 additions & 1 deletion app/components-react/shared/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Display as OBSDisplay } from '../../services/video';
import { TDisplayType } from 'services/settings-v2/video';
import uuid from 'uuid/v4';
import { useRealmObject } from 'components-react/hooks/realm';
import { useUpdateEffect } from 'components-react/hooks';

interface DisplayProps {
id?: string;
sourceId?: string;
Expand Down Expand Up @@ -43,7 +45,7 @@ export default function Display(props: DisplayProps) {
const displayEl = useRef<HTMLDivElement>(null);

useEffect(updateDisplay, [p.sourceId, paddingColor]);
useEffect(refreshOutputRegion, [v.baseResolution]);
useUpdateEffect(refreshOutputRegion, [v.baseResolution]);

function refreshOutputRegion() {
if (!obsDisplay.current) return;
Expand Down
Loading