Skip to content

Commit

Permalink
fix: Wait for colors to be loaded before generating preview image (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin committed Oct 30, 2021
1 parent de96158 commit e388cef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function Preview({ vimColorSchemes, className }: Props) {
const defaultVimColorScheme = vimColorSchemes[0];
const [index, setIndex] = useState<number>(0);

const [isLoading, setIsLoading] = useState<boolean>(true);

const [background, setBackground] = useState<Background>(
defaultVimColorScheme.defaultBackground,
);
Expand Down Expand Up @@ -47,6 +49,8 @@ function Preview({ vimColorSchemes, className }: Props) {
groups.forEach(group => {
preview.current?.style.setProperty(`--vim-${group.name}`, group.hexCode);
});

setIsLoading(false);
}, [background, vimColorScheme, preview]);

function changeVimColorScheme() {
Expand Down Expand Up @@ -81,6 +85,7 @@ function Preview({ vimColorSchemes, className }: Props) {
className={classnames('preview', className, {
'preview--light': background === Background.Light,
'preview--dark': background === Background.Dark,
'preview--loaded': !isLoading,
})}
ref={preview}
>
Expand Down
4 changes: 3 additions & 1 deletion src/gatsby/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async function generatePreviewImages(
fs.mkdirSync(previewDirectory, { recursive: true });
}

await page.waitForSelector('.preview.preview--loaded');

await page.screenshot({
path: previewPath,
clip: {
Expand All @@ -63,7 +65,7 @@ async function generatePreviewImages(
},
});

await page.close()
await page.close();
}

await browser.close();
Expand Down

0 comments on commit e388cef

Please sign in to comment.