Skip to content

Commit e598de7

Browse files
perf: only send necessary data to client (#85)
* fix(components/tweet): remove `setActiveTweet` prop * wip: only send necessary data to client * fix: use native `bigint` on server * fix: address typescript build errors * deps: replace `json-bigint` with `json-bigint-patch` Temporary fix until sidorares/json-bigint#77 is merged. * refactor(app/json): remove unused remix wrappers * fix(types): make `liked` and `retweeted` booleans * wip(utils.server): use `json-bigint-patch` for now Replace `json-bigint` until sidorares/json-bigint#77 is merged. * wip(sync/$tweet): invalidate cached user res
1 parent 4f4e3d2 commit e598de7

31 files changed

+226
-321
lines changed
-2.93 KB
Binary file not shown.
-80.5 KB
Binary file not shown.
-13.3 KB
Binary file not shown.
Binary file not shown.

.yarn/install-state.gz

-1.15 KB
Binary file not shown.

app/changelog.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { resolve } from 'path';
33

44
import type { LoaderFunction } from 'remix';
55
import { bundleMDX } from 'mdx-bundler';
6+
import { json } from 'remix';
67

7-
import { json } from '~/json';
88
import { log } from '~/utils.server';
99

1010
type Meta = { date: string; author: string };

app/components/article.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { memo, useMemo, useRef, useState } from 'react';
44
import { useLocation, useNavigate } from 'remix';
55
import { dequal } from 'dequal/lite';
66

7-
import type { Article } from '~/types';
7+
import type { ArticleJS } from '~/types';
88
import { TimeAgo } from '~/components/timeago';
99
import { substr } from '~/utils';
1010

11-
export function ArticleContent({ article }: { article: Article }) {
11+
export function ArticleContent({ article }: { article: ArticleJS }) {
1212
const earliestTweet = useMemo(
1313
() =>
1414
Array.from(article.tweets).sort(
@@ -61,9 +61,8 @@ export function ArticleContent({ article }: { article: Article }) {
6161
<span className='flex flex-row-reverse justify-end -ml-[2px] mr-0.5'>
6262
{Array.from(article.tweets)
6363
.sort((a, b) =>
64-
b.score && a.score
65-
? Number(b.score.attention_score) -
66-
Number(a.score.attention_score)
64+
b.attention_score && a.attention_score
65+
? b.attention_score - a.attention_score
6766
: 0
6867
)
6968
.slice(0, 10)
@@ -103,7 +102,7 @@ export function ArticleContent({ article }: { article: Article }) {
103102
}
104103

105104
export type ArticleItemProps = {
106-
article: Article;
105+
article: ArticleJS;
107106
setHover: Dispatch<SetStateAction<{ y: number; height: number } | undefined>>;
108107
};
109108
function ArticleItem({ article, setHover }: ArticleItemProps) {

app/components/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
NavLink,
55
useFetcher,
66
useLocation,
7+
useMatches,
78
useResolvedPath,
89
useTransition,
910
} from 'remix';
@@ -19,7 +20,6 @@ import OpenInNewIcon from '~/icons/open-in-new';
1920
import Switcher from '~/components/switcher';
2021
import Sync from '~/components/sync';
2122
import ThemeSwitcher from '~/components/theme-switcher';
22-
import { useMatches } from '~/json';
2323

2424
function PageSwitcher() {
2525
const { pathname } = useLocation();

app/components/profile.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import OpenInNewIcon from '~/icons/open-in-new';
2+
import type { UserJS } from '~/types';
23
import VerifiedIcon from '~/icons/verified';
3-
import type { UserFull } from '~/types';
44
import { num } from '~/utils';
55

66
export default function Profile({
77
name,
88
username,
99
verified,
10-
description,
1110
html,
1211
following_count,
1312
followers_count,
1413
profile_image_url,
15-
}: UserFull) {
14+
}: UserJS) {
1615
return (
1716
<article className='peer-hover:opacity-100 peer-hover:visible hover:opacity-100 hover:visible peer-active:opacity-100 peer-active:visible active:opacity-100 active:visible shadow-xl invisible opacity-0 transition-[opacity,visibility] absolute top-7 left-2 z-10 hover:delay-500 peer-hover:delay-500 active:delay-500 peer-active:delay-500 duration-300 ease-in-out w-72 p-3 border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 rounded-lg'>
1817
<div className='absolute -top-2.5 left-0 right-0 h-2.5 transparent' />
@@ -83,12 +82,7 @@ export default function Profile({
8382
</a>
8483
</div>
8584
</header>
86-
<p
87-
className='my-3'
88-
dangerouslySetInnerHTML={{
89-
__html: html ?? description ?? '',
90-
}}
91-
/>
85+
<p className='my-3' dangerouslySetInnerHTML={{ __html: html ?? '' }} />
9286
<p>
9387
<a
9488
className='hover:underline mr-3'

app/components/sync.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useContext, useEffect, useState } from 'react';
2-
import { useFetcher, useLocation } from 'remix';
2+
import { useFetcher, useLocation, useMatches } from 'remix';
33

44
import BoltIcon from '~/icons/bolt';
55
import { ErrorContext } from '~/error';
66
import ErrorIcon from '~/icons/error';
77
import type { LoaderData } from '~/root';
88
import SyncIcon from '~/icons/sync';
99
import { TimeAgo } from '~/components/timeago';
10-
import { useMatches } from '~/json';
1110

1211
export default function Sync() {
1312
const user = (useMatches()[0].data as LoaderData | undefined)?.user;

0 commit comments

Comments
 (0)