Skip to content

ZCU-DATA/fix(static-page): return HTTP 404 for missing static pages - #1461

Merged
milanmajchrak merged 2 commits into
customer/zcu-datafrom
zcu-data/fix-static-page-404
Aug 19, 2026
Merged

ZCU-DATA/fix(static-page): return HTTP 404 for missing static pages#1461
milanmajchrak merged 2 commits into
customer/zcu-datafrom
zcu-data/fix-static-page-404

Conversation

@Kasinhou

@Kasinhou Kasinhou commented Aug 18, 2026

Copy link
Copy Markdown

Problem

/static/<missing> answered HTTP 200 with an empty shell instead of a 404 page. StaticPageComponent tried to load static-files/error.html and, when that was empty/missing, rendered nothing and never set a 404 status. UNIVERSAL-016 (dspace-ui-tests notFoundPage.spec.tsnon-existent static page shows 404 page) failed on this instance, while dtq-dev returns a proper 404.

Fix

  • Set the SSR response to 404 via ServerResponseService.setNotFound() when the static file is not found.
  • Render the inline 404 page (same markup + reused 404.* i18n keys as PageNotFoundComponent) via a contentState (loading / found / not-found).
  • Drop the legacy error.html loading path.
  • Update the unit spec (provide 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 AOT ng build (development) on the sav branch (identical change across all four customers).
566-zcu-data-static-404

Refs dataquest-dev/dspace-customers#566

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/app/static-page/static-page.component.ts
Comment thread src/app/static-page/static-page.component.spec.ts
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>
@Kasinhou
Kasinhou requested a review from milanmajchrak August 19, 2026 12:38
@milanmajchrak
milanmajchrak merged commit b38e05b into customer/zcu-data Aug 19, 2026
3 of 5 checks passed
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.

3 participants