tamer-transports
Fetch, WebSocket, and EventSource polyfills for Lynx. Required for HMR and WebSocket in native Lynx apps.
Overview
Installs polyfills on import:
- installFetchPolyfill() — Replaces Lynx’s stock fetch with a polyfill that attempts to meet the browser-standard fetch API
- installWebSocketPolyfill() — WebSocket polyfill that attempts to meet the browser-standard WebSocket API
- installEventSourcePolyfill() — EventSource polyfill that attempts to meet the browser-standard EventSource API
Exports fetch, WebSocket, EventSource (native or polyfilled).
Background thread: In Lynx, fetch, WebSocket, and EventSource are background-thread APIs (same as the host fetch in the runtime docs). Do not call them from main-thread-only code. Best practice: perform network setup and any state updates from useEffect, event handlers, or other background-thread code, and add 'background only' as the first statement in that function when the compiler cannot infer it (e.g. when setting React state after a fetch inside a custom hook).
Example (ReactLynx): open a WebSocket in an effect, update state from messages, clean up on unmount:
Note: These polyfills are not fully tested. Report issues on GitHub.
Installation
Run t4l link after installing. Import early in your app entry (e.g. before any fetch/WebSocket usage):
API
The package has no public API beyond the polyfills. Importing it installs the polyfills globally. Use globalThis.fetch, new WebSocket(...), and EventSource as usual.
