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

feat(docs): add pwa with auto update strategy #573

Merged
merged 37 commits into from Feb 21, 2022
Merged

Conversation

userquin
Copy link
Member

@userquin userquin commented Jan 18, 2022

This PR includes:

  • fix a11y and SEO problems: there are anchors without rel="noopener noreferrer"
  • pwa with auto update strategy: to include prompt strategy we need to switch to @vue/theme or add a custom theme
  • png icons added to use them on the pwa manifest
  • netlify stuff to use correct cache and also adding some security entries on netlify.toml (also added: we need to review it)
  • added a few dev dependencies: localhost-https added to test pwa on local
  • added some scripts on root and on docs to allow build and serve the docs using https (localhost-https)
  • added scripts/build-pwa.ts module to rebuild the pwa once vitepress finish: also added esno to run the module => I run it using esno instead esmo because it never finish, I don't know what's happing with it

Pending tasks, will not be fixed here, see #580

@netlify
Copy link

netlify bot commented Jan 18, 2022

✔️ Deploy Preview for vitest-dev ready!

🔨 Explore the source changes: f378a55

🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/6213477dd96d6900082d91f9

😎 Browse the preview: https://deploy-preview-573--vitest-dev.netlify.app

@userquin
Copy link
Member Author

userquin commented Jan 18, 2022

Run pnpm i before starting preview docs locally, there are new dev dependencies.

To run locally just pnpm run docs:https from root , localhost-https will ask you to create and install a new ssl/tls certificate for localhost if necessary (it will be also reused in another projects using localhost-https, the ssl/tls certificate will be stored on your profile folder, just read the dep docs).

If you don't want to test the pwa, just run pnpm run docs:build && pnpm run docs:serve from root.

To test the pwa, try it on chrome canary, lighthouse is still broken on chromium based browsers. It seems to be fixed on latest version, at leat on chrome.

I mean, to test pwa with lighthouse, the pwa works on any browser.

@userquin userquin mentioned this pull request Jan 19, 2022
5 tasks
@userquin userquin marked this pull request as ready for review January 19, 2022 10:12
[[headers]]
for = "/manifest.webmanifest"
[headers.values]
Content-Type = "application/manifest+json"
Copy link
Member

Choose a reason for hiding this comment

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

We have a root-level one. Is this neccessary?

Copy link
Member Author

@userquin userquin Jan 20, 2022

Choose a reason for hiding this comment

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

Upps, I don't see it, sorry, we can use the top one adding the webmanifest entry.

Should we use 301 instead 302 on new redirection?
/cc @patak-dev

Copy link
Member

Choose a reason for hiding this comment

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

I prefer 302

<link rel="preconnect" crossorigin="anonymous" href="${jsdelivr}">
<link rel="preconnect" crossorigin="anonymous" href="${github}">
<link rel="preconnect" crossorigin="anonymous" href="${avatars}">
`
Copy link
Member

Choose a reason for hiding this comment

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

Can we automate this? I am not so confident of duplicating (It would make future changes much harder)

Copy link
Member Author

@userquin userquin Jan 20, 2022

Choose a reason for hiding this comment

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

We can include some module with the site data, including all stuff there: avatars, links, contributors, fonts...

I'll be back next Tuesday, we can merge and then change it, but proceed as you wish

@userquin userquin requested a review from antfu January 27, 2022 19:12
@userquin
Copy link
Member Author

userquin commented Jan 27, 2022

upps, I need to check offline support, it seems the avatars will not load.
It works, but we need to review a few thinks: since I use img loading="lazy" on all avatars and sponsors, on chromium browsers the images are not downloaded until you scroll down, and so, if we just await to install the sw and then go offline, pressing F5 will fail since the avatars are not yet stored since them are not requested.
I will check if we can force precaching them without prefetching.

@patak-dev
Copy link
Member

Looks awesome @userquin!

The only detail I see is that avatar images are downscaled too much now and they are seen blurry on my monitor:
image

Compared to the current one:
image

Maybe we can use a bit higher resolution for them? Same for the team avatars, you can also see the diff with our sponsor images

'content-type': 'application/json',
},
})
const data = await res.json() as Contributor[] || []
collaborators.push(...data.map(i => i.login))
collaborators.push(...data.map(({ login, avatar_url }) => {
// optimize the avatar size: check avatar and contributors components
Copy link
Member

Choose a reason for hiding this comment

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

The size doesn't matter much, let's keep the codebase simple

Copy link
Member 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 so, just compare these 2:

Your avatar using https://github.com/antfu.png

imagen

And your avatar using https://github.com/antfu.png?size=125 or https://avatars.githubusercontent.com/u/11247099?v=4&s=125:

imagen

Copy link
Member Author

Choose a reason for hiding this comment

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

744KB

@userquin

This comment has been minimized.

@Demivan
Copy link
Member

Demivan commented Jan 28, 2022

I don't know why it is failing, on my windows machine running nr ci the error is:

Looks like snapshot needs updating

@userquin
Copy link
Member Author

userquin commented Jan 28, 2022

I've disabled the PWA, it seems there is some problem with the sw and the images on home page: we only need to change pwaDisabled on docs/docs-data.ts to enable it again.

I've changed all avatars (core team members and contributors) and sponsors images to be loading="lazy" if the PWA is disabled, I need to check what's happenning.

With these latest changes, the docs will work as the current docs deployed on netlify with some performance added: lazy load images.

I think we can merge with the PWA disabled and then fix the images problem: we'll be able also to start adding the new vitepress theme.

To test the docs on the preview you will need to remove the service worker previously installed:
  • Navigate to https://deploy-preview-573--vitest-dev.netlify.app
  • Open dev tools (Option + ⌘ + J on macOS, Shift + CTRL + J on Windows/Linux)
  • Go to Application > Storage, you should check following checkboxes:
    • Application: [x] Unregister service worker
    • Storage: [x] Local and session storage
    • Cache: [x] Cache storage and [x] Application cache
  • Click on Clear site data button
  • Go to Application > Service Workers and check the current service worker is missing or has the state deleted.
  • Hard refresh on https://deploy-preview-573--vitest-dev.netlify.app

@userquin userquin requested a review from antfu January 28, 2022 23:07
@userquin
Copy link
Member Author

reverting last commit, pnpm problem when updating, points to wrong scripts when using nvm

@userquin
Copy link
Member Author

userquin commented Jan 29, 2022

Since the sponsors images can be changed I revert fixed size: there will be some jank.

@userquin
Copy link
Member Author

userquin commented Jan 29, 2022

PWA with injectManifest strategy: GoogleChrome/workbox#3023

EDIT: I need to change pwa plugin to include vite:json plugin when building the custom service worker via rollup.

@userquin
Copy link
Member Author

The PWA is disabled until we fix the contributors avarts CORS problem: to enable PWA we only need to change pwaDisabled = false on docs/docs-data.ts module.

@patak-dev
Copy link
Member

Images are working well, I was seeing them blurry because the old SW was getting in the middle. I think we should merge this one

@patak-dev patak-dev merged commit f5189fd into main Feb 21, 2022
@patak-dev patak-dev deleted the userquin/docs-add-pwa branch February 21, 2022 08:16
chaii3 pushed a commit to chaii3/vitest that referenced this pull request May 13, 2022
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.

None yet

5 participants