Skip to content

🎥 Make videos programmatically with React

race condition actually fixed

JonnyBurgerf064c7325dcc
diff --git a/packages/studio-server/src/preview-server/hmr-suppression.ts b/packages/studio-server/src/preview-server/hmr-suppression.ts
index 51b2a435a5..50905ea394 100644
--- a/packages/studio-server/src/preview-server/hmr-suppression.ts
+++ b/packages/studio-server/src/preview-server/hmr-suppression.ts
@@ -1,7 +1,10 @@
-const suppressedFiles = new Set<string>();
+const suppressedFiles = new Map<string, number>();
export function suppressHmrForFile(absolutePath: string) {
- suppressedFiles.add(absolutePath);
+ suppressedFiles.set(
+ absolutePath,
+ (suppressedFiles.get(absolutePath) ?? 0) + 1,
+ );
}
export function shouldSuppressHmr(filename: string | null): boolean {
@@ -9,8 +12,14 @@ export function shouldSuppressHmr(filename: string | null): boolean {
return false;
}
- if (suppressedFiles.has(filename)) {
- suppressedFiles.delete(filename);
+ const count = suppressedFiles.get(filename) ?? 0;
+ if (count > 0) {
+ if (count === 1) {
+ suppressedFiles.delete(filename);
+ } else {
+ suppressedFiles.set(filename, count - 1);
+ }
+
return true;
}
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index f07e46139d..501a7e1b7c 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -13,7 +13,7 @@ interface UndoEntry {
const MAX_ENTRIES = 100;
const undoStack: UndoEntry[] = [];
const redoStack: UndoEntry[] = [];
-const suppressedWrites = new Set<string>();
+const suppressedWrites = new Map<string, number>();
const watchers = new Map<string, {unwatch: () => void}>();
let storedLogLevel: LogLevel = 'info';
@@ -74,7 +74,7 @@ export function pushToRedoStack(filePath: string, oldContents: string) {
}
export function suppressUndoStackInvalidation(filePath: string) {
- suppressedWrites.add(filePath);
+ suppressedWrites.set(filePath, (suppressedWrites.get(filePath) ?? 0) + 1);
}
function ensureWatching(filePath: string) {
@@ -85,8 +85,14 @@ function ensureWatching(filePath: string) {
const watcher = installFileWatcher({
file: filePath,
onChange: () => {
- if (suppressedWrites.has(filePath)) {
- suppressedWrites.delete(filePath);
+ const count = suppressedWrites.get(filePath) ?? 0;
+ if (count > 0) {
+ if (count === 1) {
+ suppressedWrites.delete(filePath);
+ } else {
+ suppressedWrites.set(filePath, count - 1);
+ }
+
return;
}