-
Notifications
You must be signed in to change notification settings - Fork 2k
Jetbrains - Fix Webview Assets #4222
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
Merged
catrielmuller
merged 4 commits into
main
from
catrielmuller/jetbrains-fix-webview-assets
Dec 4, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Fix Jetbrains webview |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { Plugin } from "vite" | ||
|
|
||
| // Custom plugin to handle CSS per entry point | ||
| // This tracks which CSS belongs to which entry by analyzing the chunk graph | ||
|
|
||
| export const cssPerEntryPlugin = (): Plugin => ({ | ||
| name: "css-per-entry", | ||
| enforce: "post", | ||
| generateBundle(_options, bundle) { | ||
| // Map to track which chunks belong to which entry | ||
| const entryChunks: Record<string, Set<string>> = {} | ||
| const chunkToEntry: Record<string, string> = {} | ||
|
|
||
| // First pass: identify all entry points and their chunk graphs | ||
| for (const [fileName, chunk] of Object.entries(bundle)) { | ||
| if (chunk.type === "chunk" && chunk.isEntry) { | ||
| const entryName = chunk.name | ||
| entryChunks[entryName] = new Set<string>() | ||
| entryChunks[entryName].add(fileName) | ||
| chunkToEntry[fileName] = entryName | ||
|
|
||
| // Traverse all imports recursively | ||
| const traverseImports = (chunkFileName: string, visited = new Set<string>()) => { | ||
| if (visited.has(chunkFileName)) return | ||
| visited.add(chunkFileName) | ||
|
|
||
| const currentChunk = bundle[chunkFileName] | ||
| if (currentChunk && currentChunk.type === "chunk") { | ||
| entryChunks[entryName].add(chunkFileName) | ||
| chunkToEntry[chunkFileName] = entryName | ||
|
|
||
| // Follow static imports | ||
| currentChunk.imports.forEach((imp) => traverseImports(imp, visited)) | ||
|
|
||
| // Follow dynamic imports | ||
| if (currentChunk.dynamicImports) { | ||
| currentChunk.dynamicImports.forEach((imp) => traverseImports(imp, visited)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| traverseImports(fileName) | ||
| } | ||
| } | ||
|
|
||
| // Second pass: collect CSS for each entry based on chunk ownership | ||
| const entryCSS: Record<string, string[]> = {} | ||
|
|
||
| for (const [fileName, asset] of Object.entries(bundle)) { | ||
| if (asset.type === "asset" && fileName.endsWith(".css")) { | ||
| // Try to find which entry this CSS belongs to by checking chunks | ||
| let assignedEntry: string | null = null | ||
|
|
||
| // Check all chunks to see which one references this CSS | ||
| for (const [chunkFileName, chunk] of Object.entries(bundle)) { | ||
| if (chunk.type === "chunk" && chunk.viteMetadata?.importedCss) { | ||
| if (chunk.viteMetadata.importedCss.has(fileName)) { | ||
| // This chunk imports this CSS, find which entry owns this chunk | ||
| assignedEntry = chunkToEntry[chunkFileName] | ||
| if (assignedEntry) break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If we found an entry for this CSS, assign it | ||
| if (assignedEntry) { | ||
| if (!entryCSS[assignedEntry]) { | ||
| entryCSS[assignedEntry] = [] | ||
| } | ||
| entryCSS[assignedEntry].push(fileName) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Third pass: merge CSS for each entry and delete originals | ||
| for (const [entryName, cssFiles] of Object.entries(entryCSS)) { | ||
| if (cssFiles.length > 0) { | ||
| let mergedCSS = "" | ||
| cssFiles.forEach((cssFile) => { | ||
| const asset = bundle[cssFile] | ||
| if (asset && asset.type === "asset") { | ||
| const source = | ||
| typeof asset.source === "string" ? asset.source : new TextDecoder().decode(asset.source) | ||
| mergedCSS += source + "\n" | ||
| delete bundle[cssFile] | ||
| } | ||
| }) | ||
|
|
||
| if (mergedCSS) { | ||
| this.emitFile({ | ||
| type: "asset", | ||
| fileName: `assets/${entryName}.css`, | ||
| source: mergedCSS, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.