Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: polyfill event for useRequestEvent when nitro is disabled #999

Merged
merged 5 commits into from
Dec 13, 2023

Conversation

AndreyYolkin
Copy link
Contributor

🔗 Linked issue

Closes #998

This PR forces useRequestEvent function to create h3-compatible event (via createEvent utility from h3). So, when nitro disabled, useRequestEvent will return constructed event from nuxtApp.ssrContext.req and nuxtApp.ssrContext.res

❓ 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

📝 Checklist

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

@AndreyYolkin AndreyYolkin changed the title fix: useRequestEvent returns H3Event with disabled nitro fix: useRequestEvent returns H3Event with disabled nitro Dec 1, 2023
@danielroe danielroe requested a review from pi0 December 12, 2023 22:34
// Check if we created H3 event manually before
if (nuxtApp.ssrContext?._event) { return nuxtApp.ssrContext._event }
// Create H3 event https://github.com/nuxt/bridge/pull/999#discussion_r1413049422
nuxtApp.ssrContext._event = createEvent(nuxtApp.ssrContext?.req, nuxtApp.ssrContext?.res)
Copy link
Member

Choose a reason for hiding this comment

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

Mind you this is a very fragile low-level method and behavior can be broken in future releases but considering that it is acceptable for edge-case usage in bridge, looks good workaround...

@danielroe danielroe changed the title fix: useRequestEvent returns H3Event with disabled nitro fix: polyfill event for useRequestEvent when nitro is disabled Dec 13, 2023
@danielroe danielroe merged commit 2ea2a8c into nuxt:main Dec 13, 2023
9 checks passed
@github-actions github-actions bot mentioned this pull request Dec 13, 2023
@github-actions github-actions bot mentioned this pull request Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nitro-less useRequestEvent returns undefined
3 participants