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: return async function from registerSW in dev mode #799

Merged

Conversation

piotr-cz
Copy link
Contributor

@piotr-cz piotr-cz commented Nov 27, 2024

Description

The signature for registerSW function should be same for both production and development:

function registerSW(options: RegisterOptions = {}): (_reloadPage?: boolean) => Promise<void>

Linked Issues

None

Additional Context

When trying to update service worker in development, following code throws an error:

import { registerSW } from 'virtual:pwa-register'

const updateServiceWorker = registerSW()

// ...

updateServiceWorker().then(() => { console.log('Service worker updated') })
// Uncaught TypeError: Cannot read properties of undefined (reading 'then')

Note:
Waiting for updateServiceWorker promise to finish this way is particularly helpful to mitigate #789 when used in a react hook

Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for vite-plugin-pwa-legacy ready!

Name Link
🔨 Latest commit 3c20113
🔍 Latest deploy log https://app.netlify.com/sites/vite-plugin-pwa-legacy/deploys/67473617cf276b0007e937f2
😎 Deploy Preview https://deploy-preview-799--vite-plugin-pwa-legacy.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 configuration.

Copy link
Member

@userquin userquin left a comment

Choose a reason for hiding this comment

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

thx ❤️

@userquin userquin merged commit 06c1db6 into vite-pwa:main Nov 29, 2024
5 checks passed
@piotr-cz piotr-cz deleted the bugfix/return-async-register-sw-in-dev branch November 30, 2024 20:35
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.

2 participants