feat: store local-editor api keys in local storage#1260
Conversation
WalkthroughThis change modifies LocalEditorShell.tsx to persist Mapbox and nearby-locations API keys in localStorage. It adds two storage-key constants and a readLocalStorageValue helper that reads and trims stored values, guarding against server-side execution. Component state for mapboxKey and nearbyLocationsKey is now initialized from localStorage instead of being empty. A new handleApiKeyUpdate callback centralizes prompting the user, trimming input, and writing to or removing from localStorage while updating state; the existing button click handlers are rewired to use this shared callback instead of inline window.prompt logic. Sequence Diagram(s)sequenceDiagram
participant User
participant Button
participant handleApiKeyUpdate
participant localStorage
User->>Button: Click Add/Update key
Button->>handleApiKeyUpdate: invoke(storageKey, setter)
handleApiKeyUpdate->>User: window.prompt for value
User-->>handleApiKeyUpdate: input value or cancel
alt value provided
handleApiKeyUpdate->>localStorage: setItem(trimmed value)
else value empty
handleApiKeyUpdate->>localStorage: removeItem
end
handleApiKeyUpdate->>Button: update state (mapboxKey/nearbyLocationsKey)
Related Issues: None found in provided context. Related PRs: None found in provided context. Suggested labels: enhancement, local-editor Suggested reviewers: None specified. 🐰 A key once lost with each new page, 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/visual-editor/src/local-editor/LocalEditorShell.tsx`:
- Around line 273-287: Guard the localStorage writes in the prompt handler
inside LocalEditorShell so unavailable storage cannot break the flow; both
window.localStorage.removeItem and window.localStorage.setItem may throw, which
can prevent setApiKey from running and leave state inconsistent. Wrap the
storage operations in the relevant branch logic around nextValue/trimmedValue
with error handling, and make sure setApiKey(undefined) and
setApiKey(trimmedValue) still execute even if storage access fails.
- Around line 488-495: Guard the localStorage access in readLocalStorageValue,
since it is used by the useState lazy initializer in LocalEditorShell and can
throw a SecurityError in blocked-storage/private-browsing environments. Update
the readLocalStorageValue helper to wrap window.localStorage.getItem in
try/catch and return undefined on failure, while keeping the existing undefined
return for non-browser environments and empty values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 35d2045c-2f07-4b22-ab59-53445078e6c2
📒 Files selected for processing (1)
packages/visual-editor/src/local-editor/LocalEditorShell.tsx
04689fb
into
2026-custom-components-templates
This stores the mapbox and nearby locations keys in local storage when using the local-editor so we don't need to re-enter them on reload.
Tested manually and confirmed that the keys persisted after restarting
npm run dev.