From 5afc5871276e0eb52e5bed1ebba5c90d3241e5fa Mon Sep 17 00:00:00 2001 From: Nanakusa <73281112+yofukashino@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:17:22 +0530 Subject: [PATCH] virtual-merge all return fix (#641) * fix * fix: filter virtualMerge keys only if its a store --------- Co-authored-by: Federico <38290480+FedeIlLeone@users.noreply.github.com> --- src/renderer/util.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/renderer/util.ts b/src/renderer/util.ts index b79a6ccc2..5818500e4 100644 --- a/src/renderer/util.ts +++ b/src/renderer/util.ts @@ -1,4 +1,4 @@ -import { React, channels, fluxDispatcher, guilds } from "@common"; +import { React, channels, flux, fluxDispatcher, guilds } from "@common"; import type { Fiber } from "react-reconciler"; import type { Jsonifiable } from "type-fest"; import type { ObjectExports } from "../types"; @@ -287,7 +287,17 @@ export function virtualMerge(...objects: O): ExtractObje if (method === "get" && args[0] === "all") { // Return function that returns all objects combined // For use in devtools to see everything available - return () => objects.reduce((acc, obj) => ({ ...acc, ...obj }), {}); + return () => + objects.reduce((acc: Record, obj: Record) => { + // Manually iterate over the property names of the object because the spread operator does not work with prototype objects, which are common for stores. + Object.getOwnPropertyNames(obj).forEach((key) => { + // Filter out keys that are common on all stores + if (!(obj instanceof flux.Store) || (key !== "initialize" && key !== "constructor")) { + acc[key] = obj[key]; + } + }); + return acc; + }, {}); } return Reflect[method]( findObjectByProp(args[0] as PropertyKey),