Skip to content

Commit

Permalink
fix: Don't load plugins twice in HTML pages (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jun 18, 2024
1 parent 5bab9d2 commit 43ae44e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/wxt/src/core/builders/vite/plugins/wxtPluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ try {
// Use "pre" so the new script is added before vite bundles all the scripts
order: 'pre',
handler(html, _ctx) {
const { document } = parseHTML(html);
const script = document.createElement('script');
script.type = 'module';
script.src =
const src =
config.command === 'serve'
? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}`
: virtualHtmlModuleId;

const { document } = parseHTML(html);
const existing = document.querySelector(`script[src='${src}']`);
if (existing) return;

const script = document.createElement('script');
script.type = 'module';
script.src = src;

if (document.head == null) {
const newHead = document.createElement('head');
document.documentElement.prepend(newHead);
Expand Down

0 comments on commit 43ae44e

Please sign in to comment.