-
-
Notifications
You must be signed in to change notification settings - Fork 246
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(security): Use import.meta.hot
for communication with Vite 6.0.9+ (and 5.4.14+) dev server
#1411
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
packages/wxt/build.config.ts
Outdated
'http://localhost:3000/@id/wxt/background-client', | ||
'http://localhost:3000/@vite/client', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO:
'http://localhost:3000/@id/wxt/background-client', | |
'http://localhost:3000/@vite/client', | |
'__DEV_SERVER_ORIGIN__/@id/wxt/background-client', | |
'__DEV_SERVER_ORIGIN__/@vite/client', |
@@ -123,7 +127,7 @@ | |||
"publish-browser-extension": "^2.2.2", | |||
"scule": "^1.3.0", | |||
"unimport": "^3.13.1", | |||
"vite": "^5.0.0 || ^6.0.0", | |||
"vite": "^5.0.0 || <=6.0.8", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"vite": "^5.0.0 || <=6.0.8", | |
"vite": "^5.0.0 || ^6.0.0", |
if (import.meta.hot) { | ||
import.meta.hot.on('wxt:reload-page', (event) => { | ||
// "popup.html" === "/popup.html".substring(1) | ||
if (event.detail === location.pathname.substring(1)) location.reload(); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Test
}; | ||
|
||
const wxtBackgroundClientUrl = `http://${server.hostname}:${server.port}/@id/wxt/background-client`; | ||
console.log({ wxtBackgroundClientUrl }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO remove
} | ||
}); | ||
} | ||
console.log('__WXT_BACKGROUND_CLIENT_IMPORT__'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Remove
import.meta.hot
for communication with Vite 6.0.9+ dev serverimport.meta.hot
for communication with Vite 6.0.9+ (and 5.4.14+) dev server
Status update. I should have it all working, but for some reason I can't load the vite client from the server, debugging this. |
Overview
WXT previously relied on connecting to Vite's dev server manually, instead of using
import.meta.hot
. Vite 6.0.9 introduced several changes that broke WXT's dev mode:Vite introduced a randomly generated auth token to ensure of your application can access it
This broke WXT because WXT doesn't know what the token is. While it is possible to get the token from the dev server, it would take quite a bit of refactoring to route the token into the background script during development, so I'm not gonna do that. Instead, WXT now uses
import.meta.hot
.For MV2, WXT dynamically imports the
vite/client
package from the dev server. For MV3, we're updating dev mode to always setbackground.type: "module"
in the manifest.Warning
This is technically a breaking change to dev mode, however, it should have no effect. WXT will continue to bundle the background as IIFE if you don't specify
type: "module"
in your entrypoint.Manual Testing
Install the new version from pkg.pr.new and spin up your extension in dev mode:
Related Issue