Skip to content

Commit

Permalink
docs: Do not load stackblitz embeds for google
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Sep 11, 2023
1 parent 5fabf0e commit 7a7188a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion website/src/components/Playground/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ function LivePreviewLoader() {
const PreviewBlockLazy = lazy(
() =>
import(
/* webpackChunkName: '[request]', webpackPreload: true */ './PreviewBlock'
/* webpackChunkName: 'PreviewBlock', webpackPreload: true */ './PreviewBlock'
),
);
32 changes: 15 additions & 17 deletions website/src/components/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,7 @@ function PlaygroundContent<T>({
handleCodeChange={handleCodeChange}
codes={codes}
/>
<Boundary
fallback={
<PreviewWrapper key="preview">
<div className={styles.playgroundPreview}></div>
<div className={styles.debugToggle}>
Store
<span
className={clsx(styles.arrow, styles.right, styles.vertical)}
>
</span>
</div>
</PreviewWrapper>
}
>
<Boundary fallback={previewLoading}>
<PreviewWithScopeLazy
code={code}
{...{
Expand All @@ -141,11 +127,23 @@ interface ContentProps<T = any> {
getInitialInterceptorData?: () => T;
}

const previewLoading = (
<PreviewWrapper key="preview">
<div className={styles.playgroundPreview}></div>
<div className={styles.debugToggle}>
Store
<span className={clsx(styles.arrow, styles.right, styles.vertical)}>
</span>
</div>
</PreviewWrapper>
);

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'
),
);

Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Playground/monaco-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
20 changes: 14 additions & 6 deletions website/src/components/StackBlitz.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -44,12 +45,13 @@ export default function StackBlitz({
return () => frameRef.current?.removeEventListener('load', loadListener);
}, [hasIntersected, frameRef]);*/

if (!hasIntersected) {
return <iframe width={width} height={height} ref={frameRef}></iframe>;
}

return (
<>
let embedElement: React.ReactElement;
if (!hasIntersected || isGoogleBot) {
embedElement = (
<iframe width={width} height={height} ref={frameRef}></iframe>
);
} else {
embedElement = (
<iframe
src={src}
width={width}
Expand All @@ -58,6 +60,12 @@ export default function StackBlitz({
loading="lazy"
sandbox="allow-scripts allow-same-origin"
></iframe>
);
}

return (
<>
{embedElement}
<p style={{ textAlign: 'center' }}>
<Link className="button button--secondary button--sm" to="/demos">
More Demos
Expand Down

0 comments on commit 7a7188a

Please sign in to comment.