Skip to content

Commit

Permalink
Merge pull request #15607 from storybookjs/fix/lazy-load-syntax-highl…
Browse files Browse the repository at this point in the history
…ighter

Components: Lazy-load syntax highlighter
  • Loading branch information
shilman committed Jul 16, 2021
2 parents b559440 + d9183d2 commit 3c076a3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/components/src/blocks/Preview.tsx
Expand Up @@ -4,6 +4,7 @@ import React, {
FunctionComponent,
ReactElement,
ReactNode,
useCallback,
useState,
} from 'react';
import { darken } from 'polished';
Expand All @@ -16,7 +17,6 @@ import { ActionBar, ActionItem } from '../ActionBar/ActionBar';
import { Toolbar } from './Toolbar';
import { ZoomContext } from './ZoomContext';
import { Zoom } from '../Zoom/Zoom';
import { createCopyToClipboardFunction } from '../syntaxhighlighter/syntaxhighlighter';

export interface PreviewProps {
isColumn?: boolean;
Expand Down Expand Up @@ -215,7 +215,13 @@ const Preview: FunctionComponent<PreviewProps> = ({
const layout = getLayout(Children.count(children) === 1 ? [children] : children);

const { window: globalWindow } = global;
const copyToClipboard: (text: string) => Promise<void> = createCopyToClipboardFunction();

const copyToClipboard = useCallback(async (text: string) => {
const { createCopyToClipboardFunction } = await import(
'../syntaxhighlighter/syntaxhighlighter'
);
createCopyToClipboardFunction();
}, []);

const onCopyCapture = (e: ClipboardEvent<HTMLInputElement>) => {
e.preventDefault();
Expand Down

0 comments on commit 3c076a3

Please sign in to comment.