Bug report
Description / Observed Behavior
When using SWR with data returned as a Map, calling mutate with an updater function that returns a new Map instance updates the cache value, but the component does not re-render automatically.
In my repro:
- mutate callback runs
- the Map entry value is updated using a copy-on-write approach
- logs confirm updated data
- UI remains stale until a manual re-render is triggered
This appears to happen only when the SWR data type is Map. If the same data is represented as a plain object/array, re-render works as expected.
Also, after discussing the issue with Copilot, it identified that SWR uses the dequal library to compare previous and next data, and dequal currently does not support Map comparisons for this scenario, which may explain why SWR does not detect the change.
Expected Behavior
SWR should trigger a re-render when mutate returns an entirely new Map, more so if it has with different values.
Repro Steps / Code Example
- Create an SWR hook where fetcher returns a Map.
- Render a value from that Map.
- Call mutate with an updater function that:
- clones the Map
- updates one entry
- returns the new Map
- Observe that the mutate callback runs and cache content changes in logs.