Skip to content

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
Co-authored-by: Tim Dorr <timdorr@users.noreply.github.com>
@MichaelDeBoey MichaelDeBoey changed the title feat(cloudflare): allow prefix on createWorkersKVSessionStorare feat(cloudflare): allow prefix on createWorkersKVSessionStorage Jun 10, 2025
@brophdawg11
Copy link
Contributor

We should probably open an RFC for this to follow the new process. I think this seems handy - but wonder if an optional id() factory function defaulting to the current logic would be a bit more general use-case?

@brophdawg11 brophdawg11 added the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jun 30, 2025
@brophdawg11
Copy link
Contributor

brophdawg11 commented Jun 30, 2025

I hope you don't mind - I'm using this PR to test out the new alpha release workflow since I haven't tested that on a PR from a forked repo yet :)

Update: it failed 🙃 - looks like I need to dig into the workflow permissions from forked repos so I'll do that separately

@brophdawg11 brophdawg11 removed the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jun 30, 2025
@brophdawg11
Copy link
Contributor

I'm going to close this for now according to the new Open Governance model - let's open a Proposal and then if it moves along we can re-open this PR

@brophdawg11 brophdawg11 closed this Jul 1, 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.

4 participants