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

Feature request: Add SolidStart support #465

Closed
seeplusplus opened this issue Feb 12, 2023 · 4 comments
Closed

Feature request: Add SolidStart support #465

seeplusplus opened this issue Feb 12, 2023 · 4 comments

Comments

@seeplusplus
Copy link

I'm not sure how difficult this would be to add, but I've already used this plugin with a SolidStart project. Everything seems to work perfectly, except for injecting the SW registration script/manifest link (if I add them manually into the root.tsx everything works). I am also more than happy to take a look at adding this support myself, but may take me a bit longer to learn the code.

@userquin
Copy link
Member

userquin commented Feb 12, 2023

I guess we don't need to include a new package to include only these 2 features, we have a solidjs virtual module and a new virtual module for pwa info that we can use to expose the <link> in the header (not documented, it is present only in meta framework integrations, check Astro or SvelteKit, in Nuxt we have a custom component similar to the code snippet shown below).

About sw registration, use virtual:pwa-register/solid instead injectRegister: 'auto/script', will also solve automatic page reload on sw auto reload: check the warning here https://vite-pwa-org.netlify.app/guide/auto-update.html#automatic-reload

About web manifest, you can use a simple tsx component using virtual:pwa-info, I'm not an expert on Solid, update if necessary:

/// <reference types="vite-plugin-pwa/info" />
import { Link } from "solid-start"; // if missing, just use html <link> tag
import { pwaInfo } from 'virtual:pwa-info';

export function VitePwaManifest() {
  if (pwaInfo) {
    const { webManifest } = pwaInfo;
    if (webManifest) {
      const { href, useCredentials } = webManifest
      return (
        <>
          { useCredentials
            ? <Link rel="manifest" href={href} crossorigin="use-credentials" />
            : <Link rel="manifest" href={href} />
          }
        <>
      )
    }
  }
  return null;
}

@userquin
Copy link
Member

@seeplusplus
If the integration with Solid-Sart requires managing SSR or ISLANDS we could change our mind, the integrations with meta frameworks are only to avoid having to deal with the configuration to build the service worker, just check any of them.

I can upload a repository to my account and see what it comes up with, then it's a nuance to transfer it here.

@seeplusplus
Copy link
Author

@userquin Thanks for the help! These suggestions work perfectly!

Everything is in this repo,

https://github.com/seeplusplus/solid-start-vite-pwa

but it's basically as you said, I just added the useRegisterSW and pwaInfo imports to my root.tsx and everything worked.

I opened #468 in case anyone else finds themselves similarly looking to get started using this project with SolidStart.

@yume-chan
Copy link

@seeplusplus I can't get your repo (https://github.com/seeplusplus/solid-start-vite-pwa) working.

After pnpm i, npm run buidl and npm start, I got this error in browser console:

Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"index.html"}]
    at E.createHandlerBoundToURL (http://localhost:3000/workbox-e0782b83.js:1:13533)
    at Object.createHandlerBoundToURL (http://localhost:3000/workbox-e0782b83.js:1:15140)
    at http://localhost:3000/sw.js:1:1474
    at http://localhost:3000/sw.js:1:565

And after stopping the server, the web page doesn't work offline.

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

3 participants