Skip to content

Isolate content script build to prevent silent chunk-import breakage#41

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-vite-chunk-output-issue
Draft

Isolate content script build to prevent silent chunk-import breakage#41
Copilot wants to merge 2 commits intomainfrom
copilot/fix-vite-chunk-output-issue

Conversation

Copy link

Copilot AI commented Mar 15, 2026

Chrome content scripts injected via chrome.scripting.executeScript must be self-contained — they cannot resolve Rollup-emitted chunk imports at runtime. Including selection-overlay.ts in the multi-entry build was a latent trap: any future shared import would silently break the content script with no build-time warning.

Changes

  • vite.content.config.ts (new) — Dedicated single-entry Vite build for the content script. A single-entry Rollup build inlines all static imports unconditionally; no chunks are ever emitted regardless of future refactors. emptyOutDir: false appends to dist/ without clobbering the main build.

  • vite.config.ts — Removes content/selection-overlay from the multi-entry input.

  • package.json — Runs both builds sequentially:

    "build": "tsc && vite build && vite build --config vite.content.config.ts"

The result: dist/content/selection-overlay.js is a fully self-contained bundle. Future imports added to the content script will always be inlined, making the isolation structural rather than incidental.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][High] Vite chunk output risks breaking content script isolation in future refactors</issue_title>
<issue_description>## Summary

The Vite/Rollup build configuration allows shared chunk extraction across all entry points, including the content script. This creates a latent build fragility: any future import added to selection-overlay.ts from a shared module will silently break the content script at runtime.

Details

File: vite.config.ts, lines 47-50

The configuration specifies chunkFileNames: 'chunks/[name].js', and multiple entry points (popup, options, background, offscreen, share, content/selection-overlay) share dependencies. Rollup extracts shared code into common chunks.

Problem: Chrome extension content scripts cannot load ES module chunks — they must be self-contained. chrome.scripting.executeScript with a single file path cannot resolve chunk imports. The content script (selection-overlay.ts) currently works because it has no shared imports, but this is fragile.

Impact:

  • Any future refactoring that adds a shared import to selection-overlay.ts will break the content script at runtime
  • No build-time error will warn the developer — the breakage is silent
  • This is a maintenance trap for any contributor unfamiliar with Chrome extension content script constraints

Suggested Fix

Option A — Prevent chunking for content scripts via manualChunks:

output: {
  entryFileNames: '[name].js',
  chunkFileNames: 'chunks/[name].js',
  assetFileNames: '[name].[ext]',
  manualChunks(id) {
    if (id.includes('selection-overlay')) return undefined;
  }
}

Option B — Build content scripts as a separate Vite configuration with inlineDynamicImports: true (preferred for stronger isolation).

Differentiation from Existing Issues

Distinct from #23 (CI/CD pipeline, linting) and #31 (accessibility, UX polish, build tooling). Neither addresses the specific content script chunk isolation risk in the Vite Rollup output configuration.


Generated by Health Monitor with Omni</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Build the content script as a separate single-entry Vite config so all
imports are always bundled inline, preventing silent runtime breakage if
shared imports are added to selection-overlay.ts in future refactors.

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature] Fix Vite chunk output risks for content script isolation Isolate content script build to prevent silent chunk-import breakage Mar 15, 2026
Copilot AI requested a review from numbers-official March 15, 2026 03:09
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.

[Feature][High] Vite chunk output risks breaking content script isolation in future refactors

2 participants