Skip to content

Comments

Include frameworks in main-app (#41465)#3

Open
MitchLewis930 wants to merge 1 commit intopr_033_beforefrom
pr_033_after
Open

Include frameworks in main-app (#41465)#3
MitchLewis930 wants to merge 1 commit intopr_033_beforefrom
pr_033_after

Conversation

@MitchLewis930
Copy link

PR_033

There is no need to have a separate `framework` chunk for React and React DOM, as they're already included in the `main-app` entry. With this PR, React and React DOM will be included in `main-app` directly and app is no longer depending on the `framework` chunk.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `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`
- [ ] Integration 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`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@greptile-apps
Copy link

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Modified webpack splitChunks configuration to bundle framework dependencies (React/ReactDOM) directly into main-app chunk for app directory builds instead of creating a separate framework chunk. This optimization reduces the number of chunks and eliminates duplication since app directory entries already include these dependencies.

Key changes:

  • Added main-app to the list of excluded chunks in the main chunks filter
  • Changed framework cacheGroup's chunks property from 'all' to a conditional function
  • When hasAppDir is true, the function excludes main-app, app-internals, and chunks starting with app/ from the framework chunk extraction
  • For non-app chunks (pages directory), framework dependencies continue to be extracted as before

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is well-scoped and addresses a specific optimization for webpack chunk splitting. The logic is clear and properly guards the new behavior with the hasAppDir condition, ensuring backward compatibility for pages directory builds. The modification only affects how framework dependencies are bundled for app directory entries, which is an internal optimization that shouldn't break existing functionality.
  • No files require special attention

Important Files Changed

Filename Overview
packages/next/build/webpack-config.ts Modified webpack splitChunks configuration to include framework dependencies in main-app chunk instead of creating separate framework chunk

Sequence Diagram

sequenceDiagram
    participant WC as Webpack Config
    participant SC as SplitChunks Plugin
    participant FC as Framework CacheGroup
    participant Chunks as Chunk Output
    
    WC->>SC: Configure splitChunks optimization
    SC->>SC: Evaluate chunks function
    SC->>SC: Exclude polyfills, main, main-app, pages/_app
    
    alt hasAppDir is true
        SC->>FC: Evaluate framework cacheGroup
        FC->>FC: Check chunk name
        alt chunk is main-app, app-internals, or app/*
            FC->>FC: Return false (exclude from framework chunk)
            FC->>Chunks: Include in main-app bundle
        else chunk is not app-related
            FC->>FC: Return true (include in framework chunk)
            FC->>Chunks: Extract to separate framework chunk
        end
    else hasAppDir is false
        SC->>FC: Use all chunks for framework
        FC->>Chunks: Extract all framework deps to separate chunk
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

2 participants