Skip to content

Conversation

@DreamOfIce
Copy link
Contributor

@DreamOfIce DreamOfIce commented Sep 3, 2025

这个 PR 做了什么? (简要描述所做更改)

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

修复 #18152 中的错误: 更新 4.1.6 后启动开发服务器报错:

Failed to load url /app.ts (resolved id: C:/path/to/project/src/app.ts). Does the file exist?
The request url "C:\path\to\project\src\app.ts" is outside of Vite serving allow list.

原因为新增的默认值中, fs.allow 被错误的设置为[], 此时 Vite 会拒绝为任何文件提供服务
本PR将默认值改为 [searchForWorkspaceRoot()], 以对齐 Vite 默认行为
参考: https://cn.vite.dev/config/server-options.html#server-fs-allow

Summary by CodeRabbit

  • 新功能

  • 缺陷修复

    • H5 开发服务器默认将工作区根目录加入允许访问路径,解决在 Monorepo/工作区场景中导入上层依赖时的访问受限问题,减少 “Forbidden” 报错。
    • 仍支持通过配置自定义允许路径,保留对现有项目配置的兼容性。

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

在 H5 Vite 配置中,引入了 searchForWorkspaceRoot,并将 server.fs.allow 的默认值从空数组改为包含工作区根目录(searchForWorkspaceRoot(process.cwd()))。若提供自定义 serverOption.fs.allow,仍按原逻辑覆盖默认值。未改动导出/对外接口。

Changes

Cohort / File(s) Summary
H5 Vite 服务配置
packages/taro-vite-runner/src/h5/config.ts
新增从 vite 导入 searchForWorkspaceRoot;将默认 server.fs.allow[] 改为 [searchForWorkspaceRoot(process.cwd())];保持用户传入的 serverOption.fs.allow 覆盖逻辑不变。

Sequence Diagram(s)

sequenceDiagram
    participant App as H5 Runner
    participant Config as H5 Config Builder
    participant Vite as Vite Dev Server

    App->>Config: 构建 Vite 配置
    note over Config: 默认 fs.allow = [searchForWorkspaceRoot(process.cwd())]
    alt 用户提供 serverOption.fs.allow
        Config->>Config: 使用用户值覆盖默认
    else 未提供
        Config->>Config: 使用默认工作区根目录
    end
    Config->>Vite: 传入最终 server.fs.allow
    Vite-->>App: 启动 Dev Server(基于允许的文件系统路径)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • yoyo837
  • tutuxxx
  • Single-Dancer

Poem

我在仓根旁,轻轻蹦两下,
fs.allow 有了家,不再独自沙。
若你自定义,我便让路,
默认先摆好,覆盖来由你书。
(_/)\n> (•ᴥ•)🍃


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6b3b8e9 and ee9bc5c.

📒 Files selected for processing (1)
  • packages/taro-vite-runner/src/h5/config.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-vite-runner/src/h5/config.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@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

🧹 Nitpick comments (2)
packages/taro-vite-runner/src/h5/config.ts (2)

7-7: 统一引号风格,修复 ESLint 报错

本行使用了双引号,项目其余 import 基本为单引号,且 ESLint 已报 quotes 错误。建议改为单引号以通过 lint。

-import { searchForWorkspaceRoot } from "vite"
+import { searchForWorkspaceRoot } from 'vite'

145-148: 建议用 appPath 提升一致性与可移植性

此处使用 process.cwd() 在某些集成场景(例如从非项目根目录启动、脚本切换 cwd、IDE 运行配置)可能与实际应用路径不一致。建议改为使用已从上下文解构的 appPath,更贴近 Taro/RN 内部约定并与下方 build.outDir 等配置保持一致。

-  let fsAllow: string[] = [searchForWorkspaceRoot(process.cwd())]
+  let fsAllow: string[] = [searchForWorkspaceRoot(appPath)]

如需进一步稳妥,也可在用户自定义 allow 时追加而非完全覆盖(与 Vite 语义不同,需谨慎评估),以避免误配置导致再次“拒绝服务”:

-  if (serverOption.fs && Array.isArray(serverOption.fs.allow)) {
-    fsAllow = serverOption.fs.allow
-  }
+  if (serverOption.fs && Array.isArray(serverOption.fs.allow)) {
+    fsAllow = serverOption.fs.allow
+    // 可选:若希望兼容默认工作区根目录,避免覆盖导致误拒绝
+    // fsAllow = Array.from(new Set([...serverOption.fs.allow, searchForWorkspaceRoot(appPath)]))
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4a44051 and 6b3b8e9.

📒 Files selected for processing (1)
  • packages/taro-vite-runner/src/h5/config.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/taro-vite-runner/src/h5/config.ts (1)
packages/taro-vite-runner/src/utils/compiler/base.ts (1)
  • process (49-53)
🪛 ESLint
packages/taro-vite-runner/src/h5/config.ts

[error] 7-7: Strings must use singlequote.

(quotes)

🔇 Additional comments (2)
packages/taro-vite-runner/src/h5/config.ts (2)

145-148: 修复点准确:默认 allow 与 Vite 行为对齐,解决 “outside of Vite serving allow list”

将默认值从 [] 改为 [searchForWorkspaceRoot(...)] 能恢复 Vite 的默认允许路径,解决 4.1.6 后 dev 启动报错问题,且仍允许用户通过 serverOption.fs.allow 显式覆盖,符合预期。


7-7: 确认 searchForWorkspaceRoot 已在 Vite 4.x 导出
packages/taro-vite-runner/package.json 中声明了 vite 依赖范围为 ^4,Vite 4.x 内置 searchForWorkspaceRoot API(示例见 Vite 4 配置文档),无需额外变更。 (v4.vite.dev)

@coderabbitai coderabbitai bot requested a review from yoyo837 September 4, 2025 08:50
@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.05%. Comparing base (8432bc9) to head (2400867).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #18291   +/-   ##
=======================================
  Coverage   55.05%   55.05%           
=======================================
  Files         416      416           
  Lines       21560    21560           
  Branches     5256     5284   +28     
=======================================
  Hits        11870    11870           
+ Misses       8042     8034    -8     
- Partials     1648     1656    +8     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Single-Dancer Single-Dancer added this to the 4.1.7 milestone Sep 12, 2025
This was referenced Sep 13, 2025
@Single-Dancer Single-Dancer merged commit 9ac4b8b into NervJS:main Sep 19, 2025
24 checks passed
@Single-Dancer Single-Dancer changed the title fix(vite-runner): correct default value of vite option fs.allow fix(vite-runner): 修正vite 选项 fs.allow 的默认值 Sep 22, 2025
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.

3 participants