Skip to content

fix(algolia): use createFetchRequester so the SDK runs on CF Workers#68

Merged
JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/algolia-fetch-requester
Jun 3, 2026
Merged

fix(algolia): use createFetchRequester so the SDK runs on CF Workers#68
JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/algolia-fetch-requester

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

algoliasearch v4 defaults to NodeHttpRequester (uses node:http) on server runtimes — which crashes on first request in Cloudflare Workers because the node:http module isn't available. Pass @algolia/requester-fetch explicitly so the SDK uses the global fetch, which is what every Deco target runtime (Workers, Bun, Node 18+) provides.

Without this, granadobr-tanstack home ProductShelves silently swallowed the loader exception (CMS resolver chain catches errors and falls back to undefined) and rendered as empty skeletons even though credentials, init wiring, and the SDK construction all looked correct from the outside.

What changed

  • algolia/client.ts: algoliasearch(appId, key, { requester: createFetchRequester() })
  • package.json: @algolia/requester-fetch declared as an optional peer dep with the same ^4 range as algoliasearch. Added to devDeps for tests.
  • Tests updated to assert the third arg (options) is now passed through.

14/14 tests pass.

Driving consumer

deco-sites/granadobr-tanstack worker: this was the root cause behind the 6 critical visual-regression issues on /::mobile that survived the apps-start#66/#67 wiring fix. Every algolia loader's client.search(...) threw Cannot find module 'node:http' on CF Workers.

Test plan

  • bun run typecheck clean
  • bunx vitest run algolia/ — 14/14 pass
  • Validated end-to-end on granadobr-tanstack worker

🤖 Generated with Claude Code


Summary by cubic

Ensure the Algolia client works on Cloudflare Workers by using a fetch-based requester instead of Node’s HTTP. Fixes crashes in loaders and restores rendering across Workers, Bun, and modern Node.

  • Bug Fixes

    • Force algoliasearch to use @algolia/requester-fetch via createFetchRequester() to avoid the node:http dependency in Workers.
    • Updated tests to assert the options object (with requester) is passed.
  • Dependencies

    • Added @algolia/requester-fetch as an optional peer (^4) and dev dependency.

Written for commit d556ae5. Summary will update on new commits.

Review in cubic

The algoliasearch v4 default requester loads node:http via the
NodeHttpRequester, which crashes on first request in Cloudflare
Workers (no node:http module). Pass `@algolia/requester-fetch`
explicitly so every Deco runtime — Workers, Bun, Node 18+ — uses
the global fetch.

Without this, granadobr-tanstack's home ProductShelves silently
swallowed the loader exception and rendered as empty skeletons even
though credentials, init wiring, and the SDK construction all looked
correct.

requester-fetch declared as an optional peer dep with the same
^4 range as algoliasearch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@JonasJesus42 JonasJesus42 requested a review from a team June 3, 2026 02:08
@JonasJesus42 JonasJesus42 merged commit 8696f18 into main Jun 3, 2026
1 of 2 checks passed
@JonasJesus42 JonasJesus42 deleted the JonasJesus42/algolia-fetch-requester branch June 3, 2026 02:08
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant