Files
AngeloooooandDraculabo 8ed4593f73 Refactor Gemini model display: filter old versions, group low/high pкo, and improve naming (#114)
* Refactor Gemini model display: filter old versions, group low/high pro, and improve naming

* Fix potential negative minutes and refine Gemini 3 Pro grouping logic based on PR feedback

* The account change process has been sped up

* Address PR review: enhance error message and parameterize polling interval in process handler

* Address PR review: fix potential race condition in database backup logic

* fix: prevent renderer white screen and harden sentry gating

* feat:  localize model labels

* chore: enable hoisted node-linker

* chore: ignore .agent/.claude/.codex in prettier

---------

Co-authored-by: Draculabo <[email protected]>
2026-02-19 19:37:30 +08:00

1.1 KiB

title, impact, impactDescription, tags
title impact impactDescription tags
Use SWR for Automatic Deduplication MEDIUM-HIGH automatic deduplication client, swr, deduplication, data-fetching

Use SWR for Automatic Deduplication

SWR enables request deduplication, caching, and revalidation across component instances.

Incorrect (no deduplication, each instance fetches):

function UserList() {
  const [users, setUsers] = useState([]);
  useEffect(() => {
    fetch('/api/users')
      .then((r) => r.json())
      .then(setUsers);
  }, []);
}

Correct (multiple instances share one request):

import useSWR from 'swr';

function UserList() {
  const { data: users } = useSWR('/api/users', fetcher);
}

For immutable data:

import { useImmutableSWR } from '@/lib/swr';

function StaticContent() {
  const { data } = useImmutableSWR('/api/config', fetcher);
}

For mutations:

import { useSWRMutation } from 'swr/mutation';

function UpdateButton() {
  const { trigger } = useSWRMutation('/api/user', updateUser);
  return <button onClick={() => trigger()}>Update</button>;
}

Reference: https://swr.vercel.app