nitro icon indicating copy to clipboard operation
nitro copied to clipboard

fix: initialize nitro app before plugins run

Open harlan-zw opened this issue 2 years ago โ€ข 2 comments

๐Ÿ”— Linked issue

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [x] ๐Ÿž 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)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

This is more of a proof-of-concept to highlight the issue and maybe offer a solution, feel free to close for your own solution.

The issue is that when a plugin wants to make an internal fetch, if that endpoint is using useNitroApp, then it will fail. This is because plugins are ran without the nitroApp context being available.

I've got around it previously using a timeout "hack" (https://github.com/harlan-zw/nuxt-link-checker/commit/646e6ff8721eaeb4ac4c56a3a0e03c0ce764f90e), but as has been pointed out, this isn't exactly reliable (https://github.com/harlan-zw/nuxt-simple-sitemap/issues/149#issuecomment-1806885881).

๐Ÿ“ Checklist

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

harlan-zw avatar Nov 12 '23 02:11 harlan-zw

Thanks for making PR. Although it is slightly a breaking/risky behavior change i was considering to do similar change also in order to allow async plugins. I will carefully review it soon to make sure we won't break anything before moving forward.

pi0 avatar Nov 12 '23 19:11 pi0

(delaying to next minor) -- update marked as draft to investigate more

pi0 avatar Nov 20 '23 11:11 pi0

Thank you!!

pi0 avatar Sep 20 '24 12:09 pi0