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

$pwa.showInstallPrompt always false? #48

Closed
ampharino opened this issue Jun 2, 2023 · 14 comments
Closed

$pwa.showInstallPrompt always false? #48

ampharino opened this issue Jun 2, 2023 · 14 comments

Comments

@ampharino
Copy link

ampharino commented Jun 2, 2023

I'm building a Nuxt 3 app and would like to show an install prompt if the user has not installed the PWA yet. From reading the docs, my understanding is that I could just check the value of $pwa.showInstallPrompt like the way elk does it to determine whether to show the prompt. However, it seems like the value is always false. What am I missing?

<template>
    ...
    <PwaInstallPrompt v-if="$pwa.showInstallPrompt"/>
    ...
<template>

Here's my pwa config in nuxt.config.ts.

pwa: {
    manifest: {
      name: 'Codashop',
      short_name: 'Codashop',
      start_url: '/?utm_source=pwa',
      icons,
      display: 'standalone',
      orientation: 'portrait',
      background_color: '#280031',
      theme_color: '#280031',
    },
    devOptions: { enabled: true, type: 'module' },
    client: {
      installPrompt: true,
    },
  }
@userquin
Copy link
Member

userquin commented Jun 2, 2023

@ampharino weird, are you testing in Chrome (or any Chromium based browser, not all browsers support this feature)? The PWA must not be installed: https://github.com/vite-pwa/nuxt/blob/main/templates/pwa.client.ts#L95.

FYI: Elk's custom PWA module was pulled here with the help of Daniel

@ampharino
Copy link
Author

@userquin I'm testing in chrome. I can confirm that the PWA is not installed. $pwa.isInstalled is returning the correct value.
I can get the prompt to show if I do <PwaInstallPrompt v-if="!$pwa.isInstalled"/>

@userquin
Copy link
Member

userquin commented Jun 5, 2023

You need to add the webmanifest and check the service worker is Green in dev tools.

@ampharino
Copy link
Author

ampharino commented Jun 6, 2023

@userquin Service worker is green and the app is installable. I'm just using the auto generated service worker
Screen Shot 2566-06-06 at 11 27 16

@userquin
Copy link
Member

userquin commented Jun 6, 2023

Your pwa manifest seems to not have icons entry, you need at least 2 icons: 192×192 and 512×512

@ampharino
Copy link
Author

@userquin I do have an icons entry.
Screen Shot 2566-06-06 at 15 18 11

Maybe related, but if I do a hard refresh nuxt gives me a 500 error

[3:15:02 PM] [Vue warn]: Property "$pwa" was accessed during render but is not defined on instance.
[3:15:02 PM] [nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading 'showInstallPrompt')
  at _sfc_ssrRender (./pages/[locale]/index.vue:62:17)
  at renderComponentSubTree (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:683:9)
  at ./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:629:25
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:870:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)
  at async unrollBuffer$1 (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:875:16)

@userquin
Copy link
Member

userquin commented Jun 6, 2023

Use "$pwa?.<prop>"

@ampharino
Copy link
Author

Ah ok thank you that fixes the hard refresh issue

@ampharino
Copy link
Author

Could not reproduce the issue with the same pwa config in a fresh nuxt 3 project 🤔

@ampharino
Copy link
Author

ampharino commented Jun 6, 2023

@userquin I could get it working briefly. I deleted <VitePwaManifest/> from app.vue, wait for hmr update and then add it back and wait for hmr update again it works. However if I refresh the page after this, it no longer works. Only difference I've found is that there are two web manifests when its working.
Screen Shot 2566-06-06 at 18 05 55

Any ideas?

Here is my app.vue. template

<template>
  <NuxtLayout>
    <VitePwaManifest/>
    <div>
      <NuxtPage />
    </div>
  </NuxtLayout>
</template>

@userquin
Copy link
Member

userquin commented Jun 6, 2023

@ampharino can you share a minimal repo?

@ampharino
Copy link
Author

I was able to resolve the issue and get everything working by wrapping <VitePwaManifest/> inside <ClientOnly> nuxt component. Let me know if you still want a minimal repo for further investigation

@userquin
Copy link
Member

userquin commented Jun 7, 2023

@ampharino it is weird, I'll check it on a new nuxt project, but the virtual used in the component should be ok with SSR

EDIT: can you provide the repo 🙏 ?

@ampharino
Copy link
Author

@userquin I tried reproducing the issue on a new nuxt project but am unable to and unfortunately I can't share the actual repo. Lets just consider this issue resolved 🙏

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

No branches or pull requests

2 participants