Skip to content

93 static pages and not found behavior#97

Open
amadulhaxxani wants to merge 7 commits intoclarin-v7from
93-static-pages-and-not-found-behavior
Open

93 static pages and not found behavior#97
amadulhaxxani wants to merge 7 commits intoclarin-v7from
93-static-pages-and-not-found-behavior

Conversation

@amadulhaxxani
Copy link

This pull request improves the behavior of static HTML page loading and “page not found” handling. It introduces a reliable fallback mechanism for localized content, ensures correct 404 behavior when content is missing, and strengthens test coverage around these changes.

The result is more predictable static page behavior, clearer user-facing errors, and better confidence through targeted tests.


Problem Statement

Previously, static pages had inconsistent behavior:

  • Missing static pages (e.g. /static/not_there) did not render a proper 404 page.
  • Language switching behaved differently depending on whether a .html file existed.
  • When Czech (cs) content was missing, the system did not reliably fall back to English (en).
  • Error handling and cache behavior were fragile and difficult to reason about.

Key Changes

1. Error Handling & Fallback Logic

  • Refactored HtmlContentService to:

    • Fetch HTML files using full HTTP responses, allowing proper handling of 404 and 304 statuses.
    • Introduce a cache-busting mechanism to prevent stale HTML content.
    • Implement a robust fallback strategy: if a localized file is missing, the service automatically attempts to load the English version instead.
  • Simplified and hardened error handling logic in the service.

Files affected:

  • src/app/shared/html-content.service.ts

2. Static Page Component Behavior

  • Introduced a contentState property ('loading' | 'found' | 'not-found') to explicitly track content lifecycle.

  • Updated the component to:

    • Set a proper 404 server response when content is not found.
    • Remove legacy error-page loading logic.
  • This ensures consistent behavior between client-side rendering and SSR.

Files affected:

  • src/app/static-page/static-page.component.ts

3. User Interface Improvements

  • Updated the static page template to:

    • Render content only when it is successfully found.
    • Display a custom, user-friendly 404 section (localized text + home navigation) when content is missing.
  • Added missing translation keys for the static page 404 message in both languages.

Files affected:

  • src/app/static-page/static-page.component.html
  • src/assets/i18n/en.json5
  • src/assets/i18n/cs.json5

4. Test Coverage

  • Added unit tests for HtmlContentService to cover:

    • Localization fallback logic
    • Cache-busting behavior
    • HTTP response handling
  • Expanded tests for the static page component to verify:

    • contentState transitions
    • Correct 404 handling
    • Proper triggering of change detection

Files affected:

  • src/app/shared/html-content.service.spec.ts
  • src/app/static-page/static-page.component.spec.ts

Outcome

  • Static pages now behave consistently across languages.
  • Missing content results in a correct and user-friendly 404 experience.
  • Localized content reliably falls back to English when necessary.
  • The new logic is covered by focused, meaningful unit tests.

Updated StaticPageComponent to display an inline 404 error message when a static page is not found, matching the PageNotFoundComponent design. Added translations for the new 404 messages in both English and Czech, and set the server response status to 404 for SSR. Removed legacy error page loading logic and updated tests to mock the new ServerResponseService dependency.
Refactors static page loading to use a new contentState property ('loading', 'found', 'not-found') for clearer UI state management and error handling. Enhances HtmlContentService with cache-busting and robust fallback logic for localized HTML content. Updates tests and template to reflect new state handling and ensures change detection is triggered after content load or error.
Copilot AI review requested due to automatic review settings January 30, 2026 15:46
@amadulhaxxani amadulhaxxani linked an issue Jan 30, 2026 that may be closed by this pull request
@amadulhaxxani amadulhaxxani requested a review from kosarko January 30, 2026 15:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves static HTML page loading and 404 handling by introducing a content state management system, localized fallback mechanism, and user-friendly error displays. The changes ensure missing static pages properly return 404 responses for SSR and display custom error messages.

Changes:

  • Enhanced HtmlContentService with HTTP response handling, cache-busting, and English fallback for missing localized content
  • Added contentState property to StaticPageComponent to track content lifecycle ('loading' | 'found' | 'not-found')
  • Implemented inline 404 error display in the static page template matching the design of PageNotFoundComponent
  • Added comprehensive unit tests for the service's fallback mechanism and component's state transitions
  • Added localized translation keys for static page 404 messages in English and Czech

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/assets/i18n/en.json5 Added English translation keys for static page 404 error messages
src/assets/i18n/cs.json5 Added Czech translation keys for static page 404 error messages
src/app/static-page/static-page.component.ts Introduced contentState tracking, ServerResponseService integration for 404 status, removed legacy error page loading, added ChangeDetectorRef
src/app/static-page/static-page.component.html Added conditional rendering based on contentState with inline 404 error display
src/app/shared/html-content.service.ts Refactored to return full HTTP responses, added cache-busting mechanism, implemented robust localized-to-English fallback logic
src/app/shared/html-content.service.spec.ts Added new test suite covering fallback mechanism for different locales and 404 scenarios
src/app/static-page/static-page.component.spec.ts Added tests for contentState transitions and change detection behavior

Replace bracket-indexing (component['changeDetector']) with (component as any).changeDetector in static-page.component.spec.ts. This updates three occurrences in the change-detection tests so TypeScript accepts spying on detectChanges without index-signature errors.
Use a deterministic cache-bust parameter in HtmlContentService.appendCacheBust (avoid Date.now()) and avoid adding the param if it already exists — this keeps the behavior SSR-safe and cache-friendly. Refactor StaticPageComponent unit tests: allow setupTest to accept undefined HTML, return the mocked responseService, and simplify tests by reusing setupTest to remove duplicated test setup code.
Show a loading spinner while static page content is fetched and add console.error logging on load failures (includes fileName and URL) to aid debugging. Also simplify HtmlContentService by removing a redundant refetch-on-empty response path that caused an extra network request and special-case 404 handling; a 200 now consistently returns the response body (or empty string). UI behavior for not-found responses remains unchanged.
Replace the fixed cache-bust value ('1') with a dynamic hourly value computed from Date.now()/3600000. This appends a changing query parameter so responses are refreshed hourly (reducing stale content) while keeping the existing query-separator logic intact. Removed the prior comment about a deterministic SSR-safe value.
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.

Static pages and not found behavior

1 participant