⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
memoize components and increase performance
daniel31x13f30bf63c242c
diff --git a/apps/web/components/LinkListOptions.tsx b/apps/web/components/LinkListOptions.tsxindex 9090d2af..15e67607 100644--- a/apps/web/components/LinkListOptions.tsx+++ b/apps/web/components/LinkListOptions.tsx@@ -45,13 +45,8 @@ const LinkListOptions = ({setEditMode,links,}: Props) => {- const {- selectedIds,- setSelected,- clearSelected,- isSelected,- selectionCount,- } = useLinkStore();+ const { selectedIds, setSelected, clearSelected, selectionCount } =+ useLinkStore();const deleteLinksById = useBulkDeleteLinks();const refreshPreservations = useArchiveAction();diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsxindex a77bfa27..ea5a4747 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx@@ -3,7 +3,7 @@ import {CollectionIncludingMembersAndLinkCount,LinkIncludingShortenedCollectionAndTags,} from "@linkwarden/types";-import { useRef, useState } from "react";+import React, { useRef, useState } from "react";import unescapeString from "@/lib/client/unescapeString";import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";@@ -38,7 +38,7 @@ type Props = {editMode?: boolean;};-export default function LinkCard({+function LinkCard({link,collection,isPublicRoute,@@ -184,3 +184,5 @@ export default function LinkCard({</div>);}++export default React.memo(LinkCard);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCollection.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCollection.tsxindex e47a5cbc..18fc6795 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkCollection.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkCollection.tsx@@ -5,10 +5,9 @@ import {} from "@linkwarden/types";import { IconWeight } from "@phosphor-icons/react";import Link from "next/link";-import { useRouter } from "next/router";import React from "react";-export default function LinkCollection({+function LinkCollection({link,collection,isPublicRoute,@@ -45,3 +44,5 @@ export default function LinkCollection({</>) : null;}++export default React.memo(LinkCollection);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkDate.tsx b/apps/web/components/LinkViews/LinkComponents/LinkDate.tsxindex 5bce1de0..0ea920fe 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkDate.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkDate.tsx@@ -1,11 +1,7 @@import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import React from "react";-export default function LinkDate({- link,-}: {- link: LinkIncludingShortenedCollectionAndTags;-}) {+function LinkDate({ link }: { link: LinkIncludingShortenedCollectionAndTags }) {const formattedDate = new Date((link.importDate || link.createdAt) as string).toLocaleString("en-US", {@@ -21,3 +17,5 @@ export default function LinkDate({</div>);}++export default React.memo(LinkDate);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkIcon.tsx b/apps/web/components/LinkViews/LinkComponents/LinkIcon.tsxindex b00027af..ce2f965f 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkIcon.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkIcon.tsx@@ -7,7 +7,7 @@ import { IconWeight } from "@phosphor-icons/react";import clsx from "clsx";import oklchVariableToHex from "@/lib/client/oklchVariableToHex";-export default function LinkIcon({+function LinkIcon({link,className,hideBackground,@@ -104,3 +104,5 @@ const LinkPlaceholderIcon = ({</div>);};++export default React.memo(LinkIcon);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsxindex acf3b717..bb35b5dc 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx@@ -2,7 +2,7 @@ import {CollectionIncludingMembersAndLinkCount,LinkIncludingShortenedCollectionAndTags,} from "@linkwarden/types";-import { useState } from "react";+import React, { useState } from "react";import unescapeString from "@/lib/client/unescapeString";import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";@@ -33,7 +33,7 @@ type Props = {editMode?: boolean;};-export default function LinkList({+function LinkList({link,collection,isPublicRoute,@@ -137,3 +137,5 @@ export default function LinkList({</>);}++export default React.memo(LinkList);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsxindex fc083b54..affa4d97 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx@@ -3,7 +3,7 @@ import {CollectionIncludingMembersAndLinkCount,LinkIncludingShortenedCollectionAndTags,} from "@linkwarden/types";-import { useRef, useState } from "react";+import React, { useRef, useState } from "react";import unescapeString from "@/lib/client/unescapeString";import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";@@ -41,7 +41,7 @@ type Props = {editMode?: boolean;};-export default function LinkMasonry({+function LinkMasonry({link,collection,isPublicRoute,@@ -202,3 +202,5 @@ export default function LinkMasonry({</div>);}++export default React.memo(LinkMasonry);diff --git a/apps/web/components/LinkViews/LinkComponents/LinkTypeBadge.tsx b/apps/web/components/LinkViews/LinkComponents/LinkTypeBadge.tsxindex 9d2c45ee..e5fc52ca 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkTypeBadge.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkTypeBadge.tsx@@ -1,8 +1,8 @@import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import Link from "next/link";-import { useEffect, useState } from "react";+import React, { useEffect, useState } from "react";-export default function LinkTypeBadge({+function LinkTypeBadge({link,}: {link: LinkIncludingShortenedCollectionAndTags;@@ -50,3 +50,5 @@ export default function LinkTypeBadge({</div>);}++export default React.memo(LinkTypeBadge);diff --git a/apps/web/components/LinkViews/Links.tsx b/apps/web/components/LinkViews/Links.tsxindex 6391caf8..ec170457 100644--- a/apps/web/components/LinkViews/Links.tsx+++ b/apps/web/components/LinkViews/Links.tsx@@ -374,15 +374,17 @@ export default function Links({const isPublicRoute = router.pathname.startsWith("/public") ? true : false;useEffect(() => {- if (- inView &&- !useData.isFetching &&- useData?.fetchNextPage &&- useData?.hasNextPage- ) {- useData.fetchNextPage();- }- }, [useData, inView]);+ if (!inView) return;+ if (!useData.hasNextPage) return;+ if (useData.isFetchingNextPage) return;++ useData.fetchNextPage();+ }, [+ inView,+ useData.hasNextPage,+ useData.isFetchingNextPage,+ useData.fetchNextPage,+ ]);const { data: collections = [] } = useCollections();diff --git a/apps/web/components/Sidebar.tsx b/apps/web/components/Sidebar.tsxindex 1a497a41..ff5e85c5 100644--- a/apps/web/components/Sidebar.tsx+++ b/apps/web/components/Sidebar.tsx@@ -6,7 +6,7 @@ import CollectionListing from "@/components/CollectionListing";import { useTranslation } from "next-i18next";import { useCollections } from "@linkwarden/router/collections";import { useTags } from "@linkwarden/router/tags";-import { TagListing } from "./TagListing";+import TagListing from "./TagListing";import { Button } from "./ui/button";import { useUser } from "@linkwarden/router/user";import Image from "next/image";diff --git a/apps/web/components/TagListing.tsx b/apps/web/components/TagListing.tsxindex 5be097c4..368f1bdb 100644--- a/apps/web/components/TagListing.tsx+++ b/apps/web/components/TagListing.tsx@@ -9,7 +9,8 @@ interface TagListingProps {tags: Tag[];active?: string;}-export function TagListing({ tags, active }: TagListingProps) {++export default function TagListing({ tags, active }: TagListingProps) {const { active: droppableActive } = useDndContext();const { t } = useTranslation();diff --git a/packages/router/links.tsx b/packages/router/links.tsxindex 8367e23c..c8bbf80c 100644--- a/packages/router/links.tsx+++ b/packages/router/links.tsx@@ -28,15 +28,13 @@ const useLinks = (params: LinkRequestQuery = {}, auth?: MobileAuth) => {0;const queryString = useMemo(() => {- const queryParamsObject: LinkRequestQuery = {+ return buildQueryString({sort,collectionId: params.collectionId,tagId: params.tagId,pinnedOnly: params.pinnedOnly ?? undefined,searchQueryString: params.searchQueryString,- };-- return buildQueryString(queryParamsObject);+ });}, [sort,params.collectionId,@@ -45,17 +43,15 @@ const useLinks = (params: LinkRequestQuery = {}, auth?: MobileAuth) => {params.searchQueryString,]);- const { data, ...rest } = useFetchLinks(queryString, auth);+ const query = useFetchLinks(queryString, auth);const links = useMemo(() => {- return data?.pages?.flatMap((page) => page?.links ?? []) ?? [];- }, [data?.pages.at(-1)?.nextCursor]);-- const memoizedData = useMemo(() => ({ ...data, ...rest }), [data, rest]);+ return query.data?.pages?.flatMap((p) => p.links ?? []) ?? [];+ }, [query.dataUpdatedAt]);return {links,- data: memoizedData,+ data: query,};};