fix(dev): WP-37 — dev-switcher resets scenario/role instead of sticking
currentScenario()/currentRole() read the URL param before sessionStorage, so a
stale ?scenario=/?role= in the address bar overrode the switcher on reload
("stuck on slow"). The switcher now strips both dev params from the URL
(pure stripDevParams + history.replaceState) before reloading, so the stored
value wins.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { stripDevParams } from './dev-params';
|
||||
|
||||
describe('stripDevParams (WP-37)', () => {
|
||||
it('removes ?scenario and ?role so the stored dev value wins on reload', () => {
|
||||
expect(stripDevParams('http://localhost:4200/dashboard?scenario=slow&role=admin')).toBe(
|
||||
'http://localhost:4200/dashboard',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps unrelated query params and the path/hash', () => {
|
||||
expect(stripDevParams('http://localhost:4200/beheer/zaken?scenario=error&tab=2#top')).toBe(
|
||||
'http://localhost:4200/beheer/zaken?tab=2#top',
|
||||
);
|
||||
});
|
||||
|
||||
it('is a no-op when neither param is present', () => {
|
||||
expect(stripDevParams('http://localhost:4200/dashboard')).toBe(
|
||||
'http://localhost:4200/dashboard',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Remove the dev-only `?scenario=` and `?role=` params from a URL (WP-37). Once the
|
||||
* dev switcher (debug-state) has been used, sessionStorage is the authoritative source
|
||||
* for both — `currentScenario()`/`currentRole()` read the URL FIRST, so a stale param
|
||||
* left in the address bar would override the switcher on reload (the "stuck on slow"
|
||||
* bug). Stripping the params before reload lets the stored value win. Pure: returns the
|
||||
* rewritten href, mutates nothing.
|
||||
*/
|
||||
export function stripDevParams(href: string): string {
|
||||
const url = new URL(href);
|
||||
url.searchParams.delete('scenario');
|
||||
url.searchParams.delete('role');
|
||||
return url.toString();
|
||||
}
|
||||
Reference in New Issue
Block a user