Skip to content

Commit

Permalink
Use set to track CSS imports (#46772)
Browse files Browse the repository at this point in the history
Noticed some duplicated CSS resources in a large application and confirmed that this fixes it.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
shuding committed Mar 4, 2023
1 parent 9a768d5 commit 6357de0
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class FlightClientEntryPlugin {
const visitedBySegment: { [segment: string]: Set<string> } = {}
const clientComponentImports: ClientComponentImports = []
const actionImports: [string, string[]][] = []
const CSSImports: CssImports = {}
const CSSImports = new Set<string>()

const filterClientComponents = (
dependencyToFilter: any,
Expand Down Expand Up @@ -527,8 +527,7 @@ export class FlightClientEntryPlugin {
}
}

CSSImports[entryRequest] = CSSImports[entryRequest] || []
CSSImports[entryRequest].push(modRequest)
CSSImports.add(modRequest)
}

// Check if request is for css file.
Expand Down Expand Up @@ -567,7 +566,11 @@ export class FlightClientEntryPlugin {

return {
clientImports: clientComponentImports,
cssImports: CSSImports,
cssImports: CSSImports.size
? {
[entryRequest]: Array.from(CSSImports),
}
: {},
actionImports,
}
}
Expand Down

0 comments on commit 6357de0

Please sign in to comment.