Skip to content

docs: add session storage support for controls state#7279

Merged
PavelVanecek merged 2 commits into
mainfrom
session-storage-controls
Apr 27, 2026
Merged

docs: add session storage support for controls state#7279
PavelVanecek merged 2 commits into
mainfrom
session-storage-controls

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator

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:

  • Updated the Controls prop type in both CodeEditorWithPreview and ChartExample to accept an additional sessionStoreValues prop, which provides the persisted state from session storage. [1] [2]
  • Replaced the local useState for controlsState in CodeEditorWithPreview with the new useSessionStorageState hook, using the encoded stackBlitzTitle as the key for storage.
  • Passed the sessionStoreValues prop to all control components in CodeEditorWithPreview, ensuring they receive the persisted state.

Control component updates:

  • Updated all relevant control components (AnimationsControls, CustomAxisTicksControls, AxisTicksControls, BarAlignControls) to accept the new sessionStoreValues prop and initialize their local state from session storage if available. [1] [2] [3] [4]

Supporting changes:

  • Imported the useSessionStorageState hook from @recharts/devtools to enable session storage functionality.

Summary by CodeRabbit

  • Improvements
    • Interactive example controls now persist across navigation and refreshes; your adjustments (animations, axis ticks, bar settings, etc.) are restored when you return within the same session.
    • Examples initialize with previously saved control values so previews reflect your last-used settings on load.

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4acfc345-843e-41f0-b1ce-53c784989eba

📥 Commits

Reviewing files that changed from the base of the PR and between ae5a031 and cf6121b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • www/src/components/CodeEditorWithPreview.tsx
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • www/src/components/CodeEditorWithPreview.tsx

Walkthrough

Adds 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 sessionStoreValues prop; Controls components initialize from that value when present.

Changes

Cohort / File(s) Summary
Session Storage Integration
www/src/components/CodeEditorWithPreview.tsx
Replaces local useState with useSessionStorageState (keyed by encoded stackBlitzTitle) and passes sessionStoreValues to rendered Controls.
Type Definition
www/src/docs/exampleComponents/types.ts
Updates ChartExample<ControlsType> so Controls receives sessionStoreValues: ControlsType | null alongside onChange.
Controls Components
www/src/components/GuideView/Animations/AnimationsExample.tsx, www/src/components/GuideView/AxisTicks/CustomAxisTicks.tsx, www/src/components/GuideView/AxisTicks/NiceTicksPlayground.tsx, www/src/components/GuideView/BarAlign/CustomBandScaleExample.tsx
Each Controls component gains a sessionStoreValues prop and initializes internal state from sessionStoreValues ?? defaultState.
Dev Dependency Bump
package.json
Bumps devDependency @recharts/devtools from ^0.0.11^0.0.12.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding session storage support for controls state in the documentation/website components.
Description check ✅ Passed The description is comprehensive and complete, covering motivation (issue #7277), technical approach, affected components, and supporting changes with relevant code references.
Linked Issues check ✅ Passed The PR fully addresses issue #7277 by implementing session storage for controls state, keyed per example, allowing user choices to persist across page reloads within a session.
Out of Scope Changes check ✅ Passed All changes are in-scope: the PR modifies only controls-related components and their signatures to support session storage, plus a devtools dependency bump needed for the implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch session-storage-controls

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
www/src/components/CodeEditorWithPreview.tsx (2)

95-95: Add an explicit generic to useSessionStorageState for proper type inference.

Without an explicit generic, useSessionStorageState(encodeURIComponent(stackBlitzTitle), null) will infer the state type as null from the initial value, making controlsState typed as null instead of T | null. This breaks type safety when passing controlsState to the Controls component (which expects sessionStoreValues: ControlsType | null at line 201) and to Component as componentProps (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 for useSessionStorageState from @recharts/devtools.

The file imports useSessionStorageState from @recharts/devtools/dist/hooks/useSessionStorageState (line 7), but this same file imports RechartsDevtoolsContext from 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 useSessionStorageState is 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/devtools as 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

📥 Commits

Reviewing files that changed from the base of the PR and between 839f5c5 and ae5a031.

📒 Files selected for processing (6)
  • www/src/components/CodeEditorWithPreview.tsx
  • www/src/components/GuideView/Animations/AnimationsExample.tsx
  • www/src/components/GuideView/AxisTicks/CustomAxisTicks.tsx
  • www/src/components/GuideView/AxisTicks/NiceTicksPlayground.tsx
  • www/src/components/GuideView/BarAlign/CustomBandScaleExample.tsx
  • www/src/docs/exampleComponents/types.ts

@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 17.14286% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.05%. Comparing base (839f5c5) to head (cf6121b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ents/GuideView/BarAlign/CustomBandScaleExample.tsx 7.14% 13 Missing ⚠️
...ponents/GuideView/Animations/AnimationsExample.tsx 16.66% 5 Missing ⚠️
...components/GuideView/AxisTicks/CustomAxisTicks.tsx 16.66% 5 Missing ⚠️
...onents/GuideView/AxisTicks/NiceTicksPlayground.tsx 16.66% 5 Missing ⚠️
www/src/components/CodeEditorWithPreview.tsx 66.66% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@github-actions

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek
PavelVanecek merged commit 349b5fd into main Apr 27, 2026
56 of 58 checks passed
@PavelVanecek
PavelVanecek deleted the session-storage-controls branch April 27, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session storage in website examples

2 participants