93 static pages and not found behavior#97
Open
amadulhaxxani wants to merge 7 commits intoclarin-v7from
Open
Conversation
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.
There was a problem hiding this comment.
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
HtmlContentServicewith HTTP response handling, cache-busting, and English fallback for missing localized content - Added
contentStateproperty toStaticPageComponentto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
/static/not_there) did not render a proper 404 page..htmlfile existed.cs) content was missing, the system did not reliably fall back to English (en).Key Changes
1. Error Handling & Fallback Logic
Refactored
HtmlContentServiceto:404and304statuses.Simplified and hardened error handling logic in the service.
Files affected:
src/app/shared/html-content.service.ts2. Static Page Component Behavior
Introduced a
contentStateproperty ('loading' | 'found' | 'not-found') to explicitly track content lifecycle.Updated the component to:
This ensures consistent behavior between client-side rendering and SSR.
Files affected:
src/app/static-page/static-page.component.ts3. User Interface Improvements
Updated the static page template to:
Added missing translation keys for the static page 404 message in both languages.
Files affected:
src/app/static-page/static-page.component.htmlsrc/assets/i18n/en.json5src/assets/i18n/cs.json54. Test Coverage
Added unit tests for
HtmlContentServiceto cover:Expanded tests for the static page component to verify:
contentStatetransitionsFiles affected:
src/app/shared/html-content.service.spec.tssrc/app/static-page/static-page.component.spec.tsOutcome