Skip to content
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

fix: isolated chunk miss connection to chunksIdToUrlMap #988

Merged
merged 7 commits into from
Mar 31, 2024

Conversation

Jinbao1001
Copy link
Member

@Jinbao1001 Jinbao1001 commented Mar 26, 2024

optimize chunk过程, chunkgraph移除graph node时, 中会生成悬浮节点

如 (0, 16) (16, 22) 删除16节点, 两条边会同步移除

节点22成为悬浮节点, 导致深度遍历时无法建立依赖关系, chunksIdToUrlMap中文件映射缺失

解决方案: 在optimize结束后遍历出悬浮节点, 建立与跟节点的edge

Summary by CodeRabbit

  • New Features

    • Enhanced graph connection capabilities within the chunk handling system.
    • Added a new React component with dynamic import capabilities for better code splitting and optimization.
  • Bug Fixes

    • Refined chunk optimization logic to ensure more efficient module merging and dependency connections.
    • Improved handling of isolated nodes in the graph by connecting them to specified chunks.

Copy link
Contributor

coderabbitai bot commented Mar 26, 2024

Walkthrough

This update focuses on enhancing the connectivity and optimization of chunk graphs within a codebase, ensuring consistency in message handling across JavaScript plugins, and improving code-splitting capabilities with the introduction of dynamic imports. The changes aim to streamline the merging and optimization of modules, connect dependencies more efficiently, and refine the user experience with more coherent and dynamic loading of components.

Changes

Files Change Summary
.../mako/src/chunk_graph.rs, .../mako/src/optimize_chunk.rs Added methods to connect isolated nodes to the entry chunk based on criteria; updated chunk handling and removal logic for optimization.
.../e2e/fixtures/code-splitting.complex/expect.js Added assertion for a specific string related to connecting dependencies to chunksIdToUrlMap.
.../e2e/fixtures/code-splitting.complex/src/isolated.ts Introduced a new file isolated.ts with a React component rendering an inline button.
.../e2e/fixtures/code-splitting.complex/src/should-be-merged.ts Added dynamic import using React.lazy() for the isolated component in should-be-merged.ts.

🐰✨

In the realm of code so vast and wide,
A rabbit hopped with a skilled stride.
Connecting nodes with a gentle touch,
Optimizing chunks, not too much.
Through dynamic imports, components dance,
In this update, we advance.
🌟📦🚀


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 49cd6a7 and e9b4896.
Files selected for processing (6)
  • crates/mako/src/chunk_graph.rs (1 hunks)
  • crates/mako/src/optimize_chunk.rs (2 hunks)
  • crates/node/src/js_plugin.rs (1 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/should-be-merged.ts (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/vancant.ts (1 hunks)
Additional comments: 4
crates/node/src/js_plugin.rs (1)
  • 37-37: The update to use param.file.path instead of param.file.pathname for consistency is a good improvement.
crates/mako/src/chunk_graph.rs (1)
  • 195-216: The addition of the connect_vacant_nodes_to_entry_chunk method is a well-implemented solution to ensure that vacant nodes are properly connected to the entry chunk, addressing the issue of disconnected nodes in the chunk graph.
crates/mako/src/optimize_chunk.rs (2)
  • 166-185: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [158-174]

The changes related to merging minimal async chunks into entry chunks and connecting optimized chunk dependents to the entry chunk enhance the optimization process and ensure the integrity of the chunk graph. These adjustments are well-implemented and address the optimization challenges effectively.

  • 182-182: Retaining modules based on merged modules in async chunks is a necessary refinement to ensure that only relevant modules are included in the optimized chunks. This change improves the accuracy of the optimization process.

Comment on lines 1 to 2
import React from 'react';
export default React.createElement("button", null, "inline")
Copy link
Contributor

Choose a reason for hiding this comment

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

The filename vancant.ts appears to be a typo. Consider renaming it to vacant.ts to avoid potential confusion or import errors.

@@ -1,6 +1,7 @@
import React from 'react';
import context from './context';

console.log(React, context);
const vancant = React.lazy(() => import('./vancant'));
Copy link
Contributor

Choose a reason for hiding this comment

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

The component name vancant seems to be a typo. If the filename vancant.ts is corrected to vacant.ts, ensure to update this import to match: const vacant = React.lazy(() => import('./vacant'));.

- const vancant = React.lazy(() => import('./vancant'));
+ const vacant = React.lazy(() => import('./vacant'));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const vancant = React.lazy(() => import('./vancant'));
const vacant = React.lazy(() => import('./vacant'));

@@ -7,6 +7,10 @@ assert(
"minimal async chunk should be merged"
);

assert(
files["index.js"].includes("src_vancant_ts-async.js"),
Copy link
Contributor

Choose a reason for hiding this comment

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

If the filename and component name are corrected from vancant to vacant, ensure to update this assertion to match the new async chunk name: src_vacant_ts-async.js.

-  files["index.js"].includes("src_vancant_ts-async.js"),
+  files["index.js"].includes("src_vacant_ts-async.js"),

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
files["index.js"].includes("src_vancant_ts-async.js"),
files["index.js"].includes("src_vacant_ts-async.js"),

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e9b4896 and e4edc57.
Files selected for processing (3)
  • e2e/fixtures/code-splitting.complex/expect.js (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/should-be-merged.ts (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/vacant.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • e2e/fixtures/code-splitting.complex/expect.js
  • e2e/fixtures/code-splitting.complex/src/should-be-merged.ts
Additional comments: 1
e2e/fixtures/code-splitting.complex/src/vacant.ts (1)
  • 1-2: The changes in vacant.ts introduce a simple React component. The code is clean and follows best practices for React component creation in TypeScript.

However, given the PR's focus on chunk graph optimization and ensuring proper node connections, please ensure this new test fixture is correctly integrated into the test suite and effectively validates the intended improvements.

@Jinbao1001 Jinbao1001 changed the title fix: vancant chunk miss connection to chunksIdToUrlMap fix: vacant chunk miss connection to chunksIdToUrlMap Mar 26, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e4edc57 and ee38cc2.
Files selected for processing (5)
  • crates/mako/src/chunk_graph.rs (1 hunks)
  • crates/mako/src/optimize_chunk.rs (2 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/isolated.ts (1 hunks)
  • e2e/fixtures/code-splitting.complex/src/should-be-merged.ts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • crates/mako/src/chunk_graph.rs
  • crates/mako/src/optimize_chunk.rs
  • e2e/fixtures/code-splitting.complex/expect.js
  • e2e/fixtures/code-splitting.complex/src/should-be-merged.ts
Additional Context Used
Additional comments not posted (1)
e2e/fixtures/code-splitting.complex/src/isolated.ts (1)

1-2: The changes in isolated.ts introduce a simple React component, likely intended as a test fixture for validating the chunk optimization process improvements. The code is syntactically correct and follows React best practices for component creation. Ensure this new component is adequately covered in the test scenarios related to chunk optimization and code splitting.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ee38cc2 and 3c19cf1.
Files selected for processing (2)
  • crates/mako/src/chunk_graph.rs (1 hunks)
  • crates/mako/src/optimize_chunk.rs (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • crates/mako/src/chunk_graph.rs
  • crates/mako/src/optimize_chunk.rs
Additional Context Used

@Jinbao1001 Jinbao1001 changed the title fix: vacant chunk miss connection to chunksIdToUrlMap fix: isolated chunk miss connection to chunksIdToUrlMap Mar 29, 2024
@Jinbao1001 Jinbao1001 merged commit bd2dda9 into master Mar 31, 2024
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the jinbao/patch-2 branch March 31, 2024 07:20
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