Skip to content

feat(cloudflare): allow prefix on createWorkersKVSessionStorage #13778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sergiodxa
Copy link
Member

This is something I'm doing myself in a project and I think it would be useful to have directly in React Router for others as well.

Right now using createWorkersKVSessionStorage fills your Worker KV of keys like 64eb4897d922128d, if you don't use a KV exclusively for your sessions you can make it really hard to use CF Worker KV Dashboard to inspect the keys.

There's also no way to list every session and delete them, e.g you can't do this:

let result = await env.KV.list({ prefix: "session:" });
for (let key of result.keys) await env.KV.delete(key.name);

This small change adds an optional prefix option that can be used to solve this, so you can now do:

const sessionStorage = createWorkersKVSessionStorage({ cookie, kv, prefix: "session:" }) 

And now this session storage will add session: to every key ending up with something like session:64eb4897d922128d which can be easily be listed and work with using KV bindings.

Copy link

changeset-bot bot commented Jun 8, 2025

🦋 Changeset detected

Latest commit: f20b033

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/cloudflare Major
create-react-router Major
react-router Major
react-router-dom Major
@react-router/architect Major
@react-router/dev Major
@react-router/fs-routes Major
@react-router/express Major
@react-router/node Major
@react-router/remix-routes-option-adapter Major
@react-router/serve Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@MichaelDeBoey MichaelDeBoey changed the title Allow prefix on createWorkersKVSessionStorare feat(cloudflare): allow prefix on createWorkersKVSessionStorare Jun 8, 2025
@MichaelDeBoey MichaelDeBoey changed the title feat(cloudflare): allow prefix on createWorkersKVSessionStorare feat(cloudflare): allow prefix on createWorkersKVSessionStorage Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants