Skip to content

Non-GET requests to existing /_next/static - #142

Open
ivan-flamingo wants to merge 9 commits into
mainfrom
hotfix/permanent-lab
Open

Non-GET requests to existing /_next/static#142
ivan-flamingo wants to merge 9 commits into
mainfrom
hotfix/permanent-lab

Conversation

@ivan-flamingo

@ivan-flamingo ivan-flamingo commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Corrected responses for unsupported requests to existing static files, returning HTTP 405 instead of 500.
    • Improved device-count retrieval reliability with graceful fallbacks when requests fail.
  • Performance

    • Dashboard device metrics now load organization data and status counts concurrently.
    • Reduced redundant count requests while preserving total, online, and offline metrics.
    • Improved accuracy of device counts by separating status and organization-level metrics.

@ivan-flamingo ivan-flamingo self-assigned this Aug 7, 2026
@ivan-flamingo
ivan-flamingo requested review from a team as code owners August 7, 2026 07:27
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR separates device status and organization count queries, updates dashboard consumers, and adds a Docker entrypoint that converts matching Next.js static-file responses from HTTP 500 to HTTP 405.

Changes

Device count query separation

Layer / File(s) Summary
Device count contracts and queries
src/app/(app)/devices/queries/devices-api.ts, src/app/(app)/devices/queries/devices-queries.ts
The combined count contract and GraphQL query are replaced with separate status-count and organization-count APIs.
Dashboard count consumers
src/app/(app)/customers/hooks/use-customer-device-counts.ts, src/app/(app)/dashboard/hooks/use-customers-overview.ts, src/app/(app)/dashboard/services/dashboard-api-service.ts
Consumers use the separated APIs. The overview fetches organizations and status counts concurrently and derives totals from active and inactive counts.

HTTP static-file method handling

Layer / File(s) Summary
HTTP response repair entrypoint
Dockerfile, scripts/server-entry.js
The image starts through server-entry.js, which wraps HTTP responses, converts matching 500 responses with an Allow header to 405, and then loads server.js.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Dashboard
  participant DeviceAPI
  participant GraphQL
  Dashboard->>DeviceAPI: request status and organization counts
  DeviceAPI->>GraphQL: execute separate count queries
  GraphQL-->>DeviceAPI: return count maps
  DeviceAPI-->>Dashboard: return typed results
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main Docker and server-entrypoint change for non-GET requests to existing static files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/permanent-lab

Comment @coderabbitai help to get the list of available commands.

@romanivan-flamingo

Copy link
Copy Markdown
Contributor

FE review note: the doc comment has one factual inaccuracy - the paragraph claiming direct navigation to /405 is redirected by src/proxy.ts. isAllowed is a mode gate, not a page allowlist: in oss-tenant it returns true for every path, and in saas-tenant for everything outside /auth, so the shim page is reachable by URL. Suggested replacement for that paragraph:

 * Direct navigation to /405 is NOT blocked by `src/proxy.ts`: `isAllowed` is a
 * mode gate, not a page allowlist - in `oss-tenant` it returns true for every
 * path, in `saas-tenant` for everything outside `/auth`, so the shim is
 * reachable by URL and renders as a bare 200 page. That is cosmetic only -
 * nothing links to it. The proxy deliberately does not run on the internal
 * status-page render (`invokeRender` sets `middlewareInvoke: false`), so
 * blocking /405 in the proxy would not break the 405 path if we ever want to
 * hide it.

Everything else checks out against Next 16.2.4 sources (router-server.js 405 -> invokeRender('/405'), WrappedBuildError('missing required error components') in base-server.js, middlewareInvoke: false on internal renders).

