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(SSU): 🐛 in case external not avaible to all entries #1698

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Nov 20, 2024

problem

found in internal h5 project which has multi entries, different entry has different html script tag
so the external maybe not available every page

solution

wrap those require in try catch

Summary by CodeRabbit

  • 新特性

    • 增强了缓存状态加载的错误处理,返回更安全的选项。
    • 改进了构建过程中的日志记录,特别是在缓存验证和状态管理方面。
    • 更新了写入当前缓存状态的方法,确保仅在必要时写入。
    • 修复了模块块管理中的 JavaScript 运行时代码生成问题。
  • 性能优化

    • 在生成块文件的过程中引入并行处理,提升性能。

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

本次变更涉及对 CentralChunkEnsure 结构体中的 runtime_plugins 方法及 SUPlus 结构体中的多个方法的修改。主要更新包括对 JavaScript 运行时代码的改进,确保模块块管理的函数定义正确封闭,并增强了错误处理逻辑。此外,load_cached_state 方法的返回值格式已更改,以避免失败时的崩溃。整体结构保持不变,但在错误处理、日志记录和性能优化方面进行了增强。

Changes

文件路径 更改摘要
crates/mako/src/plugins/central_ensure.rs 修改 runtime_plugins 方法,添加闭合大括号以正确封闭 requireModule.updateEnsure2Map 函数。更新 requireModule.ensure2 方法以检查 toEnsure 的存在性并返回相应的 Promise。
crates/mako/src/plugins/ssu.rs 修改 load_cached_state 方法以返回 Option<CacheState>,增强错误处理。更新 runtime_plugins 方法的闭包语法,改进 next_build 方法的逻辑,增强 after_build 方法的日志记录。更新 write_current_cache_state 方法以确保必要时写入缓存状态,改进 after_generate_chunk_files 方法以支持并行处理。

Possibly related PRs

🐰 在代码的草地上,
我们跳跃着欢笑,
错误处理更周全,
模块管理更明了。
运行时的代码新,
并行处理如风行,
兔子们齐声唱,
代码美好真欢畅! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 28a1c38 and 1ece7bb.

📒 Files selected for processing (1)
  • crates/mako/src/plugins/ssu.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/mako/src/plugins/ssu.rs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Walkthrough

This pull request addresses an issue in an internal H5 project with multiple entries, where different entries have different HTML script tags, causing some externals to be unavailable on every page. The solution involves wrapping the require statements in a try-catch block to handle cases where externals are not available.

Changes

File Summary
crates/mako/src/plugins/central_ensure.rs Fixed syntax by adding missing semicolons to ensure proper closure of functions.
crates/mako/src/plugins/ssu.rs Wrapped require statements in try-catch blocks to handle potential errors when externals are not available.

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: 1

🧹 Outside diff range and nitpick comments (3)
crates/mako/src/plugins/central_ensure.rs (2)

64-64: 修复了 JavaScript 代码生成中的语法错误

添加了缺失的右花括号,确保了 updateEnsure2Map 函数定义的完整性。这个修复很重要,因为它:

  1. 修正了 JavaScript 运行时代码的语法
  2. 确保了动态模块加载时的正确性
  3. 与 PR 的目标(处理外部资源不可用的情况)相符

建议考虑以下改进:

  1. 为生成的 JavaScript 代码添加错误处理机制
  2. 在更新映射之前验证 newMapping 的格式

建议添加以下错误处理逻辑:

  requireModule.updateEnsure2Map = function(newMapping) {{
+   if (typeof newMapping !== 'object') {
+     console.warn('Invalid mapping format provided');
+     return;
+   }
    map = newMapping;
  }};

Line range hint 41-77: 建议增强错误处理的可读性

当前的错误处理实现基本完善,但建议增加更详细的错误信息,以便于调试和问题定位。

建议按照以下方式改进错误处理:

- let chunk_async_map = module_ensure_map(context)?;
+ let chunk_async_map = module_ensure_map(context)
+     .map_err(|e| anyhow!("Failed to generate module ensure map: {}", e))?;

- let ensure_map = serde_json::to_string(&chunk_async_map)?;
+ let ensure_map = serde_json::to_string(&chunk_async_map)
+     .map_err(|e| anyhow!("Failed to serialize chunk async map: {}", e))?;
crates/mako/src/plugins/ssu.rs (1)

Line range hint 571-603: 修复遍历 css_patch 时使用错误的变量

在遍历 css_patch 时,循环中错误地使用了 js_patch 作为迭代对象,导致无法正确处理 CSS 补丁映射。应将第二个循环中的迭代对象更正为 css_patch

请应用以下差异修复:

 for(var key in js_patch) {
     chunksIdToUrlMap[key] = js_patch[key];
 }
-for(var key in js_patch) {
+for(var key in css_patch) {
     cssChunksIdToUrlMap[key] = css_patch[key];
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8b38e19 and 28a1c38.

📒 Files selected for processing (2)
  • crates/mako/src/plugins/central_ensure.rs (1 hunks)
  • crates/mako/src/plugins/ssu.rs (3 hunks)

crates/mako/src/plugins/ssu.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.28%. Comparing base (8b38e19) to head (1ece7bb).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1698   +/-   ##
=======================================
  Coverage   55.28%   55.28%           
=======================================
  Files         175      175           
  Lines       17696    17696           
=======================================
  Hits         9783     9783           
  Misses       7913     7913           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@stormslowly stormslowly merged commit 5b4e068 into master Nov 21, 2024
21 checks passed
@stormslowly stormslowly deleted the fix/ssu_external_may_not_avaible branch November 21, 2024 02:32
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.

1 participant