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: clientContext isn't available in background functions #2121

Merged

Conversation

Skn0tt
Copy link
Contributor

@Skn0tt Skn0tt commented May 17, 2023

Description

This PR fixes a regression introduced in #2058. clientContext isn't available in backround functions, so destructuring on it throws an error.

Documentation

Tests

You can test this change yourself like so:

  1. TODO

Relevant links (GitHub issues, etc.) or a picture of cute animal

@Skn0tt Skn0tt requested a review from a team as a code owner May 17, 2023 09:06
@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/646499309b16920008bcb620
😎 Deploy Preview https://deploy-preview-2121--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/64649930917935000777f145
😎 Deploy Preview https://deploy-preview-2121--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/646499309c367e000874bd73
😎 Deploy Preview https://deploy-preview-2121--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label May 17, 2023
@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/646499304e550000087b6c70
😎 Deploy Preview https://deploy-preview-2121--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/646499300fc1a30008cdd8df
😎 Deploy Preview https://deploy-preview-2121--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/64649930685dc20008d113d1
😎 Deploy Preview https://deploy-preview-2121--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/64649930b9108a0008a1c13d
😎 Deploy Preview https://deploy-preview-2121--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/64649930bfa640000868f5d9
😎 Deploy Preview https://deploy-preview-2121--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 77cc11a
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/6464993027d01600084d46df
😎 Deploy Preview https://deploy-preview-2121--next-plugin-canary.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

const {
clientContext: { custom: customContext },
} = context
const customContext = context.clientContext?.custom
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any way to test this @Skn0tt?
I appreciate we might not have a good testing strategy yet for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we have a good testing strategy yet, no. We could probably build something to test background functions using https://webhook.site/, but i'd like to address that in a separate PR/issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've tested this manually and it works fine. As @Skn0tt mentioned, we definitely need e2e testing around background functions, but it feels separate to this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracked the need for an E2E test in #2122.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - thanks!

Copy link
Contributor

@orinokai orinokai left a comment

Choose a reason for hiding this comment

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

lgtm - neater too!

const {
clientContext: { custom: customContext },
} = context
const customContext = context.clientContext?.custom
Copy link
Contributor

Choose a reason for hiding this comment

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

I've tested this manually and it works fine. As @Skn0tt mentioned, we definitely need e2e testing around background functions, but it feels separate to this fix.

@kodiakhq kodiakhq bot merged commit df0f6bc into main May 17, 2023
@kodiakhq kodiakhq bot deleted the fix-clientcontext-not-available-in-background-functions branch May 17, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants