Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(dynamic-branding): hold the first paint until the branding is applied

Hristo Terezova8625d803033
diff --git a/css/_base.scss b/css/_base.scss
index 41219f67aa..d30cf7bd6a 100644
--- a/css/_base.scss
+++ b/css/_base.scss
@@ -43,6 +43,17 @@ body {
background: #040404; // should match DEFAULT_BACKGROUND from interface_config
}
+/**
+ * Hides everything on the page, including dialogs rendered straight into the body, while the dynamic
+ * branding is being applied, so the default look is never painted on branded deployments. Opacity
+ * rather than visibility so elements can still take focus meanwhile. Toggled by the dynamic-branding
+ * web middleware.
+ */
+body.dynamic-branding-pending > * {
+ opacity: 0;
+ pointer-events: none;
+}
+
/**
* This will hide the focus indicator if an element receives focus via the mouse,
* but it will still show up on keyboard focus, thus preserving accessibility.
diff --git a/react/features/dynamic-branding/constants.ts b/react/features/dynamic-branding/constants.ts
index 4658e6aaf6..b85f0f1257 100644
--- a/react/features/dynamic-branding/constants.ts
+++ b/react/features/dynamic-branding/constants.ts
@@ -3,3 +3,16 @@
* hosted by the customer, so one slow or unreachable URL must not hold back the others.
*/
export const CUSTOM_ICON_FETCH_TIMEOUT = 5000;
+
+/**
+ * How long the first paint waits for the dynamic branding to be applied before giving up and showing
+ * the default look. Long enough for the branding request and the icons on a normal connection, short
+ * enough that a slow or failing branding endpoint does not keep the page blank.
+ */
+export const DYNAMIC_BRANDING_WAIT_TIMEOUT = 3000;
+
+/**
+ * Class set on the document body while the first paint is waiting for the dynamic branding. Styled
+ * in css/_base.scss.
+ */
+export const DYNAMIC_BRANDING_PENDING_CLASS = 'dynamic-branding-pending';
diff --git a/react/features/dynamic-branding/middleware.web.ts b/react/features/dynamic-branding/middleware.web.ts
index 449e507b55..d97c060541 100644
--- a/react/features/dynamic-branding/middleware.web.ts
+++ b/react/features/dynamic-branding/middleware.web.ts
@@ -1,17 +1,37 @@
import { SET_CONFIG } from '../base/config/actionTypes';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
-import { SET_DYNAMIC_BRANDING_DATA } from './actionTypes';
+import {
+ SET_DYNAMIC_BRANDING_DATA,
+ SET_DYNAMIC_BRANDING_FAILED,
+ SET_DYNAMIC_BRANDING_ICONS,
+ SET_DYNAMIC_BRANDING_READY
+} from './actionTypes';
import { fetchCustomBrandingData } from './actions.any';
+import { DYNAMIC_BRANDING_PENDING_CLASS, DYNAMIC_BRANDING_WAIT_TIMEOUT } from './constants';
+import { isDynamicBrandingPending } from './functions.any';
import { createMuiBrandingTheme } from './functions.web';
import './middleware.any';
+/**
+ * Ends the wait for the branding when it takes too long, so a slow or failing branding endpoint
+ * cannot keep the page blank.
+ */
+let waitTimeout: ReturnType<typeof setTimeout> | undefined;
+
MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
case SET_CONFIG: {
const result = next(action);
+ // The config tells whether there is branding to wait for. Checking "pending" rather than
+ // "configured" also keeps a later SET_CONFIG (e.g. a shard change) from hiding a page whose
+ // branding is already applied.
+ if (isDynamicBrandingPending(store.getState())) {
+ holdFirstPaint();
+ }
+
store.dispatch(fetchCustomBrandingData());
return result;
@@ -22,8 +42,49 @@ MiddlewareRegistry.register(store => next => action => {
if (customTheme) {
action.value.muiBrandedTheme = createMuiBrandingTheme(customTheme);
}
+
+ // Falls through: the data may or may not complete the branding, depending on the icons.
+ }
+
+ // eslint-disable-next-line no-fallthrough
+ case SET_DYNAMIC_BRANDING_FAILED:
+ case SET_DYNAMIC_BRANDING_ICONS:
+ case SET_DYNAMIC_BRANDING_READY: {
+ const result = next(action);
+
+ if (!isDynamicBrandingPending(store.getState())) {
+ releaseFirstPaint();
+ }
+
+ return result;
}
}
return next(action);
});
+
+/**
+ * Keeps the page content invisible until the dynamic branding has been applied, so users never see
+ * the default theme and icons get replaced by the branded ones. Nothing else is held back: the app
+ * keeps mounting and initializing (connection, prejoin, devices), only the paint waits, and at most
+ * for {@link DYNAMIC_BRANDING_WAIT_TIMEOUT}.
+ *
+ * @returns {void}
+ */
+function holdFirstPaint(): void {
+ document.body.classList.add(DYNAMIC_BRANDING_PENDING_CLASS);
+ clearTimeout(waitTimeout);
+ waitTimeout = setTimeout(releaseFirstPaint, DYNAMIC_BRANDING_WAIT_TIMEOUT);
+}
+
+/**
+ * Lets the page paint, either because the branding has been applied or because waiting for it
+ * took too long.
+ *
+ * @returns {void}
+ */
+function releaseFirstPaint(): void {
+ clearTimeout(waitTimeout);
+ waitTimeout = undefined;
+ document.body.classList.remove(DYNAMIC_BRANDING_PENDING_CLASS);
+}