Skip to content

Mount i18n() before pages() in the Hono handler order - #18253

Merged
matthewp merged 1 commit into
mainfrom
factory/fix-18228
Oct 5, 2026
Merged

matthewp merged 1 commit into
mainfrom
factory/fix-18228

Conversation

@astro-factory

@astro-factory astro-factory Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Swaps the documented order of i18n() and pages() in examples/advanced-routing/src/fetch.ts and the JSDoc snippet in packages/integrations/cloudflare/src/hono.ts. pages() returns its response without calling Hono's next(), so any handler registered after it never runs. i18n() must come before pages() so it can post-process the page response and allow finalizeI18n to issue redirects (e.g. GET / → 302 /en/ when prefixDefaultLocale and redirectToDefaultLocale are both enabled). The wrong order also triggered Astro's runtime warning that the i18n handler was never called.

Testing

  • Added packages/astro/test/units/hono/i18n.test.ts, which asserts that a project with prefixDefaultLocale: true and redirectToDefaultLocale: true returns 302 with Location: /en/ when i18n() is mounted before pages(). The test fails with the old (reversed) order, confirming the bug and the fix.

Docs

  • No separate docs PR needed; the fix is the corrected code examples in the cloudflare integration JSDoc and the examples/advanced-routing entrypoint.

Closes #18228

@astro-factory astro-factory Bot added the fix verified Reporter confirmed the triage bot fix works label Oct 5, 2026
@astro-factory
astro-factory Bot requested a review from astro-reviewer October 5, 2026 17:27
@changeset-bot

changeset-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4d235d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@astro-factory

astro-factory Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

astro-author owns this pull request

Factory's code author persona works on this branch when a maintainer or Factory's reviewer requests changes, or when checks fail: it pushes follow-up commits, replies to review threads, and asks for another review. It never merges. Unassign astro-author to take the pull request back; reassign it to start a fresh budget.

Rounds used: 0 of 5
Status: waiting for feedback.

— astro-author (Factory persona)

@astro-factory
astro-factory Bot removed the request for review from astro-reviewer October 5, 2026 17:27

@astro-factory astro-factory Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: approved. No blocking findings remain.

GitHub doesn't let Factory approve a pull request it opened, so this verdict is recorded as a comment.

Findings

No findings.

Merge Requirement Assessment

Status: satisfied

  • Mount i18n() before pages() in the documented Hono handler order (#18228). The order is swapped in two places: examples/advanced-routing/src/fetch.ts and the JSDoc usage snippet in packages/integrations/cloudflare/src/hono.ts. This matches how packages/astro/src/core/hono/index.ts works:

    • pages() returns fetchPages(...) and never calls honoNext(), so any handler registered after it never runs.
    • i18n() awaits honoNext() first and then replaces context.res with the result of fetchI18n(...). It only works when it wraps pages().
  • Regression coverage for the redirect behavior. The new packages/astro/test/units/hono/i18n.test.ts:

    • builds an app with strategy: 'pathname-prefix-always'
    • mounts i18n() before pages()
    • asserts that GET / returns 302 with Location: /en/

    With the old order, i18n() never runs, so the response would be the rendered page and both assertions would fail. The test matches the existing unit-test conventions (node:test, node:assert/strict, imports from built dist/, the createTestApp/createPage mocks). It is picked up by the test/units/**/*.test.ts glob, and hono is already a devDependency of astro.

Review Status

Verdict: ready to merge based on static review
Context: PR #18253 plus its description, which links issue #18228
Scope: the full PR diff from base 1e5523d to head 4d235d8, covering 4 files
Changeset: present and covers @astrojs/cloudflare (patch). This is the only published package with a non-test change. The astro change is a test only, and examples/ doesn't need a changeset.
Limitations: I couldn't search the whole repository for other docs or examples that still show the old pages() then i18n() order. I only read the changed files and the files they directly depend on.
Validation: Static review only. I didn't run any project code, tests, builds, or checks.
GitHub context: collected
Git scope: PR base and head verified

This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.

@github-actions github-actions Bot added pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) labels Oct 5, 2026
@matthewp
matthewp merged commit 78dca00 into main Oct 5, 2026
29 checks passed
@matthewp
matthewp deleted the factory/fix-18228 branch October 5, 2026 19:46
@astrobot-houston astrobot-houston mentioned this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documented Hono order never runs i18n()

2 participants