Skip to content

Commit

Permalink
Fix glitch with displaying cookie banner for a split second (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec authored Aug 10, 2023
1 parent 4828dc6 commit da90286
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
2 changes: 0 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ const config = {
},
],

clientModules: [require.resolve("./src/clientModules/embed.ts")],

plugins: [
"docusaurus-plugin-sass",
[
Expand Down
32 changes: 0 additions & 32 deletions src/clientModules/embed.ts

This file was deleted.

27 changes: 21 additions & 6 deletions src/components/CookieBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ import React, { FC } from "react";
import { Link } from "react-router-dom";
import CookieBanner, { Cookies } from "react-cookie-banner";
import styles from "./index.module.scss";
import { DocsConfigWindow } from "@site/src/clientModules/embed";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import useIsBrowser from "@docusaurus/useIsBrowser";

export const CookiesMessageBanner: FC = () => {
const isBrowser = useIsBrowser();
if (!isBrowser) {
return null;
}

const cookies = new Cookies();

if (
!cookies ||
cookies.get("accepts-cookies") ||
(typeof window !== "undefined" && (window as DocsConfigWindow).displayConfig?.cookieBanner.forceHide)
) {
if (!cookies || cookies.get("accepts-cookies") || isSiteEmbedded()) {
console.log("disable cookie banner");
return null;
}

console.log("enable cookie banner");

return (
<CookieBanner
disableStyle={true}
Expand All @@ -31,3 +36,13 @@ export const CookiesMessageBanner: FC = () => {
/>
);
};

function isSiteEmbedded(): boolean {
if (!ExecutionEnvironment.canUseDOM || typeof window === "undefined") {
return false;
}

const urlParams = new URLSearchParams(window.location.search);
const embeddedValue = urlParams.get("embedded");
return embeddedValue === "true";
}

0 comments on commit da90286

Please sign in to comment.