workerd: 🐛 BUG: The cache field on RequestInitializerDict is not implemented in fetch
Which Cloudflare product(s) does this pertain to?
Workers for Platforms
What version of Wrangler are you using?
Latest
What operating system are you using?
All
Describe the Bug
Making a fetch request with the cache field throws the following exception.
The cache field on RequestInitializerDict is not implemented
const response = await fetch(url, {
cache: 'no-store',
method: 'POST',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}
})
This was reported in our database driver in https://github.com/planetscale/database-js/pull/102. We’re using the cache attribute to advise the runtime to avoid caching any responses since the response body is an SQL result set that varies on every request.
A similar issue was reported in https://github.com/cloudflare/workers-sdk/issues/192, but I’m not sure what the resolution was there.
Is support for the standard Request.cache attribute planned? Ideally, we’d like to treat all JS runtimes identically and rely on the fetch interfaces to hide implementation details from the driver. Even “supporting” the attribute without throwing, but with no actual implementation, would be helpful here.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 68
- Comments: 37 (3 by maintainers)
Commits related to this issue
- Added cache: 'no-store' to fetch options (prevent unexpected caching) — committed to neondatabase/serverless by jawj a year ago
- workaround for https://github.com/cloudflare/workerd/issues/698 — committed to AlexErrant/Pentive by AlexErrant a year ago
- added test rest api and downgrade planetscale/database to 1.6 due to https://github.com/cloudflare/workerd/issues/698 — committed to MANTENN/honojs-wordpress by MANTENN 4 months ago
- added test rest api and downgrade planetscale/database to 1.6 due to https://github.com/cloudflare/workerd/issues/698 — committed to MANTENN/honojs-wordpress by MANTENN 4 months ago
- downgrade supabase js Issue: - https://github.com/supabase/supabase-js/issues/1001 -https://github.com/cloudflare/workerd/issues/698 — committed to suciptoid/supalink by suciptoid 2 months ago
@dgraham — we’re going to address this, just a matter of timing. Should know more specifics soon.
Quick update on this… it’s going to take a bit of time to do and we need to do a bit more evaluation, so I cannot give a time estimate or a firm confirmation just yet, but… our current plan here is to start allowing the
cacheoption to be set but the only acceptable values will beundefinedorno-storeinitially. Passing the other spec-defined values, includingdefaultwill throw with a better error than what we have currently.undefinedwill map to Worker’s current behavior. As I said, there are still a number of details to work out so we cannot commit to a timeline just yet but I wanted to update so that y’all know we’re actively looking at this.Experiencing same issue using wrangler (3.39.0) as my main api 🫤.
If anyone got this issue in combination with
supabase-js. In the following issue I added a comment describing a temporary workaround: https://github.com/supabase/supabase-js/issues/1001#issuecomment-2027790018.Changing the label on this to
feature-requestfrombug. Will be upping the priority on getting this implemented.It’s been almost a year, do we have a timeline to when this might be fixed?
Thanks.
💀 I wonder what the author who put that comment in there makes of this bug…
@nechmads
Have you tried the method described here? https://github.com/supabase/supabase-js/issues/1001#issuecomment-2027790018
Had the same issue with not being able to downgrade.
@dgraham Downgrading to 1.6.0 seems to be a solution for now.
Will be watching this space and https://github.com/planetscale/database-js/pull/102 for a solution which will work with latest version too, FYI.
Thanks.
Looking at supporting
cache: 'default'andcache: 'no-store'as options here as shortest path. Know this is painful right now and working towards something we can do ASAP.Unfortunately not quite safe to ignore the field — you might set something like
cache: 'no-store', and then if the request was cached, could lead to confusing behavior, bugs and other types of more subtle and harder to debug issues with packages you might depend on.👋 I’ve put together a snippet to workaround this for now that replaces
fetchwith a custom one that will remove thecacheproperty if it’s not supported.Tested locally with wrangler. It should fallback to the proper implementation when support becomes available in the future. Just make this one of the first bits of code to run
https://gist.github.com/tjenkinson/53b5724bf8112487f6bd797368e02b56
No specific timeline yet but I’ll raise this again in internal discussions to see if we can get something scheduled.
Same issue
why cant workerd just ignore the cache field? it would make things a LOT easier.
@davbauer OK. I’ve been going crazy for the past day trying to figure this out. For me, it’s not enough to add: “@supabase/auth-js”: “^2.62.0” When doing this it sometimes worked and sometimes not. I had a totally new project where it was working and another when it didn’t. It something about how npm is installing packages. What solved it for me for good was to also add:
in order to make sure that the right version is always used.
@ignoramous if ur using planetscale https://github.com/planetscale/database-js/pull/102#issuecomment-1508219636
Still seeing this:
Any workaround till this attr is implemented?
Had the same issue with a remix project using
@supabase/ssr ^0.3.0on Cloudflare PagesSorted it using @tjenkinson’s method.
Created a
app/utils/supabase-ssr.cf-fetch.ts:then import in
app/root.tsxThis way I can just leave the code forever, or remove the single include and file when fixed 🥳
Getting this when trying to use
@supabase/ssron an Astro site deployed to PagesExperiencing the same issue in NextJs 14 app
@rtconner it would be helpful if you provided a repro of it happening. Are you using a framework like Next or similar?
@jdgamble555 I use my above patch with SvelteKit. I believe you should also be able to use a
handleFetchhook to accomplish the same as the global fetch replacement above.Thanks! I actually found a kinda dumb but-it-works workaround.
You can try downgrading like described from this user on another issue on
supabase-js(https://github.com/supabase/supabase-js/issues/1001#issuecomment-2027560043). This is obviously just a temporary fix for now.