Skip to content

feat: store local-editor api keys in local storage#1260

Merged
briantstephan merged 1 commit into
2026-custom-components-templatesfrom
store-api-key
Jul 7, 2026
Merged

feat: store local-editor api keys in local storage#1260
briantstephan merged 1 commit into
2026-custom-components-templatesfrom
store-api-key

Conversation

@briantstephan

Copy link
Copy Markdown
Contributor

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.

@asanehisa asanehisa 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.

nice!

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This 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)
Loading

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,
Now tucked away in storage's cage,
Prompt and trim, then save it tight,
Mapbox and locations, stored just right!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: persisting local-editor API keys in local storage.
Description check ✅ Passed The description directly describes the same local storage persistence change and its manual test result.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch store-api-key

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.

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a930db9 and 22d51be.

📒 Files selected for processing (1)
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx

Comment thread packages/visual-editor/src/local-editor/LocalEditorShell.tsx
Comment thread packages/visual-editor/src/local-editor/LocalEditorShell.tsx
@briantstephan briantstephan merged commit 04689fb into 2026-custom-components-templates Jul 7, 2026
15 checks passed
@briantstephan briantstephan deleted the store-api-key branch July 7, 2026 19:00
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.

3 participants