…cted

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/`(app)/dashboard/hooks/use-customers-overview.ts:
- Around line 100-108: Preserve failures in fetchOrganizations and
fetchCustomersOverview instead of returning null or swallowing caught errors, so
failed requests are distinguishable from an empty customer state. Update the
owning overview hook to use useToast and show feedback for both successful
queries and errors, while retaining normal rendering for valid empty results.

In `@src/app/`(app)/devices/queries/devices-queries.ts:
- Around line 43-65: Replace the raw device-count and organization-list GraphQL
POST flows with narrow Relay operations: update
src/app/(app)/devices/queries/devices-queries.ts lines 43-65 to define
source-file-prefixed Relay queries, update
src/app/(app)/devices/queries/devices-api.ts lines 174-197 to use fetchQuery for
the imperative callers, and update
src/app/(app)/dashboard/hooks/use-customers-overview.ts lines 91-98 to use the
generated Relay operation; then run the Relay compiler.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d6be053-ecec-457c-9011-67de3b96dc3f

📥 Commits

Reviewing files that changed from the base of the PR and between f396fe6 and a145da0.

📒 Files selected for processing (7)
  • Dockerfile
  • scripts/server-entry.js
  • src/app/(app)/customers/hooks/use-customer-device-counts.ts
  • src/app/(app)/dashboard/hooks/use-customers-overview.ts
  • src/app/(app)/dashboard/services/dashboard-api-service.ts
  • src/app/(app)/devices/queries/devices-api.ts
  • src/app/(app)/devices/queries/devices-queries.ts

Comment on lines +100 to +108
if (!orgsResponse.ok) {
console.warn('Organizations overview API failed:', orgsResponse.error || orgsResponse.status);
return null;
}

const orgsData = orgsResponse.data?.data?.organizations;
if (!orgsData) {
console.warn('Invalid organizations overview response structure');
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline 'src/app/(app)/dashboard/hooks/use-customers-overview.ts' --items all
rg -n -C 3 --type ts '\b(useToast|useQuery|fetchCustomersOverview)\b' \
  'src/app/(app)/dashboard/hooks/use-customers-overview.ts'

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 2196


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- hook implementation ---'
sed -n '80,230p' 'src/app/(app)/dashboard/hooks/use-customers-overview.ts'

printf '%s\n' '--- hook consumers ---'
rg -n -C 5 --type tsx 'useCustomersOverview|totalOrganizations|organizationOverview' 'src/app/(app)/dashboard'

printf '%s\n' '--- toast patterns in nearby hooks ---'
rg -n -C 4 --type ts '\buseToast\b' 'src/app/(app)/dashboard' 'src/app/(app)/devices' | head -240

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 5019


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- dashboard consumers ---'
rg -n -C 6 'useCustomersOverview|totalOrganizations|rows\.length|No Customers added yet' 'src/app/(app)/dashboard' --glob '*.tsx' --glob '*.ts' || true

printf '%s\n' '--- toast API and nearby usage ---'
rg -n -C 5 '\buseToast\b' src --glob '*.tsx' --glob '*.ts' | head -300

printf '%s\n' '--- query error handling patterns ---'
rg -n -C 6 'query\.isError|query\.error|onError|onSuccess' 'src/app/(app)/dashboard' --glob '*.tsx' --glob '*.ts' | head -300

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 42976


Preserve organization fetch errors. Throw or expose an error when fetchOrganizations() returns null or fetchCustomersOverview() catches a failure. Otherwise, the consumer renders “No Customers added yet” for failed requests. Add useToast feedback for query success and errors in the owning hook.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/`(app)/dashboard/hooks/use-customers-overview.ts around lines 100 -
108, Preserve failures in fetchOrganizations and fetchCustomersOverview instead
of returning null or swallowing caught errors, so failed requests are
distinguishable from an empty customer state. Update the owning overview hook to
use useToast and show feedback for both successful queries and errors, while
retaining normal rendering for valid empty results.

Source: Coding guidelines

Comment on lines +43 to 65
export const GET_DEVICE_STATUS_COUNTS_QUERY = `
query GetDeviceStatusCounts($filter: DeviceFilterInput) {
deviceFilters(filter: $filter) {
statuses {
value
count
}
filteredCount
}
}
`;

/** Per-organization device counts — the customers table and the dashboard overview. */
export const GET_DEVICE_ORGANIZATION_COUNTS_QUERY = `
query GetDeviceOrganizationCounts($filter: DeviceFilterInput) {
deviceFilters(filter: $filter) {
organizationIds {
value
count
}
filteredCount
}
}
`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 --type ts \
  '\b(postDeviceQuery|apiClient\.post|fetchQuery|useLazyLoadQuery|loadQuery)\b|GET_DEVICE_(STATUS|ORGANIZATION)_COUNTS_QUERY' \
  'src/app/(app)/devices/queries/devices-api.ts' \
  'src/app/(app)/devices/queries/devices-queries.ts' \
  'src/app/(app)/dashboard/hooks/use-customers-overview.ts'

