Skip to content

i18n hydration fails when multiple elements are inside an i18n tag #56176

Closed

Description

@henry-alakazhang

Which @angular/* package(s) are the source of the bug?

core, platform-browser

Is this a regression?

No

Description

When an i18n tag is placed on an Angular component that has multiple elements inside it, hydration throws an error.

For example:

@Component({
  selector: 'app-text',
  template: '<ng-content></ng-content>',
  standalone: true,
})
export class TextComponent {}

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, RouterOutlet, TextComponent],
  template: `
    <app-text i18n>
      Before
      <br />
      After
    </app-text>
  `,
  styleUrls: ['./app.component.css'],
})
export class AppComponent {}

A runtime error is thrown (e.hasAttribute is not a function) during hydration.

In dev mode, this error is thrown as

ASSERTION ERROR: expected matching nodeType [Expected=> 3 == 1 <=Actual]

Please provide a link to a minimal reproduction of the bug

https://github.com/henry-alakazhang/hydration-form-repro

Please provide the exception or error you saw

In dev mode:


ASSERTION ERROR: expected matching nodeType [Expected=> 3 == 1 <=Actual]


### Please provide the environment you discovered this bug in (run `ng version`)

```true
Angular CLI: 18.0.2
Node: 18.20.3
Package Manager: yarn 1.22.19
OS: darwin arm64

Angular: 18.0.1
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.2
@angular-devkit/build-angular   18.0.2
@angular-devkit/core            18.0.2
@angular-devkit/schematics      18.0.2
@angular/cli                    18.0.2
@angular/ssr                    18.0.2
@schematics/angular             18.0.2
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.6

Anything else?

Might be related to content projection on the Angular component, as this doesn't occur when nesting plain HTML elements, ie. this works:

<p i18n>
  Before
  <b/>
  After
</p>

It also works with ng-container.

Thanks!

Activity

  1. added
    area: core
    on May 30, 2024
  2. added this to the needsTriage milestone on May 30, 2024
  3. tomastrajan commented on May 30, 2024

    @tomastrajan
    Contributor

    Encountered the same thing today, would be really great if solved 🙏

  4. added
    P3
    on May 30, 2024
  5. modified the milestones: needsTriage, Backlog on May 30, 2024
  6. AndrewKushnir commented on Jun 20, 2024

    @AndrewKushnir
    Contributor

    Quick update: the fix for this issue was merged and will be available on NPM after the next Angular release (most likely v18.0.5).

  7. tomastrajan commented on Jun 21, 2024

    @tomastrajan
    Contributor

    @AndrewKushnir thank you !

  8. henry-alakazhang commented on Jun 25, 2024

    @henry-alakazhang
    ContributorAuthor

    I built the changes locally and tested it against my repo - everything seems to work. Thanks!

  9. angular-automatic-lock-bot commented on Jul 26, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: corecore: hydrationstate: has PR

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions