8000 Problem with hydration and condition in ssr angular 17 · Issue #54201 · angular/angular · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Problem with hydration and condition in ssr angular 17 #54201
Closed as not planned
Closed as not planned
@djouf007

Description

@djouf007

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

core

Is this a regression?

No

Description

I have a problem with a condition in SSR (Server-Side Rendering) related to "hydration." I have a condition based on the screen size, but I see my text content duplicating twice in mobile format. Can I know how to solve this problem without removing the "hydration"?

import { isPlatformBrowser} from '@angular/common';
import {RouterLink} from "@angular/router";
import {ComponentSliderComponent} from '@projects/mod-structure/components/component-slider/component-slider.component';

@Component({
    selector: 'page-fr-1',
    templateUrl: './page-fr-1.component.html',
    styleUrls: ['./page-fr-1.component.css'],
    standalone: true,
    imports: [RouterLink,ComponentSliderComponent]
})
export class Pagefr1Component {

    public isMobile: boolean;

    constructor(@Inject(PLATFORM_ID) private platformId: Object) {
        if (isPlatformBrowser(this.platformId)) this.isMobile = (window.innerWidth < 600);
    }

}

et voici mon html

<div>  @if(!isMobile){<p>
        <strong style="font-size: 30px; color: rgb(50, 75, 119);">
            <em>"Une révolution dans la filtration de l'eau"</em></strong></p><p><br></p><p><strong style="font-size: 30px; color: rgb(102, 102, 102);"></strong><span style="font-size: 24px; color: rgb(50, 75, 119);">Nos cuves par gravité, équipées des filtres </span></p><p><span style="color: rgb(50, 75, 119); font-size: 24px;">Coldstream FTO+,&nbsp;allient innovation et performance </span></p><p><span style="color: rgb(50, 75, 119); font-size: 24px;">pour vous offrir une eau d'une qualité exceptionnelle,&nbsp;</span></p><p class="ql-align-justify"><span style="color: rgb(50, 75, 119); font-size: 24px;">tout en garantissant une autonomie </span></p><p class="ql-align-justify"><span style="color: rgb(50, 75, 119); font-size: 24px;">en eau potable en toutes circonstances.</span></p><p class="ql-align-justify"><br></p>}
        @if(isMobile){<p><strong style="font-size: 30px; color: rgb(50, 75, 119);"><em>"Une révolution dans la filtration de l'eau"</em></strong></p><p><br></p><p><strong style="font-size: 30px; color: rgb(102, 102, 102);"></strong><span style="font-size: 24px; color: rgb(50, 75, 119);">Nos cuves par gravité, équipées des filtres </span></p><p><span style="color: rgb(50, 75, 119); font-size: 24px;">Coldstream FTO+,&nbsp;allient innovation et performance </span></p><p><span style="color: rgb(50, 75, 119); font-size: 24px;">pour vous offrir une eau d'une qualité exceptionnelle,&nbsp;</span></p><p class="ql-align-justify"><span style="color: rgb(50, 75, 119); font-size: 24px;">tout en garantissant une autonomie </span></p><p class="ql-align-justify"><span style="color: rgb(50, 75, 119); font-size: 24px;">en eau potable en toutes circonstances.</span></p><p class="ql-align-justify"><br></p>}</div>

Capture

Please provide a link to a minimal reproduction of the bug

Capture

Please provide the exception or error you saw

![Capture](https://github.com/angular/angular/assets/69094782/61a1dd46-cf4a-4041-bb0e-6f2ad25a1a06)

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

{
  "name": "site",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "serve:ssr": "node dist/server/server.mjs"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^17.0.0",
    "@angular/common": "^17.0.0",
    "@angular/compiler": "^17.0.0",
    "@angular/core": "^17.0.0",
    "@angular/forms": "^17.0.0",
    "@angular/platform-browser": "^17.0.0",
    "@angular/platform-browser-dynamic": "^17.0.0",
    "@angular/platform-server": "^17.0.0",
    "@angular/router": "^17.0.0",
    "@angular/ssr": "^17.0.0",
    "@angular/cdk": "17.0.0",
    "@angular/google-maps": "^17.0.0",
    "@angular/material": "^17.0.0",
    "@angular/material-moment-adapter": "^17.0.0",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "js-sha256": "^0.10.1",
    "ngx-cookie-service": "^17.0.0",
    "express": "^4.18.2",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^17.0.0",
    "@angular/cli": "^17.0.0",
    "@angular/compiler-cli": "^17.0.0",
    "@types/express": "^4.17.17",
    "@types/jasmine": "~5.1.0",
    "@types/node": "^18.18.0",
    "jasmine-core": "~5.1.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.2.2"
  }
}

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecore: hydrationneeds reproductionThis issue needs a reproduction in order for the team to investigate further

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0