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

feat(nuxt): add onNuxtReady composable #9478

Merged
merged 4 commits into from
Dec 5, 2022
Merged

feat(nuxt): add onNuxtReady composable #9478

merged 4 commits into from
Dec 5, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#15719

❓ 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

This adds a new onNuxtReady composable. It allows running a callback after your app has finished initializing. It is ideal for running code that should not block the initial rendering of your app.

export default defineNuxtPlugin(() => {
  onNuxtReady(async () => {
    const myAnalyticsLibrary = await import('my-big-analytics-library')
    // do something with myAnalyticsLibrary
  })
})

It is 'safe' to run even after your app has initialized. In this case, then the code will be registerd to run in the next idle callback.

πŸ“ Checklist

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

@danielroe danielroe added enhancement New feature or request 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Dec 2, 2022
@danielroe danielroe requested a review from pi0 December 2, 2022 20:52
@danielroe danielroe self-assigned this Dec 2, 2022
@codesandbox
Copy link

codesandbox bot commented Dec 2, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@vercel vercel bot temporarily deployed to Preview December 2, 2022 21:02 Inactive
@HigherOrderLogic
Copy link
Contributor

Isn't it more ideal to make this a hook? Something like app:ready?

@danielroe
Copy link
Member Author

There is already such a hook, which this composable uses internally.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM πŸ’―

@pi0 pi0 merged commit 4c4249d into main Dec 5, 2022
@pi0 pi0 deleted the feat/on-nuxt-ready branch December 5, 2022 10:09
@pi0 pi0 mentioned this pull request Dec 15, 2022
6 tasks
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe mentioned this pull request Jan 20, 2023
danielroe added a commit that referenced this pull request Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onNuxtReady in nuxt 3
3 participants