Skip to content

fix: prompt saving issue #102#103

Merged
wakenmeng merged 1 commit into
mainfrom
fix/prompt-persistence-bug
Mar 4, 2026
Merged

fix: prompt saving issue #102#103
wakenmeng merged 1 commit into
mainfrom
fix/prompt-persistence-bug

Conversation

@wakenmeng

Copy link
Copy Markdown
Collaborator

Fix: Prompt instructions reverting to defaults after editing (#102)

Problem

Users reported that after updating prompt instructions, changes would not persist — they would revert
to the old/default instructions on next load.

Root Cause

In ThePopupBox.vue, the save and delete handlers mutated the prompt arrays in-place rather than
creating new references:

  const {AskedQuestionPrompts} = config.value
  AskedQuestionPrompts[selectedPrompt.index] = prompt  // mutates existing array
  store.updateConfig({AskedQuestionPrompts})            // same reference — storage skips write

Since updateConfig uses a shallow spread ({...storedConfig, ...newConfig}) and the array reference is
unchanged, @plasmohq/storage does not detect a change and skips persisting it. On next load, the
previously stored (old) value is restored.

Additionally, store.ts initialized config with ref(defaultConfig) — sharing the same object reference
as the module-level default, meaning in-place mutations could also corrupt the defaults themselves.

Changes

  • src/csui/Index/ThePopupBox/ThePopupBox.vue
    • handleSavePrompt: use spread ([...arr]) to create a new array instead of mutating in-place
    • handleDeletePrompt: use .filter() instead of .splice() to produce a new array
  • src/stores/store.ts
    • Deep-copy defaultConfig on initialization to prevent shared references

@wakenmeng wakenmeng merged commit 2b4780b into main Mar 4, 2026
1 check failed
@wakenmeng wakenmeng deleted the fix/prompt-persistence-bug branch March 4, 2026 14:55
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.

1 participant