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(nuxt): await async payload revivers #25222

Merged
merged 1 commit into from Jan 16, 2024
Merged

Conversation

CernyMatej
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 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 PR resolves an issue where the payload reviver was not awaited if it was an asynchronous function. This could be useful for creating more versatile payload revivers (utilizing dynamic imports), for example. However, prior to this change, the revived value on the client would be a promise instead of its resolved value.

It would probably also be a good idea to add tests for this issue. However, I noticed that definePayloadReducer and definePayloadReviver are listed in skippedComposables in the tests. Is there a reason why they are not tested?

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

Copy link

stackblitz bot commented Jan 15, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the 3.x label Jan 15, 2024
@manniL
Copy link
Member

manniL commented Jan 16, 2024

@CernyMatej There are tests in place though, see

definePayloadReviver('BlinkingText', () => '<revivified-blink>')
if (import.meta.server) {
and
export default defineNuxtPlugin((nuxtApp) => {
if (nuxtApp.payload.serverRendered && nuxtApp.payload.blinkable !== '<revivified-blink>' && document.querySelector('#__NUXT_DATA__')) {

@danielroe danielroe merged commit 4893d19 into nuxt:main Jan 16, 2024
35 checks passed
@github-actions github-actions bot mentioned this pull request Jan 16, 2024
@CernyMatej
Copy link
Contributor Author

@manniL thanks for pointing that out! Didn't notice them. However, those are only fixtures. Where are they used in tests? I'd be happy to write a test case for it if you could tell me where to put it.

@manniL
Copy link
Member

manniL commented Jan 16, 2024

@CernyMatej That's it! the first link shows where it is set up and the 2nd link shows where it is checked in the fixture, throwing an error and failing tests when the reviving would fail ☺️
Maybe it'd be already enough to make that case async though πŸ€”

@github-actions github-actions bot mentioned this pull request Jan 16, 2024
@CernyMatej
Copy link
Contributor Author

I noticed that I had made changes to the devalue source code to support asynchronous revivers before making the changes in Nuxt and forgot about them. πŸ€¦β€β™‚οΈ

At the moment, parse() from devalue isn't asynchronous and doesn't actually await the reviver which causes the revived value to stay as a fulfilled promise. I'm wondering what would be the best solution for this... πŸ€”

Changing parse() to be asynchronous would be a breaking change, wouldn't it? I'm thinking maybe include the parsing code in Nuxt and change it to be asynchronous - so that other users of devalue are not affected by this change?

@manniL
Copy link
Member

manniL commented Jan 16, 2024

@CernyMatej I think it would unless introducing a parseAsync function πŸ˜‹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants