ZCU-DATA/fix(static-page): return HTTP 404 for missing static pages - #1461
Merged
Conversation
StaticPageComponent rendered an empty shell and answered HTTP 200 when a `/static/<file>` page did not exist: it tried to load `static-files/error.html` and, when that was empty/missing, showed nothing and never set a 404 status. UNIVERSAL-016 (dspace-ui-tests notFoundPage.spec.ts) therefore failed on the "non-existent static page shows 404 page" case. Set the SSR response to 404 via ServerResponseService and render the inline 404 page (same markup + reused `404.*` i18n keys as PageNotFoundComponent) when the content is not found. Drop the legacy error.html loading path. Behaviour now matches dtq-dev: /static/<missing> returns 404 with the "404 / Take me to the home page" page. Refs dataquest-dev/dspace-customers#566 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes incorrect handling of missing static pages under /static/<missing> by ensuring SSR responses return HTTP 404 and the UI renders an inline “page not found” view instead of an empty shell.
Changes:
- Add SSR-aware 404 handling for missing static pages via
ServerResponseService.setNotFound(). - Introduce a simple
contentState(loading/found/not-found) to control rendering of spinner, static content, or inline 404 markup. - Update unit tests to cover the not-found path and provide the SSR response service dependency.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/app/static-page/static-page.component.ts | Adds SSR 404 signaling + contentState to render an inline not-found view when content is missing. |
| src/app/static-page/static-page.component.spec.ts | Adds ServerResponseService spy and a not-found test case for the new behavior. |
| src/app/static-page/static-page.component.html | Renders loading spinner, static content, or inline 404 page based on contentState. |
Suppressed comments (3)
src/app/static-page/static-page.component.ts:65
- Calling ChangeDetectorRef.detectChanges() after an async fetch can throw if the component is destroyed before the request resolves (e.g., fast navigation away), and it’s usually unnecessary because Angular change detection will run on async completion. At minimum, guard the call against a destroyed view (or remove the explicit detectChanges usage entirely).
this.changeDetector.detectChanges();
src/app/static-page/static-page.component.spec.ts:83
- This spec calls ngOnInit() directly. Since the component now triggers its own change detection, manually calling lifecycle hooks can lead to double-initialization and makes the test less representative. Prefer letting Angular run ngOnInit via fixture.detectChanges() and awaiting stability.
htmlContentService.fetchHtmlContent.and.returnValue(of(''));
await component.ngOnInit();
expect(responseService.setNotFound).toHaveBeenCalled();
src/app/static-page/static-page.component.ts:72
- Calling ChangeDetectorRef.detectChanges() after an async fetch can throw if the component is destroyed before the request resolves (e.g., fast navigation away), and it’s usually unnecessary because Angular change detection will run on async completion. At minimum, guard the call against a destroyed view (or remove the explicit detectChanges usage entirely).
this.changeDetector.detectChanges();
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use jasmine.SpyObj<HtmlContentService> instead of `any` for the test spy, per Copilot review. Refs dataquest-dev/dspace-customers#566 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
/static/<missing>answered HTTP 200 with an empty shell instead of a 404 page.StaticPageComponenttried to loadstatic-files/error.htmland, when that was empty/missing, rendered nothing and never set a 404 status. UNIVERSAL-016 (dspace-ui-testsnotFoundPage.spec.ts→ non-existent static page shows 404 page) failed on this instance, while dtq-dev returns a proper 404.Fix
ServerResponseService.setNotFound()when the static file is not found.404.*i18n keys asPageNotFoundComponent) via acontentState(loading/found/not-found).error.htmlloading path.ServerResponseService, add a not-found test).Mirrors the verified dtq-dev fix (
f8495ea85c) on the same Angular 15 base.Result
/static/<missing>now returns HTTP 404 with the "404 / Take me to the home page" page — matching dtq-dev. Verified locally with an AOTng build(development) on thesavbranch (identical change across all four customers).Refs dataquest-dev/dspace-customers#566
🤖 Generated with Claude Code