docs: add session storage support for controls state#7279
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds session-backed persistence for example Controls: CodeEditorWithPreview now stores controls state in session storage keyed per example and passes it to Controls via a new Changes
Sequence DiagramsequenceDiagram
participant User
participant CodeEditorWithPreview as CodeEditor
participant SessionStorage as SessionStorage
participant Controls
participant Preview
User->>CodeEditor: Open example
CodeEditor->>SessionStorage: read(key)
SessionStorage-->>CodeEditor: stored controlsState (or null)
CodeEditor->>Controls: render(sessionStoreValues)
Controls->>Controls: init state = sessionStoreValues ?? defaultState
Controls-->>Preview: render with componentProps
User->>Controls: interact -> change value
Controls->>CodeEditor: onChange(newValues)
CodeEditor->>CodeEditor: setControlsState(newValues)
CodeEditor->>SessionStorage: write(key, newValues)
CodeEditor->>Preview: update componentProps
Preview-->>User: re-rendered output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (2)
www/src/components/CodeEditorWithPreview.tsx (2)
95-95: Add an explicit generic touseSessionStorageStatefor proper type inference.Without an explicit generic,
useSessionStorageState(encodeURIComponent(stackBlitzTitle), null)will infer the state type asnullfrom the initial value, makingcontrolsStatetyped asnullinstead ofT | null. This breaks type safety when passingcontrolsStateto theControlscomponent (which expectssessionStoreValues: ControlsType | nullat line 201) and toComponentascomponentProps(at line 214).Also consider prefixing the storage key to avoid collisions with other examples that may share the same
stackBlitzTitle:Suggested change
- const [controlsState, setControlsState] = useSessionStorageState(encodeURIComponent(stackBlitzTitle), null); + const [controlsState, setControlsState] = useSessionStorageState<T | null>( + `controls:${encodeURIComponent(stackBlitzTitle)}`, + null, + );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@www/src/components/CodeEditorWithPreview.tsx` at line 95, The state call infers null because the initial value is null; update the useSessionStorageState invocation to include an explicit generic (e.g., ControlsType | null) so controlsState is correctly typed, and adjust the storage key by prefixing encodeURIComponent(stackBlitzTitle) (e.g., "controls:" + ...) to avoid collisions; update references to useSessionStorageState, controlsState and setControlsState accordingly so Controls (sessionStoreValues) and Component (componentProps) receive the correctly typed value.
7-7: Use the public entry point foruseSessionStorageStatefrom@recharts/devtools.The file imports
useSessionStorageStatefrom@recharts/devtools/dist/hooks/useSessionStorageState(line 7), but this same file importsRechartsDevtoolsContextfrom the main entry point@recharts/devtools(line 5). Deep dist imports are inconsistent with the pattern used everywhere else in the codebase—nearly all other files import from the package root. The deep path is also fragile, as it depends on the package's internal build structure remaining stable.Check whether
useSessionStorageStateis exported from the main entry point of@recharts/devtools. If it is, update the import to use it:Proposed change
-import { useSessionStorageState } from '@recharts/devtools/dist/hooks/useSessionStorageState'; +import { useSessionStorageState } from '@recharts/devtools';If the hook is not yet exported from the main entry, it should be added there (or the import should be documented in
@recharts/devtoolsas a supported subpath export).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@www/src/components/CodeEditorWithPreview.tsx` at line 7, The import currently pulls useSessionStorageState from the package internals (`@recharts/devtools/dist/hooks/useSessionStorageState`) which is fragile and inconsistent with the existing RechartsDevtoolsContext import from `@recharts/devtools`; change the import to import useSessionStorageState from the package root (i.e., from '@recharts/devtools') if that hook is exported there, updating the import statement in CodeEditorWithPreview.tsx to use the public entry point; if the hook is not exported from the main entry, add it to the package's public exports (or request it be exported) so the component can import useSessionStorageState from '@recharts/devtools' instead of the deep dist path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@www/src/components/CodeEditorWithPreview.tsx`:
- Line 95: The state call infers null because the initial value is null; update
the useSessionStorageState invocation to include an explicit generic (e.g.,
ControlsType | null) so controlsState is correctly typed, and adjust the storage
key by prefixing encodeURIComponent(stackBlitzTitle) (e.g., "controls:" + ...)
to avoid collisions; update references to useSessionStorageState, controlsState
and setControlsState accordingly so Controls (sessionStoreValues) and Component
(componentProps) receive the correctly typed value.
- Line 7: The import currently pulls useSessionStorageState from the package
internals (`@recharts/devtools/dist/hooks/useSessionStorageState`) which is
fragile and inconsistent with the existing RechartsDevtoolsContext import from
`@recharts/devtools`; change the import to import useSessionStorageState from the
package root (i.e., from '@recharts/devtools') if that hook is exported there,
updating the import statement in CodeEditorWithPreview.tsx to use the public
entry point; if the hook is not exported from the main entry, add it to the
package's public exports (or request it be exported) so the component can import
useSessionStorageState from '@recharts/devtools' instead of the deep dist path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e46a794e-ea12-4cdc-837c-11b21994c105
📒 Files selected for processing (6)
www/src/components/CodeEditorWithPreview.tsxwww/src/components/GuideView/Animations/AnimationsExample.tsxwww/src/components/GuideView/AxisTicks/CustomAxisTicks.tsxwww/src/components/GuideView/AxisTicks/NiceTicksPlayground.tsxwww/src/components/GuideView/BarAlign/CustomBandScaleExample.tsxwww/src/docs/exampleComponents/types.ts
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7279 +/- ##
==========================================
- Coverage 89.08% 89.05% -0.04%
==========================================
Files 541 541
Lines 41069 41088 +19
Branches 5564 5564
==========================================
+ Hits 36588 36589 +1
- Misses 4473 4491 +18
Partials 8 8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Bundle ReportBundle size has no change ✅ |
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
closes #7277
website changes only
AI summary below
This pull request introduces session storage for chart controls in the code editor and playground examples, allowing users' control states to persist across page reloads within a session. The main changes include updating the controls' component signatures, wiring up session storage state, and ensuring all relevant controls use the persisted state as their initial value.
Session storage integration for controls:
Controlsprop type in bothCodeEditorWithPreviewandChartExampleto accept an additionalsessionStoreValuesprop, which provides the persisted state from session storage. [1] [2]useStateforcontrolsStateinCodeEditorWithPreviewwith the newuseSessionStorageStatehook, using the encodedstackBlitzTitleas the key for storage.sessionStoreValuesprop to all control components inCodeEditorWithPreview, ensuring they receive the persisted state.Control component updates:
AnimationsControls,CustomAxisTicksControls,AxisTicksControls,BarAlignControls) to accept the newsessionStoreValuesprop and initialize their local state from session storage if available. [1] [2] [3] [4]Supporting changes:
useSessionStorageStatehook from@recharts/devtoolsto enable session storage functionality.Summary by CodeRabbit