Reduce __NEXT_DATA__ size by removing content and author.commit properties from IconEntity (#846)

Reduces __NEXT_DATA__ size on main page by 127610 bytes by calculating `content` from `src` property and removing `commit` data altogether.

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
Wojciech Maj
2022-10-27 08:17:25 +02:00
committed by GitHub
co-authored by Eric Fennis
parent 01e11a61f8
commit eb706417e6
9 changed files with 22 additions and 38 deletions
+5 -5
View File
@@ -6,7 +6,7 @@ import {useContext, useEffect, useRef} from "react";
import {IconStyleContext} from "./CustomizeIconContext";
import {IconWrapper} from "./IconWrapper";
import ModifiedTooltip from "./ModifiedTooltip";
import { IconData } from "../lib/icons";
import { IconEntity } from "../types";
type IconDownload = {
src: string;
@@ -16,7 +16,7 @@ type IconDownload = {
interface IconDetailOverlayProps {
open: boolean
close: () => void
icon?: IconData
icon?: IconEntity
}
const IconDetailOverlay = ({ open = true, close, icon }: IconDetailOverlayProps) => {
@@ -152,7 +152,7 @@ const IconDetailOverlay = ({ open = true, close, icon }: IconDetailOverlayProps)
className="icon-large"
>
<IconWrapper
content={icon.content}
src={icon.src}
stroke={color}
strokeWidth={strokeWidth}
height={size}
@@ -229,8 +229,8 @@ const IconDetailOverlay = ({ open = true, close, icon }: IconDetailOverlayProps)
</Heading>
<AvatarGroup size="md">
{ icon.contributors.map((commit, index) => (
<Link href={`https://github.com/${commit.author}`} isExternal key={`${index}_${commit.commit}`}>
<Tooltip label={commit.author} key={commit.commit}>
<Link href={`https://github.com/${commit.author}`} isExternal key={`${index}_${commit.author}`}>
<Tooltip label={commit.author} key={commit.author}>
<Avatar name={commit.author} src={`https://github.com/${commit.author}.png?size=88`} />
</Tooltip>
</Link>
+1 -1
View File
@@ -2,8 +2,8 @@ import { Grid } from '@chakra-ui/react';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { memo } from 'react';
import { IconEntity } from '../types';
import IconListItem from './IconListItem';
import { IconEntity } from '../types';
interface IconListProps {
icons: IconEntity[];
+3 -6
View File
@@ -1,19 +1,16 @@
import { Button, ButtonProps, Flex, Text, useToast } from '@chakra-ui/react';
import download from 'downloadjs';
import { memo } from 'react';
import { Contributor } from '../lib/fetchAllContributors';
import { useCustomizeIconContext } from './CustomizeIconContext';
import { IconWrapper } from './IconWrapper';
interface IconListItemProps {
name: string;
content: string;
contributors: Contributor[]
src: string;
onClick?: ButtonProps['onClick']
src: string;
}
const IconListItem = ({ name, content, onClick, src: svg }: IconListItemProps) => {
const IconListItem = ({ name, onClick, src: svg }: IconListItemProps) => {
const toast = useToast();
const { color, size, strokeWidth, iconsRef } = useCustomizeIconContext();
@@ -53,7 +50,7 @@ const IconListItem = ({ name, content, onClick, src: svg }: IconListItemProps) =
<Flex direction="column" align="center" justify="stretch" width="100%" gap={4}>
<Flex flex={2} flexBasis="100%" minHeight={10} align="flex-end">
<IconWrapper
content={content}
src={svg}
stroke={color}
strokeWidth={strokeWidth}
height={size}
+1 -1
View File
@@ -1,9 +1,9 @@
import { Box, Text } from '@chakra-ui/react';
import React, { useState } from 'react';
import useSearch from '../lib/useSearch';
import { IconEntity } from '../types';
import IconList from './IconList';
import { SearchInput } from './SearchInput';
import { IconEntity } from '../types';
interface IconOverviewProps {
data: IconEntity[];
+3 -2
View File
@@ -1,7 +1,7 @@
import { forwardRef, SVGProps } from 'react';
interface IconWrapperProps extends SVGProps<SVGSVGElement> {
content: string;
src: string;
}
export const IconWrapper = forwardRef<SVGSVGElement, IconWrapperProps>((props, ref) => {
@@ -17,11 +17,12 @@ export const IconWrapper = forwardRef<SVGSVGElement, IconWrapperProps>((props, r
strokeLinejoin: 'round',
};
const { content, ...rest } = props;
const { src, ...rest } = props;
const attrs = {
...defaultAttrs,
...rest,
};
const content = src.replace(/<svg[^>]*>|<\/svg>/g, '');
return <svg ref={ref} {...attrs} dangerouslySetInnerHTML={{ __html: content }} />;
});
+2 -7
View File
@@ -1,11 +1,7 @@
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
export interface Contributor {
author: string
commit: string
}
import { Contributor } from '../types';
const IGNORE_COMMIT_MESSAGES = ['fork', 'optimize'];
@@ -54,9 +50,8 @@ export const filterCommits = (commits) =>
!IGNORE_COMMIT_MESSAGES.some(ignoreItem =>
commit.message.toLowerCase().includes(ignoreItem),
))
.map(({ sha, author }) => ({
.map(({ author }) => ({
author: author && author.login ? author.login : null,
commit: sha,
}))
.filter(({ author }, index, self) => self.findIndex((commit) => commit.author === author) === index);
+4 -12
View File
@@ -2,7 +2,8 @@ import fs from "fs";
import path from "path";
import { parseSync, stringify } from 'svgson';
import tags from '../../../tags.json';
import { Contributor, getContributors } from "./fetchAllContributors";
import { IconEntity } from "../types";
import { getContributors } from "./fetchAllContributors";
const directory = path.join(process.cwd(), "../icons");
@@ -28,20 +29,11 @@ export async function getData(name: string) {
name,
tags: tags[name] || [],
contributors,
src: fileContent,
content: svgContent
src: fileContent
};
}
export interface IconData {
name: string
tags: string[]
contributors: Contributor[]
src: string
content: string
}
export async function getAllData(): Promise<IconData[]> {
export async function getAllData(): Promise<IconEntity[]> {
const names = getAllNames();
return Promise.all(names.map((name) => getData(name)));
+3 -2
View File
@@ -1,5 +1,5 @@
import Layout from '../components/Layout';
import { getAllData, IconData } from '../lib/icons';
import { getAllData } from '../lib/icons';
import IconOverview from '../components/IconOverview';
import IconDetailOverlay from '../components/IconDetailOverlay';
@@ -8,9 +8,10 @@ import Header from '../components/Header';
import MobileMenu from '../components/MobileMenu';
import { useMemo } from 'react';
import { GetStaticPropsResult, NextPage } from 'next';
import { IconEntity } from '../types';
interface HomePageProps {
data: IconData[]
data: IconEntity[]
}
const HomePage: NextPage<HomePageProps> = ({ data }) => {
-2
View File
@@ -1,5 +1,4 @@
export interface IconEntity {
content: string;
contributors: Contributor[];
name: string;
src: string;
@@ -8,5 +7,4 @@ export interface IconEntity {
export interface Contributor {
author: string;
commit: string;
}