Skip to content

Commit

Permalink
Merge pull request #109 from indeyets/limit-recursion
Browse files Browse the repository at this point in the history
findAssetsInViteManifest: Prevent recursive parsing of same ids
  • Loading branch information
nksaraf authored Jan 10, 2024
2 parents 4f793bd + b3deb3d commit a5271e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-shrimps-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vinxi": patch
---

findAssetsInViteManifest: Prevent recursive parsing of same ids
12 changes: 12 additions & 0 deletions packages/vinxi/lib/manifest/vite-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
* @returns Array of asset URLs
*/
const findAssetsInViteManifest = (manifest, id, assetMap = new Map()) => {
const stack = [];

/**
* @param {string} id
*/
function traverse(id) {
if (stack.includes(id)) {
return [];
}

const cached = assetMap.get(id);
if (cached) {
return cached;
Expand All @@ -21,6 +27,9 @@ const findAssetsInViteManifest = (manifest, id, assetMap = new Map()) => {
if (!chunk) {
return [];
}

stack.push(id);

const assets = [
...(chunk.assets || []),
...(chunk.css || []),
Expand All @@ -30,6 +39,9 @@ const findAssetsInViteManifest = (manifest, id, assetMap = new Map()) => {
const all = [...assets, ...imports].filter(Boolean);
all.push(chunk.file);
assetMap.set(id, all);

stack.pop();

return Array.from(new Set(all));
}
return traverse(id);
Expand Down

0 comments on commit a5271e0

Please sign in to comment.