Skip to content

Commit a58af10

Browse files
committed
feat (vs-code-ext): do not allow for more than one preview panels open at a time
1 parent e49d7e0 commit a58af10

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/vs-code-extension/src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ export function activate(context: vscode.ExtensionContext) {
6666
let disposable = vscode.commands.registerCommand(
6767
"react-email-preview.open",
6868
() => {
69+
if (typeof previewPanel !== 'undefined') return;
70+
6971
previewPanel = vscode.window.createWebviewPanel(
70-
"react-email preview",
71-
"react-email preview",
72+
"react-email preview - try opening an email",
73+
"react-email preview - try opening an email",
7274
vscode.ViewColumn.Two,
7375
{ enableScripts: true },
7476
);
7577

78+
previewPanel.onDidDispose(() => previewPanel = undefined);
79+
7680
updatePreviewPanelContent();
7781

7882
vscode.workspace.onDidChangeTextDocument((ev) => {

packages/vs-code-extension/src/renderOpenEmailFile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { rm, unlink, writeFile } from "fs/promises";
55
import * as esbuild from "esbuild";
66

77
import { render } from "@react-email/render";
8+
import { existsSync } from "fs";
89

910
const extensionPreviewFolder = ".vscpreview" as const;
1011

@@ -61,7 +62,9 @@ export async function renderOpenEmailFile(
6162
outfile: builtFileWithCurrentContents,
6263
});
6364

64-
await unlink(currentlyOpenTabFilesPathWithCurrentContents); // unlink the temporary file after building it
65+
if (existsSync(currentlyOpenTabFilesPathWithCurrentContents)) {
66+
await unlink(currentlyOpenTabFilesPathWithCurrentContents); // unlink the temporary file after building it
67+
}
6568

6669
delete require.cache[builtFileWithCurrentContents];
6770
// we need to use require since it has a way to programatically invalidate its cache

0 commit comments

Comments
 (0)