Skip to content

Build HttpRouter.toHttpEffect apps with a fresh router - #10194

Merged
tim-smart merged 11 commits into
v4/next-minorfrom
fix/http-router-to-http-effect-fresh-router
Oct 30, 2026
Merged

tim-smart merged 11 commits into
v4/next-minorfrom
fix/http-router-to-http-effect-fresh-router

Conversation

@effect-bot

@effect-bot effect-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

HttpRouter.toHttpEffect built its app with Layer.provideMerge(appLayer, HttpRouter.layer) in a memo map forked from the caller's. When the sub-app is built inside HttpRouter.serve or HttpRouter.toWebHandler, that lookup found the server's memoized HttpRouter. The sub-app's routes and middleware then registered on the server's router:

  • sub-app routes matched before their mount, bypassing checks attached to the mount
  • mounting a sub-app at one of its own paths failed at startup with a duplicate-route error

toHttpEffect now forks the caller's memo map with HttpRouter.layer marked fresh. The fork never looks that layer up in its parent, so the first use of HttpRouter.layer inside the fork builds a new router and every later use in the fork shares it. That covers toHttpEffect's own router and an app that provides HttpRouter.layer itself. Every other layer is still reused from the parent memo map as before, so services shared with the server are not rebuilt.

HttpRouter.serve uses the same option, so a server always builds its own router instead of reusing an HttpRouter.layer already built outside it. Within the server's app, HttpRouter.layer still resolves to the server's router, and the routerConfig option now always applies. toWebHandler is unchanged.

New Layer option

To support this, Layer.forkMemoMap, Layer.forkMemoMapUnsafe and Layer.CurrentMemoMap.forkOrCreate take an optional { fresh } options argument listing layers. Layers in the list are never looked up in the parent; they are built again the first time the child uses them, then memoized in the child. The change is additive.

Docs

The toHttpEffect doc comment says the app's fresh router also stands in for HttpRouter.layer. It keeps the existing gotchas:

  • calling toHttpEffect twice builds the layer twice
  • the router reads RouterConfig from the context where toHttpEffect runs, not from the outer server's routerConfig option

Tests

  • packages/effect/test/http/HttpRouter.test.ts:
    • a sub-app behind an auth check on its mount, both plain and with Layer.provide(HttpRouter.layer)
    • a sub-app mounted at its own route
    • serve does not reuse an HttpRouter.layer built outside it
  • packages/effect/test/Layer.test.ts: a fork with { fresh: [layer] } builds that layer again while reusing other layers from the parent.

Closes EFF-3175

@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6a70bc4

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

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

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

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.35 KB 39.35 KB 0.00 KB (0.00%)
basic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
batching.ts 11.06 KB 11.06 KB 0.00 KB (0.00%)
brand.ts 6.84 KB 6.84 KB 0.00 KB (0.00%)
cache.ts 11.49 KB 11.49 KB 0.00 KB (0.00%)
config.ts 22.77 KB 22.77 KB 0.00 KB (0.00%)
differ.ts 21.92 KB 21.92 KB 0.00 KB (0.00%)
http-client.ts 26.90 KB 26.86 KB +0.04 KB (+0.13%)
http-router.ts 36.88 KB 36.85 KB +0.04 KB (+0.10%)
logger.ts 11.96 KB 11.96 KB 0.00 KB (0.00%)
metric.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
optic.ts 7.05 KB 7.05 KB 0.00 KB (0.00%)
pubsub.ts 15.97 KB 15.97 KB 0.00 KB (0.00%)
queue.ts 12.77 KB 12.77 KB 0.00 KB (0.00%)
schedule.ts 11.74 KB 11.74 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.02 KB 14.02 KB 0.00 KB (0.00%)
schema-binary.ts 41.06 KB 41.06 KB 0.00 KB (0.00%)
schema-class.ts 21.65 KB 21.65 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.51 KB 29.51 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.91 KB 27.91 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.27 KB 15.27 KB 0.00 KB (0.00%)
schema-string.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.19 KB 16.19 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.87 KB 38.87 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.10 KB 26.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.83 KB 20.83 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.97 KB 20.97 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.11 KB 26.11 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.16 KB 21.16 KB 0.00 KB (0.00%)
schema.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
stm.ts 14.15 KB 14.15 KB 0.00 KB (0.00%)
stream.ts 10.33 KB 10.33 KB 0.00 KB (0.00%)

Comment thread packages/effect/src/Layer.ts Outdated
export const forkMemoMapUnsafe = (parent: MemoMap): MemoMap => new MemoMapImpl(parent)
export const forkMemoMapUnsafe = (
parent: MemoMap,
options?: ForkMemoMapOptions | undefined

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

inline options instead of interface

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.

Inlined the { fresh } options type on forkMemoMap, forkMemoMapUnsafe and CurrentMemoMap.forkOrCreate and removed ForkMemoMapOptions in 402c429.

@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 30, 2026 09:08
@effect-janitor effect-janitor Bot removed the 4.0 label Oct 30, 2026
@effect-bot
effect-bot force-pushed the fix/http-router-to-http-effect-fresh-router branch from 7826eea to f3e2d96 Compare October 30, 2026 09:13
@tim-smart
tim-smart merged commit be6e453 into v4/next-minor Oct 30, 2026
11 checks passed
@tim-smart
tim-smart deleted the fix/http-router-to-http-effect-fresh-router branch October 30, 2026 09:37
tim-smart added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 3, 2026
effect-bot added a commit that referenced this pull request Nov 6, 2026
effect-bot added a commit that referenced this pull request Nov 6, 2026
effect-bot added a commit that referenced this pull request Nov 6, 2026
effect-bot added a commit that referenced this pull request Nov 6, 2026
effect-bot added a commit that referenced this pull request Nov 7, 2026
effect-bot added a commit that referenced this pull request Nov 7, 2026
effect-bot added a commit that referenced this pull request Nov 7, 2026
effect-bot added a commit that referenced this pull request Nov 8, 2026
tim-smart added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 18, 2026
effect-bot added a commit that referenced this pull request Nov 18, 2026
effect-bot added a commit that referenced this pull request Nov 19, 2026
effect-bot added a commit that referenced this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants