From ef5082057f82dad0e18b289011ec283d4fc8b1a1 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Wed, 5 Mar 2025 11:15:38 +0100 Subject: [PATCH] fix(vue): Attach Pinia state only once per event --- packages/vue/src/pinia.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/vue/src/pinia.ts b/packages/vue/src/pinia.ts index 2448a30c4f08..c7448deaeed1 100644 --- a/packages/vue/src/pinia.ts +++ b/packages/vue/src/pinia.ts @@ -45,13 +45,20 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi const timestamp = new Date().toTimeString().split(' ')[0]; const filename = `pinia_state_all_stores_${timestamp}.json`; - hint.attachments = [ - ...(hint.attachments || []), - { - filename, - data: JSON.stringify(getAllStoreStates()), - }, - ]; + // event processor runs for each pinia store - attachment should only be added once per event + const hasExistingPiniaStateAttachment = hint.attachments?.some(attachment => + attachment.filename.startsWith('pinia_state_all_stores_'), + ); + + if (!hasExistingPiniaStateAttachment) { + hint.attachments = [ + ...(hint.attachments || []), + { + filename, + data: JSON.stringify(getAllStoreStates()), + }, + ]; + } } catch (_) { // empty }