Detect Rocket Loader and advert about it on docs (#295)

This commit is contained in:
Greg Bergé
2024-03-18 17:33:26 +01:00
committed by GitHub
parent 9b6d34bdbc
commit 718452728f
3 changed files with 22 additions and 1 deletions
+3
View File
@@ -6,6 +6,7 @@ import * as ReactDOM from 'react-dom';
import { AdminToolbar } from '@/components/AdminToolbar';
import { CookiesToast } from '@/components/Cookies';
import { LoadIntegrations } from '@/components/Integrations';
import { RocketLoaderDetector } from '@/components/RocketLoaderDetector';
import { SpaceLayout } from '@/components/SpaceLayout';
import { buildVersion } from '@/lib/build';
import { getContentSecurityPolicyNonce } from '@/lib/csp';
@@ -76,6 +77,8 @@ export default async function ContentLayout(props: { children: React.ReactNode }
</React.Suspense>
) : null}
<RocketLoaderDetector />
<AdminToolbar space={space} content={content} />
</ClientContexts>
);
+16
View File
@@ -0,0 +1,16 @@
export function RocketLoaderDetector() {
return (
<script data-cfasync="false">
{`
if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {
document.getElementById('gitbook-main-content').innerHTML = \`
<div class="p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400 max-w-screen-lg mt-10 mx-auto" role="alert">
<strong>Error in site configuration:</strong>
It looks like \${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to <a href="https://docs.gitbook.com/published-documentation/custom-domain/configure-dns#are-you-using-cloudflare">GitBook's documentation</a> for steps to fix the problem.
</div>
\`;
}
`}
</script>
);
}
+3 -1
View File
@@ -96,7 +96,9 @@ export function SpaceLayout(props: {
}
withHeaderOffset={withTopHeader}
/>
<div className={tcls('flex-1', 'flex', 'flex-col')}>{children}</div>
<div id="gitbook-main-content" className={tcls('flex-1', 'flex', 'flex-col')}>
{children}
</div>
</div>
{customization.themes.toggeable ||