Files
mrInvincible29andClaude Opus 4.6 3c70a57af7 fix(mobile): prevent app hanging behind reverse proxies and fix Hermes compat (#2559)
* fix(mobile): prevent app hanging behind reverse proxies and fix Hermes compat

The mobile app would hang indefinitely when connecting through reverse
proxies (e.g. Traefik) because tRPC's httpBatchLink had no fetch timeout,
and the default maxURLLength of 14000 could produce requests that
reverse proxies reject or buffer indefinitely.

Additionally, signing in on Android (Hermes runtime) would crash with
"undefined is not a function" due to two Hermes-specific issues.

Changes:
- Add custom fetch wrapper with 30s AbortController-based timeout
  (AbortSignal.timeout() is not available in Hermes)
- Use arrow function for the fetch property to prevent
  @babel/plugin-transform-shorthand-properties from creating a named
  function expression that shadows the global fetch, causing infinite
  recursion
- Use .then(onFulfilled, onRejected) instead of .finally() which may
  not be available on all Hermes versions
- Reduce maxURLLength from 14000 to 4000 to stay within reverse proxy
  default limits
- Extract makeQueryClient() with staleTime to reduce redundant refetches

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* review comments

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 11:27:42 +00:00

26 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Maximum URL length for tRPC httpBatchLink requests.
*
* The web app uses a higher limit to support bulk operations (e.g.
* drag-and-drop bookmark import from the browser) that produce large
* batched request URLs. The trade-off is that users behind a reverse
* proxy with strict default header limits may hit 431 errors on very
* large batches.
*
* The mobile app and browser extension use a lower limit because they
* don't need bulk operations and their requests always travel through
* the user's server, which typically sits behind a reverse proxy.
* nginx — the most common reverse proxy for self-hosted deployments —
* defaults `large_client_header_buffers` to 4 × 8 KB, meaning a single
* request line (including the URL) must fit within ~8 KB. 4,000
* characters stays safely under that limit after accounting for the
* method, HTTP version, and any URL-encoding overhead.
*
* Also see:
* * https://github.com/karakeep-app/karakeep/issues/281
* * https://github.com/karakeep-app/karakeep/issues/1619
* * https://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers
*/
export const TRPC_MAX_URL_LENGTH_INTERNAL = 14000;
export const TRPC_MAX_URL_LENGTH_EXTERNAL = 4000;