---
title: "Comment by OneLifeVibe on \"Mock Your API Inside the Client: HTTP, SSE, NDJSON & WebSocket with tanstack-fetch\" | Hashnode"
description: "The per-route enabled switch is the part that makes this more than a demo trick — being able to turn off /market/overview the day the real endpoint ships while"
url: "https://hashnode.com/posts/mock-your-api-inside-the-client-http-sse-ndjson-websocket-with-tanstack-fetch/6af1739e443aa35f80419d91/comment/6af1974b79c8674ebaa2b472"
---

[Discussion](https://hashnode.com/posts/mock-your-api-inside-the-client-http-sse-ndjson-websocket-with-tanstack-fetch/6af1739e443aa35f80419d91)

Comment [Mock Your API Inside the Client: HTTP, SSE, NDJSON & WebSocket with tanstack-fetch](https://hashnode.com/posts/mock-your-api-inside-the-client-http-sse-ndjson-websocket-with-tanstack-fetch/6af1739e443aa35f80419d91)

[OneLifeVibe](https://hashnode.com/@onelifevibe)

[2d ago](https://hashnode.com/posts/mock-your-api-inside-the-client-http-sse-ndjson-websocket-with-tanstack-fetch/6af1739e443aa35f80419d91/comment/6af1974b79c8674ebaa2b472)

The per-route enabled switch is the part that makes this more than a demo trick — being able to turn off /market/overview the day the real endpoint ships while the chat room and price feed stay mocked is exactly how a frontend team keeps moving during a staggered backend rollout. I also appreciated the honest note that a static import drags the fixtures into the production bundle, with the dynamic-import fix right there instead of buried in a footnote. One question: with the SSE generator's finally cleanup on unmount, how do you handle a mock that needs to keep a shared timer across two components subscribing to the same feed, or is one generator per subscriber the intended shape?

[mohammad garmabi](https://hashnode.com/@garmabi07)

[2d ago](https://hashnode.com/posts/mock-your-api-inside-the-client-http-sse-ndjson-websocket-with-tanstack-fetch/6af1739e443aa35f80419d91/comment/6af1974b79c8674ebaa2b472#reply-6af19d228e701a05b6b935ed)

Thanks, and you nailed the use case: the `enabled` switch exists precisely for staggered rollouts.

Yes, one generator per subscriber is the intended shape. Each `api.sse()` call gets its own iterator, so `finally` cleanup stays scoped to that subscriber and unmounting one component never kills another's stream.

If two subscribers need to see the same ticks, keep the shared state outside the generator. Create one module-level ticker (a `setInterval` plus a small listener set), and have each generator subscribe to it on start and unsubscribe in `finally`. Then the timer is shared, and the per-subscriber cleanup still works. You can also stop the interval when the listener set is empty, which mirrors how a real server behaves.

In practice, the simpler fix is often one level up: if both components render the same feed, put the subscription in a shared hook or query so there's only one consumer in the first place.
