Skip to content

fix(react-router): delete flashed entries in session.unset() - #15811

Open
ragib-mrb wants to merge 1 commit into
remix-run:mainfrom
ragib-mrb:fix/session-unset-flash-values
Open

ragib-mrb wants to merge 1 commit into
remix-run:mainfrom
ragib-mrb:fix/session-unset-flash-values

Conversation

@ragib-mrb

Copy link
Copy Markdown
Contributor

Problem

In packages/react-router/lib/server-runtime/sessions.ts, session.has(name) and session.get(name) both check both regular keys (name) and flashed keys (__flash_${name}__). However, session.unset(name) only deletes name:

unset(name) {
  map.delete(name);
}

As a result, calling session.unset(name) on a flashed value leaves it intact (session.has(name) remains true and session.get(name) still returns the flashed value).

Fix

  • Delete both name and flash(name) in session.unset(name) and widen Session["unset"]'s parameter type to (keyof Data | keyof FlashData) & string to match has() and get().
  • Add a unit test in packages/react-router/__tests__/server-runtime/sessions-test.ts.

Verification

  • node --experimental-vm-modules ../../node_modules/jest/bin/jest.js __tests__/server-runtime/sessions-test.ts (18/18 passing; fails before fix)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant