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

feat: skip bundle stats when load non-html page #12246

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

bytemain
Copy link
Contributor

@bytemain bytemain commented Mar 28, 2024

close: #12235

Summary by CodeRabbit

  • Refactor
    • Improved the logic for handling bundle status checks to better respond to different content type requests in the development tool.

Copy link

vercel bot commented Mar 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
umi ⬜️ Ignored (Inspect) Visit Preview Mar 28, 2024 6:15am

Copy link

coderabbitai bot commented Mar 28, 2024

Walkthrough

The recent update in the devTool.ts file introduces a nuanced approach to handling requests for the bundle status during development. By considering the request headers for content type acceptance, the system now better manages how and when to display the loading HTML. This change aims to improve the developer experience, especially for those working with server-side rendered pages and relying on specific script loading behaviors.

Changes

File Path Change Summary
.../preset-umi/src/.../devTool.ts Adjusted logic to consider request headers for content type before responding with bundle status HTML

Assessment against linked issues

Objective Addressed Explanation
[#12235]: Allow disabling devtools bundle stats page via environment variable

A hop, a skip, in the code we dip,
Changes we make, so smoothly they slip.
Through headers and bundles, we carefully tread,
Improving the flow, where developers are led.
🐰 With each line refined, our goals we meet,
In the world of code, these victories are sweet.

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>.
    • 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

@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 e7e9895 and 44006b5.
Files selected for processing (1)
  • packages/preset-umi/src/features/devTool/devTool.ts (1 hunks)
Additional comments (1)
packages/preset-umi/src/features/devTool/devTool.ts (1)
  • 83-97: The logic introduced to check the request headers' Accept value before deciding to serve the loading HTML is a good approach to address the issue described in the PR objectives. However, there are a few considerations and potential improvements:
  1. Performance and Readability: The condition checks for text/html or */* in the Accept header. This is a straightforward and effective way to determine the content type the client expects. However, it's worth noting that the Accept header can contain multiple values with varying priorities. While the current implementation works for most cases, a more robust parsing might be needed for complex scenarios. For now, this approach is sufficient but keep an eye on edge cases where clients send complex Accept headers.

  2. Maintainability: The logic for determining whether the bundle is done is clear and concise. It checks the bundle status and, depending on the configuration (enableVite, mfsu), decides whether to serve the loading HTML. This is a good practice as it keeps the decision-making process centralized and easy to understand. However, consider extracting this logic into a separate function if the decision-making process becomes more complex in the future. This would improve maintainability and testability.

  3. Best Practices: Setting the Content-Type header explicitly before sending the response is a good practice, ensuring that the client interprets the response correctly. This aligns with best practices for web development.

Overall, the changes are well-implemented and address the issue at hand effectively. Just keep the mentioned considerations in mind for future development.

@sorrycc sorrycc merged commit f26517c into umijs:master Mar 28, 2024
3 checks passed
@fz6m
Copy link
Member

fz6m commented Apr 1, 2024

这个改动经验证真的解决了你的问题了吗,See #12235 (comment) ,我认为有可能没完全解决。

@bytemain
Copy link
Contributor Author

bytemain commented Apr 2, 2024

升级了一下 4.1.6 想验证一下,发现项目起不来了。

但是应该是没有解决我的问题的,我直接看了下 stackoverflow 和 github 的 js 请求,<script> 标签的 request headers 都是 Accpet: */*

CleanShot 2024-04-02 at 10 18 32@2x

@bytemain
Copy link
Contributor Author

bytemain commented Apr 2, 2024

验证了下,还是没用

CleanShot 2024-04-02 at 10 21 34@2x

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.

[Bug] 启动项目编译时,请求 js 文件,不要返回 devtools 的 bundle stats html 页面
3 participants