rg -n -C 3 --type ts 'graphql`|graphql\s*`|fetchQuery<' 'src/app'

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 50393


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- focused diff ---'
git diff --unified=25 -- \
  'src/app/(app)/devices/queries/devices-queries.ts' \
  'src/app/(app)/devices/queries/devices-api.ts' \
  'src/app/(app)/dashboard/hooks/use-customers-overview.ts'

printf '%s\n' '--- devices-api imports and count callers ---'
sed -n '1,230p' 'src/app/(app)/devices/queries/devices-api.ts'
rg -n -C 5 --type ts \
  'fetchDeviceStatusCounts|fetchDeviceOrganizationCounts|fetchOrganizations|GET_ORGANIZATIONS_QUERY|deviceFiltersRelayQuery|organization.*Relay|organizations.*graphql' \
  'src/app' 'src/graphql' 'src/__generated__'

printf '%s\n' '--- customers overview ---'
sed -n '1,180p' 'src/app/(app)/dashboard/hooks/use-customers-overview.ts'

printf '%s\n' '--- Relay configuration and scripts ---'
rg -n -C 3 \
  'relay|compiler|codegen' \
  package.json relay.config.* '*.config.*' 2>/dev/null || true

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 36526


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- existing device Relay facet ---'
sed -n '1,180p' 'src/graphql/devices/device-filters-relay.ts'
printf '%s\n' '--- device query documents ---'
sed -n '1,120p' 'src/app/(app)/devices/queries/devices-queries.ts'

printf '%s\n' '--- organization Relay documents and generated types ---'
rg -l --type tsx --type ts 'organizations\s*\(' 'src/graphql' 'src/app' | sort
rg -n -C 8 --type tsx --type ts \
  'query [A-Za-z0-9_]*Organization|organizations\s*\(|Organization.*Query' \
  'src/graphql' 'src/app/(app)' | head -n 240

printf '%s\n' '--- cited endpoint/document structural check ---'
python3 - <<'PY'
from pathlib import Path
files = [
    Path('src/app/(app)/devices/queries/devices-api.ts'),
    Path('src/app/(app)/dashboard/hooks/use-customers-overview.ts'),
]
for path in files:
    text = path.read_text()
    print(path)
    for needle in ("apiClient.post", "postDeviceQuery", "graphql`", "/api/graphql", "GET_DEVICE_STATUS_COUNTS_QUERY",
                   "GET_DEVICE_ORGANIZATION_COUNTS_QUERY", "GET_ORGANIZATIONS_QUERY"):
        print(f"  {needle}: {text.count(needle)}")
PY

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 4361


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- organization GraphQL documents ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
  'graphql`|query [A-Za-z0-9_]*Organization|organizations\s*\(' \
  src/graphql 'src/app/(app)' | head -n 320

printf '%s\n' '--- generated organization query artifacts ---'
find src/__generated__ -maxdepth 1 -type f -iname '*organization*' -printf '%f\n' | sort | head -n 120
rg -n -C 3 --glob '*.ts' \
  'Organizations|organizations|OrganizationConnection' src/__generated__ | head -n 240

printf '%s\n' '--- Relay configuration and repository state ---'
find . -maxdepth 2 -type f \( -iname '*relay*config*' -o -name 'relay.config.js' -o -name 'relay.config.json' \) -print
git status --short

Repository: flamingo-stack/openframe-oss-frontend

Length of output: 27577


Use Relay for the new /api/graphql operations.

Replace the raw device-count and organization-list POST calls with narrow, source-file-prefixed Relay operations. Use fetchQuery for these imperative callers and run the Relay compiler.

📍 Affects 3 files
  • src/app/(app)/devices/queries/devices-queries.ts#L43-L65 (this comment)
  • src/app/(app)/devices/queries/devices-api.ts#L174-L197
  • src/app/(app)/dashboard/hooks/use-customers-overview.ts#L91-L98
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/`(app)/devices/queries/devices-queries.ts around lines 43 - 65,
Replace the raw device-count and organization-list GraphQL POST flows with
narrow Relay operations: update src/app/(app)/devices/queries/devices-queries.ts
lines 43-65 to define source-file-prefixed Relay queries, update
src/app/(app)/devices/queries/devices-api.ts lines 174-197 to use fetchQuery for
the imperative callers, and update
src/app/(app)/dashboard/hooks/use-customers-overview.ts lines 91-98 to use the
generated Relay operation; then run the Relay compiler.

Source: Coding guidelines

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