-
Notifications
You must be signed in to change notification settings - Fork 114
feat(core,plugin-history-sync): allow step actions for non-top activities #642
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
980c183
7696863
42cde0f
398bcf8
8f5a022
ae7c98d
289cd62
a8167c8
57b087f
d951a66
8807c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| "@stackflow/core": minor | ||
| "@stackflow/plugin-history-sync": minor | ||
| --- | ||
|
|
||
| Allow step actions to target lower activities with targetActivityId | ||
|
|
||
| **Core Changes:** | ||
| - Step actions (stepPush, stepPop, stepReplace) can now target any activity in the stack using `targetActivityId` option | ||
| - Previously only the top activity could be targeted | ||
| - Enables modifying lower activity steps when popping current activity | ||
|
|
||
| **History Sync Plugin Changes:** | ||
| - Added intelligent synchronization when navigating to lower activities with removed steps | ||
| - When navigating back to a step that was removed via `stepPop`, automatically skips the removed entry | ||
| - Uses `history.back()` to navigate to the correct remaining step | ||
|
|
||
| **Use Case:** | ||
| ```typescript | ||
| // Remove a step from a lower activity while at top activity | ||
| actions.stepPop({ targetActivityId: lowerActivityId }); | ||
|
|
||
| // When user navigates back, the removed step entry is automatically skipped | ||
| history.back(); // Skips removed step, lands on the correct step | ||
| ``` | ||
|
|
||
| This is backward compatible - existing code works without changes. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1463,4 +1463,55 @@ describe("historySyncPlugin", () => { | |
| */ | ||
| expect(queryResponse.data.hello).toEqual("world"); | ||
| }); | ||
|
|
||
| test("historySyncPlugin - stepPop on lower activity skips removed step when navigating back", async () => { | ||
| actions.push({ | ||
| activityId: "a1", | ||
| activityName: "Article", | ||
| activityParams: { | ||
| articleId: "10", | ||
| title: "step1", | ||
| }, | ||
| }); | ||
|
|
||
| actions.stepPush({ | ||
| stepId: "s1", | ||
| stepParams: { | ||
| articleId: "11", | ||
| title: "step2", | ||
| }, | ||
| }); | ||
|
|
||
| actions.stepPush({ | ||
| stepId: "s2", | ||
| stepParams: { | ||
| articleId: "12", | ||
| title: "step3", | ||
| }, | ||
| }); | ||
|
|
||
| await actions.push({ | ||
| activityId: "a2", | ||
| activityName: "Article", | ||
| activityParams: { | ||
| articleId: "20", | ||
| title: "second", | ||
| }, | ||
| }); | ||
|
|
||
| expect(history.index).toEqual(4); | ||
|
|
||
| // Pop step from lower activity a1 | ||
| actions.stepPop({ targetActivityId: "a1" }); | ||
|
|
||
| // Navigate back - should skip the removed step3 entry and land on step2 | ||
| history.back(); | ||
|
|
||
| const stack = await actions.getStack(); | ||
| const active = activeActivity(stack); | ||
| expect(active?.id).toEqual("a1"); | ||
| expect(active?.steps.length).toEqual(2); // step1 and step2 remain | ||
| expect(active?.steps[1]?.params.title).toEqual("step2"); | ||
| expect(path(history.location)).toEqual("/articles/11/?title=step2"); | ||
| }); | ||
|
Comment on lines
+1467
to
+1516
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add test coverage for multiple step pops on lower activity. The test correctly verifies single step pop behavior, but doesn't cover the scenario where multiple steps are popped from a lower activity. Given the past review comment flagging a critical issue with multi-step pops (only calling
This would catch the bug in the implementation where only one step is skipped. Example test structure: test("historySyncPlugin - multiple stepPops on lower activity skip all removed steps when navigating back", async () => {
// Setup: activity a1 with 3 steps, then activity a2
actions.push({ activityId: "a1", activityName: "Article", activityParams: { articleId: "10", title: "step1" } });
actions.stepPush({ stepId: "s1", stepParams: { articleId: "11", title: "step2" } });
actions.stepPush({ stepId: "s2", stepParams: { articleId: "12", title: "step3" } });
actions.stepPush({ stepId: "s3", stepParams: { articleId: "13", title: "step4" } });
await actions.push({ activityId: "a2", activityName: "Article", activityParams: { articleId: "20", title: "second" } });
// Pop TWO steps from lower activity a1
actions.stepPop({ targetActivityId: "a1" });
actions.stepPop({ targetActivityId: "a1" });
// Navigate back - should skip both removed steps (step4 and step3) and land on step2
history.back();
const stack = await actions.getStack();
const active = activeActivity(stack);
expect(active?.id).toEqual("a1");
expect(active?.steps.length).toEqual(2);
expect(active?.steps[1]?.params.title).toEqual("step2");
expect(path(history.location)).toEqual("/articles/11/?title=step2");
});🤖 Prompt for AI Agents |
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.