diff --git a/package.json b/package.json index 3ef430b..9485a2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-live-preview", - "version": "0.1.5", + "version": "0.1.6", "description": "Vite preview watch mode.", "license": "ISC", "repository": { diff --git a/src/plugin.ts b/src/plugin.ts index e4e90b1..556cdc8 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -54,6 +54,7 @@ export default ({ reload = true, enable }: PreviewModeOptions = {}): Plugin => { let resolvedConfig: ResolvedConfig | undefined; let previewServer: PreviewServer | undefined; let error: Error | undefined; + let sendTimeout: NodeJS.Timeout | undefined; const sockets = new Set(); @@ -98,9 +99,12 @@ export default ({ reload = true, enable }: PreviewModeOptions = {}): Plugin => { if (previewServer) { if (reload) { previewServer.config.logger.info(chalk.green('page-reload'), { timestamp: true }); - sockets.forEach((socket) => { - socket.send(JSON.stringify({ type: 'page-reload' })); - }); + clearTimeout(sendTimeout); + sendTimeout = setTimeout(() => { + sockets.forEach((socket) => { + socket.send(JSON.stringify({ type: 'page-reload' })); + }); + }, 250).unref(); } if (resolvedConfig?.clearScreen !== false) {