From 7a7188adfdf9c99d47c85145dcbc27955765c0bd Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sun, 10 Sep 2023 22:59:59 -0500 Subject: [PATCH] docs: Do not load stackblitz embeds for google --- website/src/components/Playground/Preview.tsx | 2 +- website/src/components/Playground/index.tsx | 32 +++++++++---------- .../src/components/Playground/monaco-init.ts | 2 +- website/src/components/StackBlitz.tsx | 20 ++++++++---- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/website/src/components/Playground/Preview.tsx b/website/src/components/Playground/Preview.tsx index 731705f8abc7..d400c622e1c1 100644 --- a/website/src/components/Playground/Preview.tsx +++ b/website/src/components/Playground/Preview.tsx @@ -92,6 +92,6 @@ function LivePreviewLoader() { const PreviewBlockLazy = lazy( () => import( - /* webpackChunkName: '[request]', webpackPreload: true */ './PreviewBlock' + /* webpackChunkName: 'PreviewBlock', webpackPreload: true */ './PreviewBlock' ), ); diff --git a/website/src/components/Playground/index.tsx b/website/src/components/Playground/index.tsx index 0d8fc75864b3..b16522847ee3 100644 --- a/website/src/components/Playground/index.tsx +++ b/website/src/components/Playground/index.tsx @@ -102,21 +102,7 @@ function PlaygroundContent({ handleCodeChange={handleCodeChange} codes={codes} /> - -
-
- Store - - ▶ - -
- - } - > + { getInitialInterceptorData?: () => T; } +const previewLoading = ( + +
+
+ Store + + ▶ + +
+
+); + const PreviewWithScopeLazy = lazy(() => isGoogleBot - ? Promise.resolve({ default: (props: any): JSX.Element => null }) + ? Promise.resolve({ default: (props: any): JSX.Element => previewLoading }) : import( - /* webpackChunkName: '[request]', webpackPrefetch: true */ './PreviewWithScope' + /* webpackChunkName: 'PreviewWithScope', webpackPrefetch: true */ './PreviewWithScope' ), ); diff --git a/website/src/components/Playground/monaco-init.ts b/website/src/components/Playground/monaco-init.ts index 6915cd625e0b..4a6aca1e9862 100644 --- a/website/src/components/Playground/monaco-init.ts +++ b/website/src/components/Playground/monaco-init.ts @@ -215,7 +215,7 @@ if ( ...rhDeps.map( dep => import( - /* webpackChunkName: '[request]', webpackPreload: true */ `!!raw-loader?esModule=false!./editor-types/@data-client/${dep}.d.ts` + /* webpackChunkName: '[request]', webpackPreload: true, webpackMode: "lazy-once" */ `!!raw-loader?esModule=false!./editor-types/@data-client/${dep}.d.ts` ), ), ]).then(([mPromise, ...settles]) => { diff --git a/website/src/components/StackBlitz.tsx b/website/src/components/StackBlitz.tsx index 704b6c641816..0011ea2470ea 100644 --- a/website/src/components/StackBlitz.tsx +++ b/website/src/components/StackBlitz.tsx @@ -1,6 +1,7 @@ import Link from '@docusaurus/Link'; import React, { useEffect } from 'react'; +import { isGoogleBot } from './Playground/isGoogleBot'; import { useHasIntersected } from './useHasIntersected'; export default function StackBlitz({ @@ -44,12 +45,13 @@ export default function StackBlitz({ return () => frameRef.current?.removeEventListener('load', loadListener); }, [hasIntersected, frameRef]);*/ - if (!hasIntersected) { - return ; - } - - return ( - <> + let embedElement: React.ReactElement; + if (!hasIntersected || isGoogleBot) { + embedElement = ( + + ); + } else { + embedElement = ( + ); + } + + return ( + <> + {embedElement}

More Demos