Skip to content

Commit 7e7f46b

Browse files
authored
Merge pull request #3740 from IgniteUI/simeonoff/fix-calendar-samples-vnext
fix(calendar): samples do not work in SSR mode
2 parents 6dfefcb + 99ae510 commit 7e7f46b

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/app/app.config.server.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import { provideServerRendering, withRoutes } from '@angular/ssr';
2-
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
3-
import { AppConfig } from './app.config';
4-
import { serverRoutes } from './app.routes.server';
1+
import { provideServerRendering, withRoutes } from "@angular/ssr";
2+
import { mergeApplicationConfig, ApplicationConfig } from "@angular/core";
3+
import { AppConfig } from "./app.config";
4+
import { serverRoutes } from "./app.routes.server";
5+
import { provideClientHydration } from "@angular/platform-browser";
6+
import { provideHttpClient, withFetch } from "@angular/common/http";
57

68
const serverConfig: ApplicationConfig = {
7-
providers: [provideServerRendering(withRoutes(serverRoutes))]
9+
providers: [
10+
provideServerRendering(withRoutes(serverRoutes)),
11+
provideClientHydration(),
12+
provideHttpClient(withFetch())
13+
]
814
};
915

1016
export const config = mergeApplicationConfig(AppConfig, serverConfig);

src/app/app.routes.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ export const serverRoutes: ServerRoute[] = [
5959
},
6060
{
6161
path: 'scheduling/**',
62-
renderMode: RenderMode.Prerender
62+
renderMode: RenderMode.Client // TODO: Calendar components have SSR hydration issues
6363
},
6464
{
6565
path: 'samples/scheduling/**',
66-
renderMode: RenderMode.Prerender
66+
renderMode: RenderMode.Client // TODO: Calendar components have SSR hydration issues
6767
},
6868
{
6969
path: 'menus/**',

src/app/index/index.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild, DOCUMENT, inject } from '@angular/core';
1+
import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild, DOCUMENT, PLATFORM_ID, inject } from '@angular/core';
22
import { NavigationStart, Route, Router, RouterLinkActive, RouterLink, RouterOutlet } from '@angular/router';
33
import { IgxNavigationDrawerComponent, IgxTreeComponent, IgxLayoutDirective, IgxNavDrawerTemplateDirective, IgxNavDrawerItemDirective, IgxRippleDirective, IgxIconComponent, IgxInputGroupComponent, IgxPrefixDirective, IgxInputDirective, IgxSuffixDirective, IgxTreeNodeComponent, IgxTreeNodeLinkDirective, IgxFlexDirective, IgxNavbarComponent } from 'igniteui-angular';
44
import { fromEvent, Subscription } from 'rxjs';
@@ -19,6 +19,7 @@ import { servicesRoutesData } from '../services/services-routes-data';
1919
import { themingRoutesData } from '../theming/theming-routes-data';
2020
import { treeGridRoutesData } from '../tree-grid/tree-grid-routes-data';
2121
import { FormsModule } from '@angular/forms';
22+
import { isPlatformBrowser } from '@angular/common';
2223

2324

2425

@@ -32,6 +33,7 @@ export class IndexComponent implements OnInit, AfterViewInit {
3233
private router = inject(Router);
3334
private cdr = inject(ChangeDetectorRef);
3435
private document = inject<Document>(DOCUMENT);
36+
private platformId = inject(PLATFORM_ID);
3537

3638

3739
@ViewChild('navdrawer', { read: IgxNavigationDrawerComponent, static: true })
@@ -168,7 +170,7 @@ export class IndexComponent implements OnInit, AfterViewInit {
168170
const loadedRouteItem = this.appRoutes.filter(
169171
(route: any) => route.path === this.router.url)[0];
170172

171-
if (loadedRouteItem) {
173+
if (loadedRouteItem && isPlatformBrowser((this.platformId))) {
172174
// Get parent (INavItem)
173175
const loadedParentItem = this.currentNavItems.filter(
174176
(navItem) => navItem.name === loadedRouteItem.parentName)[0];

0 commit comments

Comments
 (0)