Addon-Docs: Add Reset story button to re-render stories in docs#34086
Addon-Docs: Add Reset story button to re-render stories in docs#34086Sidnioulz merged 12 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a Reload action to the docs preview: Preview accepts an optional Changes
sequenceDiagram
autonumber
actor User as "User"
participant Preview as "Preview UI"
participant Canvas as "Canvas / PurePreview wrapper"
participant Channel as "docsContext.channel"
participant Story as "Story iframe / Manager"
User->>Preview: Click Reload button
Preview->>Canvas: call onReloadStory()
Canvas->>Channel: emit(FORCE_REMOUNT, { storyId })
Channel->>Story: FORCE_REMOUNT event
Story->>Story: Remount / reload story
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/addons/docs/src/blocks/blocks/Canvas.tsx`:
- Around line 100-102: The inline Canvas currently always wires onResetStory
(inline ? handleResetStory : undefined) which forces a reset button for every
inline Docs canvas; change this to check a configurable prop/parameter (e.g., a
block prop like allowReset or a docs parameter like docs.disableReset) so the
handler is only passed when inline && !disableReset (or inline && allowReset).
Update the Canvas component where onResetStory is assigned and ensure the Story
usage (Story ... resetKey={resetKey}) remains unchanged; document/read the prop
from props or props.meta so consumers can opt out per-story, per-component, or
globally.
- Around line 86-89: The handler currently emits RESET_STORY_ARGS and also bumps
local resetKey (setResetKey), causing two remounts; remove the local remount
path by deleting the setResetKey((prev) => prev + 1) call (and remove/reset the
resetKey state if present) so handleResetStory only calls
docsContext.channel.emit(RESET_STORY_ARGS, { storyId: story.id }); update the
handleResetStory dependency array to only include docsContext.channel and
story.id and remove any references to setResetKey/resetKey elsewhere in this
component.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5ae9e1b6-5386-4fb6-841a-97bca5fc45c7
📒 Files selected for processing (4)
code/addons/docs/src/blocks/blocks/Canvas.tsxcode/addons/docs/src/blocks/blocks/Story.tsxcode/addons/docs/src/blocks/components/Preview.tsxcode/addons/docs/src/blocks/components/Story.tsx
|
Hi @6810779s Thank you so much for your contribution! After reviewing the changes and discussing them internally, we have a few requested adjustments to ensure this aligns with the original issue and our existing UI patterns. The original issue specifically requested a way to reload a story. Currently, this PR introduces a feature that does an args reset + reload. We feel it's best to give users the exact same controls in the Docs canvas as they already have in the Story canvas, which is a standard "reload" action. Additionally, we'd prefer not to put this behind a parameter (docs.canvas.resetButton). Managing this configuration seems unnecessary for users, and we'd rather it be the default behavior. |
Thanks for the feedback! I've updated the PR:
|
Sidnioulz
left a comment
There was a problem hiding this comment.
Thanks for the PR! I've added some notes on UI/copy for you!
64a45cf to
b26eb76
Compare
Sidnioulz
left a comment
There was a problem hiding this comment.
Could you please move the button to the start of the canvas toolbar, to match its position in the main UI toolbar in story mode?
e4e69c9 to
b82d98e
Compare
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
|
Thanks so much @6810779s! Now we wait for CI to go green 🍿 🤓 I'll let you know if something requires your attention. |
Thank you for the thorough review, @Sidnioulz ! 🙏 |
Closes #12101
What I did
Add a "Reload story" button to the Canvas action bar in Docs view.
Uses
FORCE_REMOUNTevent, matching the existing Story canvas reload behavior.The button is shown by default for all inline stories — no configuration needed.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task --task sandbox --start-from auto --template react-vite/default-tshttp://localhost:6006Documentation
Summary by CodeRabbit