mcpField
A
angular-ssr

angular-ssr

github.com/oguzhan18Development7168 installsUpdated 31w ago
Repository

About angular-ssr

A reference skill for Angular 21 server-side rendering, hydration, and prerendering. It guides Angular developers through current setup patterns and route-level hybrid rendering options.

Key features

  1. 01SSR setup with Angular CLI
  2. 02Client and incremental hydration
  3. 03Hybrid rendering by route
  4. 04Lazy loading with @defer
  5. 05Browser/server platform checks
  6. 06TransferState request reuse

Use cases

  1. 01Adding SSR to an Angular app
  2. 02Configuring incremental hydration
  3. 03Choosing rendering modes per route

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-ssr

After installing, type/angular-ssrin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/discussions/
_INDEX.md
references/docs/
_INDEX.md
references/issues/
_INDEX.md
references/releases/
_INDEX.md

Details

From the project README

@angular/ssr (Server-Side Rendering)

Version: Angular 21 (2025) Tags: SSR, Hydration, Prerendering, SEO, Angular Universal

References: SSR Guide • Hydration • @angular/ssr

API Changes

This section documents recent version-specific API changes.

  • NEW: Incremental Hydration — Hydrate components incrementally instead of all at once source

  • NEW: Hybrid Rendering — Per-route rendering mode configuration source

  • NEW: provideClientHydration — Modern hydration setup with event replay

  • NEW: Deferrable views (@defer) — Load components lazily with SSR support

  • NEW: ngSkipHydration — Opt-out of hydration for specific components

  • DEPRECATED: Angular Universal — Migrate to @angular/ssr

Best Practices

  • Enable SSR with CLI
ng add @angular/ssr

# Or create new project with SSR
ng new my-app --ssr
  • Enable client hydration
import { provideClientHydration } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
  providers: [
    provideClientHydration()
  ]
};
  • Use incremental hydration for better performance
import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
  providers: [
    provideClientHydration(withIncrementalHydration())
  ]
};
  • Use @defer for lazy loading
@Component({
  template: `
    @defer (on viewport) {
      <heavy-component />
    } @placeholder {
      <div>Loading...</div>
    }
  `
})
export class MainComponent {}
  • Handle browser-specific code with isPlatformBrowser
import { PLATFORM_ID, Inject } from '@angular/core';

constructor(@Inject(PLATFORM_ID) private platformId: Object) {
  if (isPlatformBrowser(this.platformId)) {
    // Browser-only code
  }
}
  • Use TransferState to prevent duplicate HTTP requests
import { TransferState, makeStateKey } from '@angular/platform-browser';

@Injectable()
export class DataService {
  constructor(private http: HttpClient, private transferState: TransferState) {}

  getData() {
    const DATA_KEY = makeStateKey('DATA');
    
    if (this.transferState.hasKey(DATA_KEY)) {
      return of(this.transferState.get(DATA_KEY, []));
    }
    
    return this.http.get('/api/data').pipe(
      tap(data => this.transferState.set(DATA_KEY, data))
    );
  }
}
  • Skip hydration for DOM-manipulating components
@Component({
  selector: 'app-third-party',
  host: {
    'ngSkipHydration': 'true'
  }
})
export class ThirdPartyComponent {}
  • Configure hybrid rendering per route
import { RenderMode, ServerRoute } from '@angular/ssr';

export const serverRoutes: ServerRoute[] = [
  {
    path: 'dashboard',
    renderMode: RenderMode.Client
  },
  {
    path: 'blog/:slug',
    renderMode: RenderMode.Server
  },
  {
    path: 'about',
    renderMode: RenderMode.Prerender
  }
];
  • Use platform-server for server-side logic
import { isPlatformServer } from '@angular/common';

constructor(@Inject(PLATFORM_ID) platformId: Object) {
  if (isPlatformServer(platformId)) {
    // Server-side only
  }
}

Comments

Markdown supported