ionic-team / ionic-team/ionic-framework

bug: During hydration Angular expected a text node but found a comment node.

未关闭
#30,125 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
triage
主要语言
TypeScript
星标
52.7k
派生
13.3k
平均合并
1 天 15 小时
30 天内合并 PR
51

描述

### Prerequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.

### Ionic Framework Version

v8.x

### Current Behavior

Following from https://github.com/ionic-team/ionic-framework/issues/28625

My only HTML file is: `app.component.html`
```html
Home
```

`provideServerRendering()` causes
> ERROR RuntimeError: NG0500: During hydration Angular expected a text node but found a comment node.

Fully:
```html
RuntimeError: NG0500: During hydration Angular expected a text node but found a comment node.

Angular expected this DOM:

#text(Home) <-- AT THIS LOCATION

Actual DOM is:

<-- AT THIS LOCATION

Note: attributes are only displayed to better represent the DOM but have no effect on hydration mismatches.

To fix this problem:
* check the "_AppComponent" component for hydration-related issues
* check to see if your template has valid HTML structure
* or skip hydration by adding the `ngSkipHydration` attribute to its host node in a template

Find more at https://angular.dev/errors/NG0500
at validateMatchingNode (core.mjs:15140:11)
at locateOrCreateTextNodeImpl (core.mjs:30741:16)
at Module.ɵɵtext (core.mjs:30715:22)
at AppComponent_Template (app.component.html:4:12)
at executeTemplate (core.mjs:12849:5)
at renderView (core.mjs:14018:7)
at renderComponent (core.mjs:13964:3)
at renderChildComponents (core.mjs:14064:5)
at renderView (core.mjs:14046:7)
at ComponentFactory.create (core.mjs:17381:9)
```

### Expected Behavior

`provideServerRendering` should work with no issue.

### Steps to Reproduce

1. Clone https://github.com/sign/translate
2. Edit `app.component.html` to include only `Home`
3. Edit `app.config.server.ts` to include `provideServerRendering()`
4. Run `npm start`

### Code Reproduction URL

https://github.com/sign/translate

### Ionic Info

[WARN] You are not in an Ionic project directory. Project context may be missing.

Ionic:

Ionic CLI : 7.2.0

Utility:

cordova-res : 0.15.4
native-run : 2.0.1

System:

NodeJS : v22.0.0
npm : 10.5.1
OS : macOS Unknown

"@ionic/angular": "8.4.1",

### Additional Information

Blocks https://github.com/sign/translate/issues/194 and https://github.com/angular/angular-cli/issues/29236

贡献指南

打开贡献指南

调研方向

Start with the reproduction in https://github.com/sign/translate, especially app.component.html and app.config.server.ts, then run npm start with provideServerRendering() enabled. Compare the server-rendered ion-label DOM with Angular's hydration expectations and trace the relevant Ionic component behavior. Done means the minimal reproduction hydrates without NG0500 while preserving the label text.

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend, web-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。