fix(licensing): keep hash target revealed after next-stage updates
This commit is contained in:
@@ -462,7 +462,7 @@ export default function InvestmentPath(path: Path) {
|
||||
reveal();
|
||||
window.addEventListener('hashchange', reveal);
|
||||
return () => window.removeEventListener('hashchange', reveal);
|
||||
}, [path.case.id, path.context_opportunity, stageCodes]);
|
||||
}, [path.case.id, path.context_opportunity, stageCodes, path.next?.code]);
|
||||
const { auth, flash } = usePage<{
|
||||
auth: { user: { id: number } };
|
||||
flash: { success?: string };
|
||||
|
||||
@@ -200,11 +200,12 @@ test("unknown, absent or out-of-scope hash targets have no effect", () => {
|
||||
assert.equal(f.phase.open, false);
|
||||
assert.deepEqual(f.calls, []);
|
||||
});
|
||||
test("page reveals the initial hash, listens for later hash changes and cleans up the listener", () => {
|
||||
test("page reveals the initial hash and server next-stage updates, listens for hash changes and cleans up", () => {
|
||||
const f = targetFixture(),
|
||||
effects = [],
|
||||
listeners = new Map();
|
||||
const previousWindow = globalThis.window;
|
||||
let previousDependencies;
|
||||
globalThis.window = {
|
||||
location: { hash: "#S08" },
|
||||
addEventListener: (type, fn) => listeners.set(type, fn),
|
||||
@@ -233,7 +234,12 @@ test("page reveals the initial hash, listens for later hash changes and cleans u
|
||||
{
|
||||
...React,
|
||||
useRef: () => ({ current: f.root }),
|
||||
useEffect: (effect) => effects.push(effect),
|
||||
useEffect: (effect, dependencies) => {
|
||||
if (!previousDependencies || dependencies.some((value, i) => value !== previousDependencies[i])) {
|
||||
effects.push(effect);
|
||||
}
|
||||
previousDependencies = dependencies;
|
||||
},
|
||||
useState: (initial) => [
|
||||
typeof initial === "function" ? initial() : initial,
|
||||
() => {},
|
||||
@@ -249,6 +255,17 @@ test("page reveals the initial hash, listens for later hash changes and cleans u
|
||||
assert.equal(f.phase.open, true);
|
||||
cleanup();
|
||||
assert.equal(listeners.size, 0);
|
||||
h.renderPage();
|
||||
assert.equal(effects.length, 1);
|
||||
// A saved transition changes the controlled phase's `open` prop.
|
||||
h.path.next = { code: "S09" };
|
||||
f.phase.open = false;
|
||||
h.renderPage();
|
||||
assert.equal(effects.length, 2);
|
||||
const updatedCleanup = effects[1]();
|
||||
assert.equal(f.phase.open, true);
|
||||
updatedCleanup();
|
||||
assert.equal(listeners.size, 0);
|
||||
} finally {
|
||||
globalThis.window = previousWindow;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user