Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(bridge,nitro,nuxi,nuxt3,vite): ensure debounced/async handlers run in order #3656

Merged
merged 3 commits into from
Mar 15, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#13492

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Across the nuxt codebase, this PR uses debounce + debounce.promise to prevent initialising a new handler before the old one has finished running (which should prevent double access to files, for example, or multiple callbacks pushing the same plugin to app.plugins, as in the issue linked above).

At the same time, we drop the timeout from (for example) 300 to 1. This leads to a significant increase in DX as it feels much faster.

This PR also:

  • fixes a bug with nuxi dev where any path starting with .nuxt was not triggering a reload (such as .nuxtignore)
  • adds .env and .nuxtrc files to trigger a full nuxt reload

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Mar 14, 2022

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: 9acb39f

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/62306f1d05fa67000813b074

@danielroe danielroe requested a review from pi0 March 14, 2022 15:17
@danielroe danielroe self-assigned this Mar 14, 2022
@danielroe danielroe added bridge bug Something isn't working cli dx enhancement New feature or request nitro nuxt3 vite ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf labels Mar 14, 2022
@pi0
Copy link
Member

pi0 commented Mar 14, 2022

pdebounce.promise waits for the previous promise. When saving file multiple times, the first call takes precedence which is usually an unwanted behavior to build not the latest code. I think we shouldn't set debounce value to a low number like 1ms. It will loose it's purpose of debouncing effect.

@danielroe
Copy link
Member Author

danielroe commented Mar 14, 2022

The reason I've combined debounce.promise + debounce is that it will wait for the previous promise to resolve, and then run the function again, ensuring the latest changes are reflected.

What would you say is the purpose of the debouncing effect?

@pi0
Copy link
Member

pi0 commented Mar 14, 2022

Awaiting on the promise and combining are fine. Changing debounce delay from 200ms to 1ms is almost the same as not having a debnounce effect but a serial await which uses first change not last as .promise avoid calling function if previously running.

@danielroe
Copy link
Member Author

danielroe commented Mar 14, 2022

I think I might be misunderstanding you. The current implementation will use both first and last change, as I've explained.

Might be worth considering not debouncing then, because honestly the experience of speed without the artificial 300ms delay is πŸ”₯

@pi0
Copy link
Member

pi0 commented Mar 14, 2022

See this sandbox please: https://stackblitz.com/edit/node-vnqatc?dev=dev&file=index.mjs

Running pdebounce with 1ms saves one delay but randomly missing last update (v3 should normally be shown in output)

image

@pi0
Copy link
Member

pi0 commented Mar 15, 2022

As a regression of this PR, the last build might still be skipped. We are working on a better solutioon.

@pi0 pi0 merged commit 14b3225 into main Mar 15, 2022
@pi0 pi0 deleted the cli/dev-promises branch March 15, 2022 10:56
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x bridge bug Something isn't working cli dx enhancement New feature or request nitro nuxt3 ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf vite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

duplicate plugins inserted in app:plugins
2 participants