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(html): add head when missing from entry point #784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

userquin
Copy link
Member

@userquin userquin commented Nov 13, 2024

Description

When there is no head in the html entry point, the sw and the web manifest may not be register: this PR checks for </head> and <body> to add the head when required, showing a warning when missing both.

Linked Issues

resolves #782

Additional Context


Tip

The author of this PR can publish a preview release by commenting /publish below.

Copy link

netlify bot commented Nov 13, 2024

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

Name Link
🔨 Latest commit f3817fa
🔍 Latest deploy log https://app.netlify.com/sites/vite-plugin-pwa-legacy/deploys/6734ab1ce27fef00081f6456
😎 Deploy Preview https://deploy-preview-784--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

pkg-pr-new bot commented Nov 13, 2024

pnpm add https://pkg.pr.new/vite-plugin-pwa@784

commit: f3817fa

console.warn([
'',
yellow('PWA WARNING:'),
'</head> and <body> not found in the html, the service worker and web manifest will not be injected.',
Copy link
Member Author

Choose a reason for hiding this comment

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

replace this message with:
</head> and <body> not found in the html, the service worker and the web manifest may not be injected.

@@ -25,20 +26,36 @@ navigator.serviceWorker.register('${path}', { scope: '${options.scope}' })
}`.replace(/\n/g, '')
}

export function checkForHtmlHead(html: string) {
if (!html.includes('</head>')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

should we also check for <head />? This will require to parse the html: Vite doesn't add the entries if head is missing and returning the tag array instead here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<head> tag required for the manifest to be correctly injected
1 participant