fix rebuild debouncing
This commit is contained in:
		@@ -355,6 +355,7 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
 | 
			
		||||
      ],
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    const timeoutIds = new Set()
 | 
			
		||||
    const build = async (clientRefresh) => {
 | 
			
		||||
      const result = await ctx.rebuild().catch((err) => {
 | 
			
		||||
        console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`)
 | 
			
		||||
@@ -380,6 +381,11 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
 | 
			
		||||
      clientRefresh()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const rebuild = (clientRefresh) => {
 | 
			
		||||
      timeoutIds.forEach((id) => clearTimeout(id))
 | 
			
		||||
      timeoutIds.add(setTimeout(() => build(clientRefresh), 250))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (argv.serve) {
 | 
			
		||||
      const wss = new WebSocketServer({ port: 3001 })
 | 
			
		||||
      const connections = []
 | 
			
		||||
@@ -457,7 +463,7 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
 | 
			
		||||
        })
 | 
			
		||||
        .on("all", async () => {
 | 
			
		||||
          console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
 | 
			
		||||
          await build(clientRefresh)
 | 
			
		||||
          rebuild(clientRefresh)
 | 
			
		||||
        })
 | 
			
		||||
    } else {
 | 
			
		||||
      await build(() => {})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user