Skip to content

Conversation

@danigrim
Copy link

@danigrim danigrim commented Nov 18, 2025

Add Firebase SDK realtime updates and Server-Side Rendering

Summary

This PR implements the two improvements identified in the README (lines 67-70):

  1. Firebase SDK Integration: Adds realtime updates using the official Hacker News Firebase API with a settings toggle to switch between Firebase SDK and REST endpoints
  2. Server-Side Rendering: Implements Angular Universal for SSR to improve initial load performance and SEO

Phase 1: Firebase SDK Integration

  • Installed @angular/fire@6.1.5 and firebase@8.10.1 (compatible with Angular 9)
  • Created FirebaseAPIService that connects to https://hacker-news.firebaseio.com/v0/ with realtime listeners
  • Added APIService abstraction layer that switches between HackerNewsAPIService (REST) and FirebaseAPIService based on settings.useFirebaseSDK
  • Updated all components (FeedComponent, ItemDetailsComponent, UserComponent) to use APIService
  • Added settings toggle UI in the settings panel under "Data Source" section
  • Toggle persists to localStorage and dynamically switches data source
  • Comprehensive unit tests for Firebase service, API service, and settings toggle

Phase 2: Server-Side Rendering

  • Installed Angular Universal dependencies (@angular/platform-server, @nguniversal/express-engine)
  • Created app.server.module.ts, main.server.ts, and tsconfig.server.json
  • Added server build configuration to angular.json
  • Created Express server (server.ts) for SSR
  • Wrapped browser-specific code in SettingsService with isPlatformBrowser checks
  • Unit tests for SSR compatibility

Testing Performed

  • ✅ Manually tested Firebase SDK toggle UI - checkbox appears in settings and persists to localStorage
  • ✅ Verified app loads and displays Hacker News feed correctly
  • ✅ Lint checks pass for modified files
  • ⚠️ Build and unit tests failed locally due to Node.js 24 vs Angular 9/webpack compatibility (requires Node 10-14)
  • ⚠️ Snyk security check failing (needs investigation)

Review & Testing Checklist for Human

🔴 Critical Issues to Address:

  • Remove package-lock.json - This repo uses Yarn (yarn.lock exists). The addition of package-lock.json is causing CI/Snyk inconsistencies. Run rm package-lock.json and use yarn exclusively.
  • Investigate Snyk security failure - Check if it's related to vulnerable dependencies in firebase@8.10.1 or @angular/fire@6.1.5, or just the dual package manager issue.
  • Test SSR build - Run ng build --prod && ng run angular-hnpwa:server:production to verify server build works.
  • Test Firebase SDK data fetching - Toggle Firebase SDK on in settings, navigate to different feeds, and verify data loads correctly from Firebase API.
  • Test service worker compatibility - Verify service worker still caches REST endpoints when Firebase SDK is disabled (per README requirement).

🟡 Important Verification:

  • Run unit tests in proper Node environment (Node 10-14) to verify all tests pass
  • Test realtime updates - With Firebase SDK enabled, check if feed updates automatically when new stories are posted
  • Test offline functionality in both modes
  • Verify no console errors in browser when toggling between modes

Test Plan:

  1. Install dependencies with yarn install (not npm)
  2. Start app with export NODE_OPTIONS=--openssl-legacy-provider && yarn start
  3. Open settings and toggle "Use Firebase SDK (realtime updates)" on/off
  4. Navigate between different feeds (news, newest, show, ask, jobs) in both modes
  5. Check browser DevTools Network tab to verify correct API is being called
  6. Test offline mode with service worker in both REST and Firebase modes

Notes

  • Video recording of local testing: Testing Firebase SDK Toggle

View original video (recording-aa207fe0-a7b8-4ddb-9f09-6d893a4824f4-edited.mp4)

  • The Firebase SDK uses the official Hacker News Firebase API which provides realtime updates via listeners
  • When Firebase SDK is disabled, the app falls back to the existing REST API (https://node-hnapi.herokuapp.com)
  • SSR configuration is in place but needs testing in a proper Node environment
  • All browser-specific code (localStorage, window.matchMedia) is wrapped with isPlatformBrowser checks for SSR compatibility

Link to Devin run: https://app.devin.ai/sessions/d574293cf433481faf5aab3fbf7bf214
Requested by: Daniella Grimberg (daniella.grimberg@cognition.ai) / @danigrim

Phase 1: Firebase SDK Integration
- Install @angular/fire and firebase dependencies
- Add Firebase configuration to environment files
- Create FirebaseAPIService with realtime listeners for Hacker News data
- Add settings toggle for Firebase SDK vs REST mode
- Create APIService abstraction layer to switch between services
- Update all components to use APIService
- Add comprehensive unit tests for Firebase service and settings toggle

Phase 2: Server-Side Rendering
- Install Angular Universal dependencies
- Create app.server.module.ts and main.server.ts
- Add server build configuration to angular.json
- Create Express server for SSR
- Wrap browser-specific code with platform checks in SettingsService
- Add unit tests for SSR compatibility

Both improvements maintain backward compatibility and existing functionality.

Co-Authored-By: Daniella Grimberg <daniella@cognition.ai>
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Add toggleFirebaseSDK() method to SettingsComponent
- Add Data Source section with Firebase SDK checkbox to settings template
- Users can now toggle between REST API and Firebase SDK realtime updates
- Toggle persists to localStorage and switches data source dynamically

Co-Authored-By: Daniella Grimberg <daniella@cognition.ai>
@devin-ai-integration devin-ai-integration bot changed the title Add Firebase SDK Integration and Server-Side Rendering Support Add Firebase SDK realtime updates and Server-Side Rendering Nov 18, 2025
This repo uses Yarn (yarn.lock exists). The package-lock.json was
accidentally created during npm package installation and is causing
Snyk to analyze a different dependency graph than intended.

Co-Authored-By: Daniella Grimberg <daniella@cognition.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants