I am using Zustand for state management (without any persistence options). I have a pretty simple store:
export const useStore = create<State>()(
devtools((set) => ({
map: null,
setMap: (map: Map) => set(() => ({ map })),
layer: null,
setLayer: (layer: Layer) => set(() => ({ layer })),
source: null,
setSource: (source: VectorSource) => set(() => ({ source })),
userRole: UserRole.EDITOR,
setUserRole: (role: UserRole) => set(() => ({ userRole: role })),
}))
);
In my app there is a switch which sets user role:
What I noticed is that in normal mode (even in production settings) changing this one simple variable is really slow. What is really interesting that in chrome's incognito mode it works flawlesly without any noticable delay - just instantly.
What may be causing it? For production mode in normal tab it is ~2 seconds. For production mode in incognito tab it is just instant.
Update:
map
I am holding in store is an OpenLayers map object.
After rewriting it to use context instead of zustand's store it works significantly faster. Still don't know why.