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(preset-umi): throw by default when pre-render error #11521

Merged
merged 3 commits into from
Aug 16, 2023

Conversation

MadCcc
Copy link
Contributor

@MadCcc MadCcc commented Aug 16, 2023

Background

现在 Pre-render 失败时仍会跑完整个构建,用户不注意的话就不会发现有编译问题。

Solution

  1. Pre-render 失败时抛错并终止进程
  2. 添加 exportStatic.ignorePreRenderError 配置,开启后会和以前的行为一样

image

@vercel
Copy link

vercel bot commented Aug 16, 2023

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

Name Status Preview Comments Updated (UTC)
umi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2023 2:30am

@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (538fc99) 29.03% compared to head (fcb892d) 29.02%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11521      +/-   ##
==========================================
- Coverage   29.03%   29.02%   -0.01%     
==========================================
  Files         484      484              
  Lines       14701    14705       +4     
  Branches     3473     3475       +2     
==========================================
  Hits         4268     4268              
- Misses       9678     9681       +3     
- Partials      755      756       +1     
Files Changed Coverage Δ
...eset-umi/src/features/exportStatic/exportStatic.ts 0.00% <0.00%> (ø)

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

@PeachScript PeachScript changed the title feat(exportStatic): process exit on pre-render error feat(preset-umi): throw by default on pre-render error Aug 16, 2023
@PeachScript PeachScript changed the title feat(preset-umi): throw by default on pre-render error feat(preset-umi): throw by default when pre-render error Aug 16, 2023
Copy link
Member

@PeachScript PeachScript left a comment

Choose a reason for hiding this comment

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

+1

@PeachScript PeachScript merged commit ca168e9 into umijs:master Aug 16, 2023
24 checks passed
@@ -58,6 +58,9 @@ function getExportHtmlData(routes: Record<string, IRoute>): IExportHtmlItem[] {
* get pre-rendered html by route path
*/
async function getPreRenderedHTML(api: IApi, htmlTpl: string, path: string) {
const {
exportStatic: { ignorePreRenderError = false },
Copy link
Contributor

Choose a reason for hiding this comment

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

下面还有一个 api.config.mountElementId ,所有的属性解构应该放在一起。

@@ -82,6 +85,9 @@ async function getPreRenderedHTML(api: IApi, htmlTpl: string, path: string) {
logger.info(`Pre-render for ${path}`);
} catch (err) {
logger.error(`Pre-render ${path} error: ${err}`);
if (!ignorePreRenderError) {
throw err;
Copy link
Contributor

Choose a reason for hiding this comment

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

  throw new Error('Pre render error', { cause: err })

@@ -654,6 +654,17 @@ export default {
}
```

`exportStatic` 在搭配 `ssr` 使用时会进行预渲染,在预渲染失败时会抛出异常并终止构建,可以通过配置 `ignorePreRenderError` 来忽略预渲染失败的错误,例如:
Copy link
Contributor

@fz6m fz6m Aug 16, 2023

Choose a reason for hiding this comment

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

- `exportStatic` 在搭配 `ssr` 使用时会进行预渲染,在预渲染失败时会抛出异常并终止构建,可以通过配置 `ignorePreRenderError` 来忽略预渲染失败的错误,例如:
+ `exportStatic` 在搭配 `ssr` 使用时会进行预渲染,默认在预渲染失败时会抛出异常并终止构建,通过配置 `ignorePreRenderError` 来忽略预渲染异常报错,例如:

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