From 76af7ccfec4a53baff7545e6d6ef7f45533a47dd Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 01:06:17 +0900 Subject: [PATCH 01/21] fix: ini site dynamic --- app/[locale]/clock/page.tsx | 7 ++ app/[locale]/journal/page.tsx | 7 ++ app/layout.tsx | 1 - next.config.mjs | 6 +- package.json | 4 +- pnpm-lock.yaml | 188 +++++++++++++++++----------------- src/components/clock.tsx | 61 ----------- 7 files changed, 115 insertions(+), 159 deletions(-) delete mode 100644 src/components/clock.tsx diff --git a/app/[locale]/clock/page.tsx b/app/[locale]/clock/page.tsx index d6ddea60..754b0b25 100644 --- a/app/[locale]/clock/page.tsx +++ b/app/[locale]/clock/page.tsx @@ -15,6 +15,7 @@ import { Clock } from "@/sections/clock"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -47,6 +48,12 @@ export async function generateMetadata({ export default async function ClockPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/journal/page.tsx b/app/[locale]/journal/page.tsx index 75bcb920..9fd51630 100644 --- a/app/[locale]/journal/page.tsx +++ b/app/[locale]/journal/page.tsx @@ -21,6 +21,7 @@ import { } from "@tanstack/react-query"; import type { Metadata } from "next"; import { getTranslations } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -52,6 +53,12 @@ export async function generateMetadata({ // biome-ignore lint/style/noDefaultExport: // biome-ignore lint/suspicious/useAwait: export default async function JournalPage() { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // Actions // --------------------------------------------------------------------------- diff --git a/app/layout.tsx b/app/layout.tsx index 587ce3b6..d53134b7 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -140,4 +140,3 @@ export default function RootLayout({ children }: RootLayoutProps) { // biome-ignore lint/style/useNamingConvention: export const experimental_ppr = true; -export const revalidate = 300; diff --git a/next.config.mjs b/next.config.mjs index 5e73f529..a7ae4772 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -30,12 +30,16 @@ const nextConfig = { eslint: { ignoreDuringBuilds: true, }, + experimental: { + ppr: "incremental", + // biome-ignore lint/style/useNamingConvention: + dynamicIO: true, + }, logging: { fetches: { fullUrl: true, }, }, - ppr: "incremental", images: { remotePatterns: [ { diff --git a/package.json b/package.json index da5137e1..cbfdc142 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@lightdotso/svg": "^0.0.16", "@lightdotso/tailwindcss": "^3.1.9", "@lightdotso/ui": "^3.1.20", - "@next/bundle-analyzer": "^15.0.0", + "@next/bundle-analyzer": "^15.0.2-canary.7", "@notionhq/client": "^2.2.15", "@radix-ui/react-accordion": "^1.2.1", "@radix-ui/react-alert-dialog": "^1.0.5", @@ -73,7 +73,7 @@ "input-otp": "^1.2.4", "jotai": "^2.10.1", "lucide-react": "^0.453.0", - "next": "15.0.0", + "next": "15.0.2-canary.7", "next-intl": "^3.22.0", "next-themes": "^0.3.0", "open-graph-scraper": "^6.8.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 126adeef..4c64f00d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^3.1.20 version: 3.1.20(@babel/core@7.25.2)(@emotion/is-prop-valid@1.3.0)(@tanstack/query-core@5.59.13)(@types/react-dom@18.3.1)(@types/react@18.3.11)(@upstash/redis@1.34.3)(blurhash@2.0.5)(bufferutil@4.0.8)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react-is@19.0.0-rc-65a56d0e-20241020)(react-native@0.75.2(@babel/core@7.25.2)(@babel/preset-env@7.25.4(@babel/core@7.25.2))(@types/react@18.3.11)(bufferutil@4.0.8)(react@19.0.0-rc-65a56d0e-20241020)(typescript@5.6.3)(utf-8-validate@5.0.10))(react@19.0.0-rc-65a56d0e-20241020)(tailwindcss@3.4.14(ts-node@10.9.1(@types/node@22.7.7)(typescript@5.6.3)))(typescript@5.6.3)(utf-8-validate@5.0.10) '@next/bundle-analyzer': - specifier: ^15.0.0 - version: 15.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) + specifier: ^15.0.2-canary.7 + version: 15.0.2-canary.7(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@notionhq/client': specifier: ^2.2.15 version: 2.2.15 @@ -136,10 +136,10 @@ importers: version: 1.34.3 '@vercel/analytics': specifier: ^1.3.1 - version: 1.3.1(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + version: 1.3.1(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) '@vercel/speed-insights': specifier: ^1.0.12 - version: 1.0.12(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + version: 1.0.12(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) class-variance-authority: specifier: ^0.7.0 version: 0.7.0 @@ -165,11 +165,11 @@ importers: specifier: ^0.453.0 version: 0.453.0(react@19.0.0-rc-65a56d0e-20241020) next: - specifier: 15.0.0 - version: 15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + specifier: 15.0.2-canary.7 + version: 15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) next-intl: specifier: ^3.22.0 - version: 3.22.0(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + version: 3.22.0(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) next-themes: specifier: ^0.3.0 version: 0.3.0(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) @@ -1642,20 +1642,14 @@ packages: resolution: {integrity: sha512-z10PF9JV6SbjFq+/rYabM+8CVlMokgl8RFGvieSGNTmrkQanfHn+15XBrhG3BgUfvmTeSeyShfOHpG0i9zEdcg==} deprecated: Motion One for Vue is deprecated. Use Oku Motion instead https://oku-ui.com/motion - '@next/bundle-analyzer@15.0.0': - resolution: {integrity: sha512-FGkM4yaHe+BadSJvcI5C4hV00i7MSbrc7esqjICxN1tEttDFPzxrXHb5W0DUJGcbnEsei0psdQMvbu4Bz8wS0Q==} - - '@next/env@15.0.0': - resolution: {integrity: sha512-Mcv8ZVmEgTO3bePiH/eJ7zHqQEs2gCqZ0UId2RxHmDDc7Pw6ngfSrOFlxG8XDpaex+n2G+TKPsQAf28MO+88Gw==} + '@next/bundle-analyzer@15.0.2-canary.7': + resolution: {integrity: sha512-4hU7NERRg7htMalUYIuLS0xtMgE8GyUckIfXIDogXjO7IuM8B5q3A2FF7TxUH3GBLqaf6f6380O1Kjp7+vTbzg==} '@next/env@15.0.0-canary.146': resolution: {integrity: sha512-C8F8PibNFcO/YsFVN9KI5Gn+2Cq4+zzu/erILyNBXHdyLJ1qnvbF1rQmodgCps/FrKhwfQRBS5WnVUuavbZPhA==} - '@next/swc-darwin-arm64@15.0.0': - resolution: {integrity: sha512-Gjgs3N7cFa40a9QT9AEHnuGKq69/bvIOn0SLGDV+ordq07QOP4k1GDOVedMHEjVeqy1HBLkL8rXnNTuMZIv79A==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] + '@next/env@15.0.2-canary.7': + resolution: {integrity: sha512-1ALOxlNpkmBuSI9h/JLWdTWb4Bs5vQYk1xWaQS9y98W03CJwxhy5IJINkhhGZz3+lS2lbKtbR2EHxDxO0V65Rw==} '@next/swc-darwin-arm64@15.0.0-canary.146': resolution: {integrity: sha512-QouMxXA7Zvb6A+x6jtuR2H2Bifhf6Sc/XS/Ft1rk7toPD8BzMU7ebm2gDUujWjDvgffBikgbcWSO61WpYe8Z+g==} @@ -1663,10 +1657,10 @@ packages: cpu: [arm64] os: [darwin] - '@next/swc-darwin-x64@15.0.0': - resolution: {integrity: sha512-BUtTvY5u9s5berAuOEydAUlVMjnl6ZjXS+xVrMt317mglYZ2XXjY8YRDCaz9vYMjBNPXH8Gh75Cew5CMdVbWTw==} + '@next/swc-darwin-arm64@15.0.2-canary.7': + resolution: {integrity: sha512-ctOho5J4J1liF/zJOwbIeVd8JXDRrEU1sz6HSYawslTPn4VxorZZjx0iBCfff2LFFE0Cz8+A1u6MCK8jaNy7Zw==} engines: {node: '>= 10'} - cpu: [x64] + cpu: [arm64] os: [darwin] '@next/swc-darwin-x64@15.0.0-canary.146': @@ -1675,11 +1669,11 @@ packages: cpu: [x64] os: [darwin] - '@next/swc-linux-arm64-gnu@15.0.0': - resolution: {integrity: sha512-sbCoEpuWUBpYoLSgYrk0CkBv8RFv4ZlPxbwqRHr/BWDBJppTBtF53EvsntlfzQJ9fosYX12xnS6ltxYYwsMBjg==} + '@next/swc-darwin-x64@15.0.2-canary.7': + resolution: {integrity: sha512-hnO4j1HtdHMJhyhqxirw+5U+wqzSENyrVt/13+jMCpLi8o/LUEMVJYFGFEteRyoECLqfeqnB5eIwBl24K02j8A==} engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] + cpu: [x64] + os: [darwin] '@next/swc-linux-arm64-gnu@15.0.0-canary.146': resolution: {integrity: sha512-BvxOO8pyOzWaNNLGcoJtUnyYzJfnhTzLvIscA+ems8aAXQs+kVQEaNLGL08337X3kkZswOfZ0hmgGg2zoPGu3w==} @@ -1687,8 +1681,8 @@ packages: cpu: [arm64] os: [linux] - '@next/swc-linux-arm64-musl@15.0.0': - resolution: {integrity: sha512-JAw84qfL81aQCirXKP4VkgmhiDpXJupGjt8ITUkHrOVlBd+3h5kjfPva5M0tH2F9KKSgJQHEo3F5S5tDH9h2ww==} + '@next/swc-linux-arm64-gnu@15.0.2-canary.7': + resolution: {integrity: sha512-OYwxKzJbwIUQ3S5yMekmyO1w6sQ6pp3c3V7+KQu395LOr1FHARKGMZ0iYMONhCtrY3Y1xRnkRd/y3FaA2BHJ1w==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -1699,10 +1693,10 @@ packages: cpu: [arm64] os: [linux] - '@next/swc-linux-x64-gnu@15.0.0': - resolution: {integrity: sha512-r5Smd03PfxrGKMewdRf2RVNA1CU5l2rRlvZLQYZSv7FUsXD5bKEcOZ/6/98aqRwL7diXOwD8TCWJk1NbhATQHg==} + '@next/swc-linux-arm64-musl@15.0.2-canary.7': + resolution: {integrity: sha512-vS5jusPpM6fC+ysNGO34yUVIf8MUO9grXBFPGPUZPs+C0wPcrPDgs8cIni4W3atiRoFenVC0M+a2/+Y8/Axf6A==} engines: {node: '>= 10'} - cpu: [x64] + cpu: [arm64] os: [linux] '@next/swc-linux-x64-gnu@15.0.0-canary.146': @@ -1711,8 +1705,8 @@ packages: cpu: [x64] os: [linux] - '@next/swc-linux-x64-musl@15.0.0': - resolution: {integrity: sha512-fM6qocafz4Xjhh79CuoQNeGPhDHGBBUbdVtgNFJOUM8Ih5ZpaDZlTvqvqsh5IoO06CGomxurEGqGz/4eR/FaMQ==} + '@next/swc-linux-x64-gnu@15.0.2-canary.7': + resolution: {integrity: sha512-hgfDc8NrZ1Z6bCFiFehP7sPo2NbdsdGWwC1gBLgD/HeIlYxtJ1WONvlTwesRtg1u3Ag/uPwxym530qn1DyOjOw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -1723,11 +1717,11 @@ packages: cpu: [x64] os: [linux] - '@next/swc-win32-arm64-msvc@15.0.0': - resolution: {integrity: sha512-ZOd7c/Lz1lv7qP/KzR513XEa7QzW5/P0AH3A5eR1+Z/KmDOvMucht0AozccPc0TqhdV1xaXmC0Fdx0hoNzk6ng==} + '@next/swc-linux-x64-musl@15.0.2-canary.7': + resolution: {integrity: sha512-QqWrVXh9oAbg70q4qeVGhtP9Km8jcZMrXxOjuTAVPnMDGX28dg7x2hJEVh1qu5BR8UuQauKMi8XxCjyQwP/o4g==} engines: {node: '>= 10'} - cpu: [arm64] - os: [win32] + cpu: [x64] + os: [linux] '@next/swc-win32-arm64-msvc@15.0.0-canary.146': resolution: {integrity: sha512-KigH/uh+89+Ki5J8Kawu5m6hNrOsoGjy60tnfdzMbmfJm+l6JLNc4ExoLv03OuG2uA5cyyfOPzCGquKI9/a5ng==} @@ -1735,20 +1729,26 @@ packages: cpu: [arm64] os: [win32] + '@next/swc-win32-arm64-msvc@15.0.2-canary.7': + resolution: {integrity: sha512-BEnQqQqSujE2RhORp9jDGhG3ZF1VwROHmlVdLMNpr2yd12yHGoAh0PcgBgO/LdkYoLAJfxdzMrBPAhiA/wKwcg==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + '@next/swc-win32-ia32-msvc@15.0.0-canary.146': resolution: {integrity: sha512-F0I9tuHMV7Qz/foqKsb6k232kiUAjUxVVARknPoYfRiWLYlpQY+8DewIg+ZxlqTzeyVdAnAc0KEQf5DHkyY0Aw==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] - '@next/swc-win32-x64-msvc@15.0.0': - resolution: {integrity: sha512-2RVWcLtsqg4LtaoJ3j7RoKpnWHgcrz5XvuUGE7vBYU2i6M2XeD9Y8RlLaF770LEIScrrl8MdWsp6odtC6sZccg==} + '@next/swc-win32-x64-msvc@15.0.0-canary.146': + resolution: {integrity: sha512-xWLlSKpbIFTyaRs8iG6JRaoDxtbEmSBydsjjFedE/lyVLhTZqd7P3YCWxHbVTOqtrFSaqqKwnqNRon6D/zxdPg==} engines: {node: '>= 10'} cpu: [x64] os: [win32] - '@next/swc-win32-x64-msvc@15.0.0-canary.146': - resolution: {integrity: sha512-xWLlSKpbIFTyaRs8iG6JRaoDxtbEmSBydsjjFedE/lyVLhTZqd7P3YCWxHbVTOqtrFSaqqKwnqNRon6D/zxdPg==} + '@next/swc-win32-x64-msvc@15.0.2-canary.7': + resolution: {integrity: sha512-CGI/lcF5gCJdRyaeGTO4oGUUexUYdZN64+fBSvRHDgkGNKrLLd3BcbJD0h5MGHeCZwJZB6mWKihEaEAIpm0k4w==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -2225,8 +2225,8 @@ packages: peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: 19.0.0-rc-cc1ec60d0d-20240607 - react-dom: 19.0.0-rc-cc1ec60d0d-20240607 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true @@ -2344,8 +2344,8 @@ packages: peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: 19.0.0-rc-cc1ec60d0d-20240607 - react-dom: 19.0.0-rc-cc1ec60d0d-20240607 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true @@ -2790,8 +2790,8 @@ packages: peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: 19.0.0-rc-cc1ec60d0d-20240607 - react-dom: 19.0.0-rc-cc1ec60d0d-20240607 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true @@ -6002,16 +6002,16 @@ packages: react: ^16.8 || ^17 || ^18 react-dom: ^16.8 || ^17 || ^18 - next@15.0.0: - resolution: {integrity: sha512-/ivqF6gCShXpKwY9hfrIQYh8YMge8L3W+w1oRLv/POmK4MOQnh+FscZ8a0fRFTSQWE+2z9ctNYvELD9vP2FV+A==} + next@15.0.0-canary.146: + resolution: {integrity: sha512-wKwODWXdOJ9A+w7VcAFxm2eASwjRArEV6szY0csI9ehONENg3lOcTZSK5ygNCc2r02Xj6dIUqxYscYcrqwyPFA==} engines: {node: '>=18.18.0'} hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 '@playwright/test': ^1.41.2 babel-plugin-react-compiler: '*' - react: ^18.2.0 || 19.0.0-rc-65a56d0e-20241020 - react-dom: ^18.2.0 || 19.0.0-rc-65a56d0e-20241020 + react: 19.0.0-rc-7771d3a7-20240827 + react-dom: 19.0.0-rc-7771d3a7-20240827 sass: ^1.3.0 peerDependenciesMeta: '@opentelemetry/api': @@ -6023,16 +6023,16 @@ packages: sass: optional: true - next@15.0.0-canary.146: - resolution: {integrity: sha512-wKwODWXdOJ9A+w7VcAFxm2eASwjRArEV6szY0csI9ehONENg3lOcTZSK5ygNCc2r02Xj6dIUqxYscYcrqwyPFA==} + next@15.0.2-canary.7: + resolution: {integrity: sha512-64SgkNLFKyElS1pj+DTNM51hkio+0qY0IQYsqjDbhZ8ZMohlsTBfpYSEnWAdSe4gHwziI9Cit5YXGvG/H4nhMw==} engines: {node: '>=18.18.0'} hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 '@playwright/test': ^1.41.2 babel-plugin-react-compiler: '*' - react: 19.0.0-rc-7771d3a7-20240827 - react-dom: 19.0.0-rc-7771d3a7-20240827 + react: ^18.2.0 || 19.0.0-rc-1631855f-20241023 + react-dom: ^18.2.0 || 19.0.0-rc-1631855f-20241023 sass: ^1.3.0 peerDependenciesMeta: '@opentelemetry/api': @@ -10076,68 +10076,68 @@ snapshots: '@motionone/dom': 10.18.0 tslib: 2.7.0 - '@next/bundle-analyzer@15.0.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@next/bundle-analyzer@15.0.2-canary.7(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: webpack-bundle-analyzer: 4.10.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - utf-8-validate - '@next/env@15.0.0': {} - '@next/env@15.0.0-canary.146': {} - '@next/swc-darwin-arm64@15.0.0': - optional: true + '@next/env@15.0.2-canary.7': {} '@next/swc-darwin-arm64@15.0.0-canary.146': optional: true - '@next/swc-darwin-x64@15.0.0': + '@next/swc-darwin-arm64@15.0.2-canary.7': optional: true '@next/swc-darwin-x64@15.0.0-canary.146': optional: true - '@next/swc-linux-arm64-gnu@15.0.0': + '@next/swc-darwin-x64@15.0.2-canary.7': optional: true '@next/swc-linux-arm64-gnu@15.0.0-canary.146': optional: true - '@next/swc-linux-arm64-musl@15.0.0': + '@next/swc-linux-arm64-gnu@15.0.2-canary.7': optional: true '@next/swc-linux-arm64-musl@15.0.0-canary.146': optional: true - '@next/swc-linux-x64-gnu@15.0.0': + '@next/swc-linux-arm64-musl@15.0.2-canary.7': optional: true '@next/swc-linux-x64-gnu@15.0.0-canary.146': optional: true - '@next/swc-linux-x64-musl@15.0.0': + '@next/swc-linux-x64-gnu@15.0.2-canary.7': optional: true '@next/swc-linux-x64-musl@15.0.0-canary.146': optional: true - '@next/swc-win32-arm64-msvc@15.0.0': + '@next/swc-linux-x64-musl@15.0.2-canary.7': optional: true '@next/swc-win32-arm64-msvc@15.0.0-canary.146': optional: true - '@next/swc-win32-ia32-msvc@15.0.0-canary.146': + '@next/swc-win32-arm64-msvc@15.0.2-canary.7': optional: true - '@next/swc-win32-x64-msvc@15.0.0': + '@next/swc-win32-ia32-msvc@15.0.0-canary.146': optional: true '@next/swc-win32-x64-msvc@15.0.0-canary.146': optional: true + '@next/swc-win32-x64-msvc@15.0.2-canary.7': + optional: true + '@noble/curves@1.4.2': dependencies: '@noble/hashes': 1.4.0 @@ -11961,11 +11961,11 @@ snapshots: dependencies: crypto-js: 4.2.0 - '@vercel/analytics@1.3.1(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020)': + '@vercel/analytics@1.3.1(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020)': dependencies: server-only: 0.0.1 optionalDependencies: - next: 15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + next: 15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) react: 19.0.0-rc-65a56d0e-20241020 '@vercel/build-utils@8.4.11': {} @@ -12102,9 +12102,9 @@ snapshots: '@vercel/ruby@2.1.0': {} - '@vercel/speed-insights@1.0.12(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020)': + '@vercel/speed-insights@1.0.12(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020)': optionalDependencies: - next: 15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + next: 15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) react: 19.0.0-rc-65a56d0e-20241020 '@vercel/static-build@2.5.33': @@ -15165,11 +15165,11 @@ snapshots: neverthrow@8.0.0: {} - next-intl@3.22.0(next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): + next-intl@3.22.0(next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): dependencies: '@formatjs/intl-localematcher': 0.5.4 negotiator: 0.6.3 - next: 15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) + next: 15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020) react: 19.0.0-rc-65a56d0e-20241020 use-intl: 3.22.0(react@19.0.0-rc-65a56d0e-20241020) @@ -15178,53 +15178,53 @@ snapshots: react: 19.0.0-rc-65a56d0e-20241020 react-dom: 19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020) - next@15.0.0(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): + next@15.0.0-canary.146(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): dependencies: - '@next/env': 15.0.0 + '@next/env': 15.0.0-canary.146 '@swc/counter': 0.1.3 '@swc/helpers': 0.5.13 busboy: 1.6.0 caniuse-lite: 1.0.30001651 + graceful-fs: 4.2.11 postcss: 8.4.31 react: 19.0.0-rc-65a56d0e-20241020 react-dom: 19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020) styled-jsx: 5.1.6(@babel/core@7.25.2)(react@19.0.0-rc-65a56d0e-20241020) optionalDependencies: - '@next/swc-darwin-arm64': 15.0.0 - '@next/swc-darwin-x64': 15.0.0 - '@next/swc-linux-arm64-gnu': 15.0.0 - '@next/swc-linux-arm64-musl': 15.0.0 - '@next/swc-linux-x64-gnu': 15.0.0 - '@next/swc-linux-x64-musl': 15.0.0 - '@next/swc-win32-arm64-msvc': 15.0.0 - '@next/swc-win32-x64-msvc': 15.0.0 + '@next/swc-darwin-arm64': 15.0.0-canary.146 + '@next/swc-darwin-x64': 15.0.0-canary.146 + '@next/swc-linux-arm64-gnu': 15.0.0-canary.146 + '@next/swc-linux-arm64-musl': 15.0.0-canary.146 + '@next/swc-linux-x64-gnu': 15.0.0-canary.146 + '@next/swc-linux-x64-musl': 15.0.0-canary.146 + '@next/swc-win32-arm64-msvc': 15.0.0-canary.146 + '@next/swc-win32-ia32-msvc': 15.0.0-canary.146 + '@next/swc-win32-x64-msvc': 15.0.0-canary.146 sharp: 0.33.5 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros - next@15.0.0-canary.146(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): + next@15.0.2-canary.7(@babel/core@7.25.2)(react-dom@19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020))(react@19.0.0-rc-65a56d0e-20241020): dependencies: - '@next/env': 15.0.0-canary.146 + '@next/env': 15.0.2-canary.7 '@swc/counter': 0.1.3 '@swc/helpers': 0.5.13 busboy: 1.6.0 caniuse-lite: 1.0.30001651 - graceful-fs: 4.2.11 postcss: 8.4.31 react: 19.0.0-rc-65a56d0e-20241020 react-dom: 19.0.0-rc-65a56d0e-20241020(react@19.0.0-rc-65a56d0e-20241020) styled-jsx: 5.1.6(@babel/core@7.25.2)(react@19.0.0-rc-65a56d0e-20241020) optionalDependencies: - '@next/swc-darwin-arm64': 15.0.0-canary.146 - '@next/swc-darwin-x64': 15.0.0-canary.146 - '@next/swc-linux-arm64-gnu': 15.0.0-canary.146 - '@next/swc-linux-arm64-musl': 15.0.0-canary.146 - '@next/swc-linux-x64-gnu': 15.0.0-canary.146 - '@next/swc-linux-x64-musl': 15.0.0-canary.146 - '@next/swc-win32-arm64-msvc': 15.0.0-canary.146 - '@next/swc-win32-ia32-msvc': 15.0.0-canary.146 - '@next/swc-win32-x64-msvc': 15.0.0-canary.146 + '@next/swc-darwin-arm64': 15.0.2-canary.7 + '@next/swc-darwin-x64': 15.0.2-canary.7 + '@next/swc-linux-arm64-gnu': 15.0.2-canary.7 + '@next/swc-linux-arm64-musl': 15.0.2-canary.7 + '@next/swc-linux-x64-gnu': 15.0.2-canary.7 + '@next/swc-linux-x64-musl': 15.0.2-canary.7 + '@next/swc-win32-arm64-msvc': 15.0.2-canary.7 + '@next/swc-win32-x64-msvc': 15.0.2-canary.7 sharp: 0.33.5 transitivePeerDependencies: - '@babel/core' diff --git a/src/components/clock.tsx b/src/components/clock.tsx deleted file mode 100644 index 3f363add..00000000 --- a/src/components/clock.tsx +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2023-2024 Shun Kakinoki. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -"use client"; - -import { useEffect, useState } from "react"; - -// ----------------------------------------------------------------------------- -// Component -// ----------------------------------------------------------------------------- - -export const Clock = () => { - // --------------------------------------------------------------------------- - // State Hooks - // --------------------------------------------------------------------------- - - const [time, setTime] = useState(new Date()); - - // --------------------------------------------------------------------------- - // Effect Hooks - // --------------------------------------------------------------------------- - - useEffect(() => { - setInterval(() => { - setTime(new Date()); - }, 100); - }, []); - - // --------------------------------------------------------------------------- - // Render - // --------------------------------------------------------------------------- - - return ( -
-
-
- {time.toLocaleString("en", { - weekday: "long", - year: "numeric", - month: "long", - day: "numeric", - })} -
-

- {time.toLocaleTimeString("en", { hour12: false })} -

-
-
- ); -}; From e589f3493d43d95310714ac3af8d690b275831dc Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:01:20 +0900 Subject: [PATCH 02/21] feat: ini dynamic connection --- app/[locale]/about/page.tsx | 6 ++++++ app/[locale]/blog/page.tsx | 7 +++++++ app/[locale]/cause/page.tsx | 7 +++++++ app/[locale]/dashboard/page.tsx | 7 +++++++ app/[locale]/history/page.tsx | 7 +++++++ app/[locale]/mission/page.tsx | 7 +++++++ app/[locale]/page.tsx | 7 +++++++ app/[locale]/products/page.tsx | 7 +++++++ app/[locale]/social/page.tsx | 7 +++++++ app/[locale]/values/page.tsx | 7 +++++++ src/components/providers.tsx | 13 +++++++++++-- 11 files changed, 80 insertions(+), 2 deletions(-) diff --git a/app/[locale]/about/page.tsx b/app/[locale]/about/page.tsx index e981ddce..f1c5fd16 100644 --- a/app/[locale]/about/page.tsx +++ b/app/[locale]/about/page.tsx @@ -59,6 +59,12 @@ export async function generateMetadata({ export default async function AboutPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/blog/page.tsx b/app/[locale]/blog/page.tsx index dfe08b13..20d689cb 100644 --- a/app/[locale]/blog/page.tsx +++ b/app/[locale]/blog/page.tsx @@ -21,6 +21,7 @@ import { } from "@tanstack/react-query"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -54,6 +55,12 @@ export async function generateMetadata({ export default async function BlogPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/cause/page.tsx b/app/[locale]/cause/page.tsx index 5c6ffd33..c327d2f7 100644 --- a/app/[locale]/cause/page.tsx +++ b/app/[locale]/cause/page.tsx @@ -14,6 +14,7 @@ import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; import SlugPage from "../[slug]/page"; // ----------------------------------------------------------------------------- @@ -57,6 +58,12 @@ export async function generateMetadata({ export default async function CausePage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/dashboard/page.tsx b/app/[locale]/dashboard/page.tsx index 4467fc67..0a983c67 100644 --- a/app/[locale]/dashboard/page.tsx +++ b/app/[locale]/dashboard/page.tsx @@ -15,6 +15,7 @@ import { Dashboard } from "@/sections/dashboard"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -47,6 +48,12 @@ export async function generateMetadata({ export default async function DashboardPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/history/page.tsx b/app/[locale]/history/page.tsx index 88aff598..ad5fcb25 100644 --- a/app/[locale]/history/page.tsx +++ b/app/[locale]/history/page.tsx @@ -15,6 +15,7 @@ import { History } from "@/sections/history"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -47,6 +48,12 @@ export async function generateMetadata({ export default async function HistoryPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/mission/page.tsx b/app/[locale]/mission/page.tsx index ae1627d7..99315064 100644 --- a/app/[locale]/mission/page.tsx +++ b/app/[locale]/mission/page.tsx @@ -14,6 +14,7 @@ import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; import SlugPage from "../[slug]/page"; // ----------------------------------------------------------------------------- @@ -58,6 +59,12 @@ export async function generateMetadata({ export default async function MissionPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index 1b66fa0c..af6c9180 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -28,6 +28,7 @@ import { Button } from "@lightdotso/ui/components/button"; import { TwitterLogoIcon } from "@radix-ui/react-icons"; import { ArrowUpRightFromSquareIcon } from "lucide-react"; import { setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Page @@ -38,6 +39,12 @@ import { setRequestLocale } from "next-intl/server"; export default async function IndexPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/products/page.tsx b/app/[locale]/products/page.tsx index c97a9f50..10bc74e2 100644 --- a/app/[locale]/products/page.tsx +++ b/app/[locale]/products/page.tsx @@ -15,6 +15,7 @@ import { Products } from "@/sections/products"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -47,6 +48,12 @@ export async function generateMetadata({ export default async function ProductsPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/social/page.tsx b/app/[locale]/social/page.tsx index 23a2acd7..5950d4b2 100644 --- a/app/[locale]/social/page.tsx +++ b/app/[locale]/social/page.tsx @@ -15,6 +15,7 @@ import { Social } from "@/sections/social"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Metadata @@ -47,6 +48,12 @@ export async function generateMetadata({ export default async function AboutPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/app/[locale]/values/page.tsx b/app/[locale]/values/page.tsx index 39f762eb..fc6c96a7 100644 --- a/app/[locale]/values/page.tsx +++ b/app/[locale]/values/page.tsx @@ -14,6 +14,7 @@ import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; import SlugPage from "../[slug]/page"; // ----------------------------------------------------------------------------- @@ -58,6 +59,12 @@ export async function generateMetadata({ export default async function valuesPage({ params, }: { params: Promise<{ locale: string }> }) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/src/components/providers.tsx b/src/components/providers.tsx index 57874458..0c52efd0 100644 --- a/src/components/providers.tsx +++ b/src/components/providers.tsx @@ -16,23 +16,32 @@ import { getQueryClient } from "@/lib/query"; import { TooltipProvider } from "@lightdotso/ui/components/tooltip"; -import { QueryClientProvider } from "@tanstack/react-query"; +import { type QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { Provider as JotaiProvider } from "jotai"; import { ThemeProvider as NextThemesProvider } from "next-themes"; import type { ThemeProviderProps } from "next-themes/dist/types"; +import { useEffect, useState } from "react"; // ----------------------------------------------------------------------------- // Component // ----------------------------------------------------------------------------- export function ThemeProvider({ children, ...props }: ThemeProviderProps) { - const queryClient = getQueryClient(); + const [queryClient, setQueryClient] = useState(); + + useEffect(() => { + setQueryClient(getQueryClient()); + }, []); // --------------------------------------------------------------------------- // Render // --------------------------------------------------------------------------- + if (!queryClient) { + return null; + } + return ( From 58aedfd97191321a8c51cc6a857245f5d8d2deb3 Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:02:01 +0900 Subject: [PATCH 03/21] chore: update --- src/components/providers.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/providers.tsx b/src/components/providers.tsx index 0c52efd0..63da0998 100644 --- a/src/components/providers.tsx +++ b/src/components/providers.tsx @@ -28,8 +28,16 @@ import { useEffect, useState } from "react"; // ----------------------------------------------------------------------------- export function ThemeProvider({ children, ...props }: ThemeProviderProps) { + // --------------------------------------------------------------------------- + // State Hooks + // --------------------------------------------------------------------------- + const [queryClient, setQueryClient] = useState(); + // --------------------------------------------------------------------------- + // Effect Hooks + // --------------------------------------------------------------------------- + useEffect(() => { setQueryClient(getQueryClient()); }, []); From a8863e53716413c2d97a7f2d127a5e5b41e25360 Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:07:56 +0900 Subject: [PATCH 04/21] feat: update --- app/[locale]/[slug]/page.tsx | 22 ++++++++---------- app/[locale]/about/page.tsx | 1 + src/actions/getBlogAction.ts | 7 ++---- src/actions/getJournalAction.ts | 7 ++---- src/actions/getPostsAction.ts | 7 ++---- src/sections/check.tsx | 4 ++-- src/sections/dashboard.tsx | 30 ++++++++++++------------ src/sections/mind.tsx | 4 ++-- src/sections/products.tsx | 4 ++-- src/services/cloudflare.ts | 15 +----------- src/services/notion.ts | 41 +++++++++------------------------ src/services/ogs.ts | 23 ++++++++---------- src/services/twitter.ts | 38 +++++------------------------- 13 files changed, 65 insertions(+), 138 deletions(-) diff --git a/app/[locale]/[slug]/page.tsx b/app/[locale]/[slug]/page.tsx index 3200e7fb..446bea42 100644 --- a/app/[locale]/[slug]/page.tsx +++ b/app/[locale]/[slug]/page.tsx @@ -17,12 +17,8 @@ import { ViewCount } from "@/components/view-count"; import { extractValidUUID } from "@/lib/utils"; import { Check } from "@/sections/check"; import { Mind } from "@/sections/mind"; -import { - type blockWithChildren, - getCachedBlocks, - getCachedPage, -} from "@/services/notion"; -import { getCachedOpenGraphData } from "@/services/ogs"; +import { type blockWithChildren, getBlocks, getPage } from "@/services/notion"; +import { getOpenGraphData } from "@/services/ogs"; import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { Suspense } from "react"; @@ -34,7 +30,7 @@ import { Suspense } from "react"; export async function generateMetadata({ params, }: { params: Promise<{ slug: string }> }): Promise { - const page = await getCachedPage((await params).slug); + const page = await getPage((await params).slug); return { //@ts-ignore @@ -64,20 +60,20 @@ export default async function SlugPage({ } // Get the page - const page = await getCachedPage(pageId); + const page = await getPage(pageId); // @ts-ignore const pageEmoji = page?.icon?.emoji ?? "📄"; - const getCachedBlocksRecursively = async ( + const getBlocksRecursively = async ( blockId: string, ): Promise => { - const blocks = await getCachedBlocks(blockId); + const blocks = await getBlocks(blockId); return await Promise.all( blocks.map(async (block) => { // @ts-ignore if (block.has_children) { - const children = await getCachedBlocksRecursively(block.id); + const children = await getBlocksRecursively(block.id); return { ...block, children }; } return block; @@ -89,7 +85,7 @@ export default async function SlugPage({ // @ts-ignore const url = block.bookmark?.url ?? block.link_preview?.url; if (url) { - const ogData = await getCachedOpenGraphData({ url }); + const ogData = await getOpenGraphData({ url }); block.openGraphData = ogData; } return block; @@ -116,7 +112,7 @@ export default async function SlugPage({ const getProcessedBlocks = async ( slug: string, ): Promise => { - const blocks = await getCachedBlocksRecursively(slug); + const blocks = await getBlocksRecursively(slug); return await Promise.all(blocks.map(processBlockRecursively)); }; diff --git a/app/[locale]/about/page.tsx b/app/[locale]/about/page.tsx index f1c5fd16..bfb35260 100644 --- a/app/[locale]/about/page.tsx +++ b/app/[locale]/about/page.tsx @@ -15,6 +15,7 @@ import { Life } from "@/sections/life"; import type { Metadata } from "next"; import { getTranslations, setRequestLocale } from "next-intl/server"; +import { connection } from "next/server"; import SlugPage from "../[slug]/page"; // ----------------------------------------------------------------------------- diff --git a/src/actions/getBlogAction.ts b/src/actions/getBlogAction.ts index 30f4af65..f21d3544 100644 --- a/src/actions/getBlogAction.ts +++ b/src/actions/getBlogAction.ts @@ -15,10 +15,7 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { - type NotionPageObject, - getCachedQueryDatabase, -} from "@/services/notion"; +import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -42,7 +39,7 @@ export async function getBlogAction( // Services // --------------------------------------------------------------------------- - const res = await getCachedQueryDatabase({ + const res = await getQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "e4ef762ca07f465e8f5cce906732140b", filter: { diff --git a/src/actions/getJournalAction.ts b/src/actions/getJournalAction.ts index f1802685..87ad5a6b 100644 --- a/src/actions/getJournalAction.ts +++ b/src/actions/getJournalAction.ts @@ -15,10 +15,7 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { - type NotionPageObject, - getCachedQueryDatabase, -} from "@/services/notion"; +import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -41,7 +38,7 @@ export async function getJournalAction( // Services // --------------------------------------------------------------------------- - const res = await getCachedQueryDatabase({ + const res = await getQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "badf29d87d2f4e03b2c5451a627d8618", // biome-ignore lint/style/useNamingConvention: diff --git a/src/actions/getPostsAction.ts b/src/actions/getPostsAction.ts index 6ce90b57..4683790e 100644 --- a/src/actions/getPostsAction.ts +++ b/src/actions/getPostsAction.ts @@ -15,10 +15,7 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { - type NotionPageObject, - getCachedQueryDatabase, -} from "@/services/notion"; +import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -41,7 +38,7 @@ export async function getPostsAction( // Services // --------------------------------------------------------------------------- - const res = await getCachedQueryDatabase({ + const res = await getQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "105dc0a4cffa807ead38c5c5184e9836", // biome-ignore lint/style/useNamingConvention: diff --git a/src/sections/check.tsx b/src/sections/check.tsx index 3987a957..41b7ae00 100644 --- a/src/sections/check.tsx +++ b/src/sections/check.tsx @@ -14,7 +14,7 @@ import { Checklist } from "@/components/check-list"; import { PageHeader, PageHeaderSubheading } from "@/components/page-header"; -import { getCachedQueryDatabase } from "@/services/notion"; +import { getQueryDatabase } from "@/services/notion"; import { getTranslations } from "next-intl/server"; // ----------------------------------------------------------------------------- @@ -41,7 +41,7 @@ export async function Check({ dateStart }: CheckProps) { // --------------------------------------------------------------------------- const checklist = ( - await getCachedQueryDatabase({ + await getQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "ccf0648ddaab42a38644f209e6cd641f", filter: { diff --git a/src/sections/dashboard.tsx b/src/sections/dashboard.tsx index e44a3196..a27a4349 100644 --- a/src/sections/dashboard.tsx +++ b/src/sections/dashboard.tsx @@ -15,13 +15,13 @@ import { PageHeader, PageHeaderHeading } from "@/components/page-header"; import { InternalConfig } from "@/config/internal"; import { SocialConfig } from "@/config/social"; -import { getCachedCloudflareAnalytics } from "@/services/cloudflare"; -import { getCachedDatabaseStats } from "@/services/notion"; +import { getCloudflareAnalytics } from "@/services/cloudflare"; +import { getDatabaseStats } from "@/services/notion"; import { getTotalViewCount, getTotalVisitorCount } from "@/services/redis"; import { - getCachedFollowerCount, - getCachedImpressionCount, - getCachedLatestPublishedTweetCount, + getFollowerCount, + getImpressionCount, + getLatestPublishedTweetCount, } from "@/services/twitter"; import { DocumentMagnifyingGlassIcon, @@ -140,7 +140,7 @@ export async function VisitorCard() { } export async function TwitterCard() { - const followerCount = await getCachedFollowerCount(); + const followerCount = await getFollowerCount(); return ( database_id: "be3e2449e1324b518f78c21e168f5a78", filter: { diff --git a/src/sections/products.tsx b/src/sections/products.tsx index 13983e10..b4a707b8 100644 --- a/src/sections/products.tsx +++ b/src/sections/products.tsx @@ -14,7 +14,7 @@ import { PageHeader, PageHeaderHeading } from "@/components/page-header"; import { SectionHeaderHeading } from "@/components/section-header"; -import { getCachedQueryDatabase } from "@/services/notion"; +import { getQueryDatabase } from "@/services/notion"; import { ArrowUpRightIcon } from "@heroicons/react/24/outline"; import { getTranslations } from "next-intl/server"; @@ -41,7 +41,7 @@ export async function Products({ isPartial }: ProductsProps) { // Services // --------------------------------------------------------------------------- - const res = await getCachedQueryDatabase({ + const res = await getQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "bd49167ff0b140aea87c4548f3fbbc82", sorts: [ diff --git a/src/services/cloudflare.ts b/src/services/cloudflare.ts index f6ce15d7..935d43a9 100644 --- a/src/services/cloudflare.ts +++ b/src/services/cloudflare.ts @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { unstable_cache } from "next/cache"; - // ----------------------------------------------------------------------------- // Utils // ----------------------------------------------------------------------------- export const getCloudflareAnalytics = async () => { + "use cache"; const url = "https://api.cloudflare.com/client/v4/graphql"; const payload = { operationName: "RumAnalyticsTimeseriesBydatetimeHourGroupedByall", @@ -92,15 +91,3 @@ export const getCloudflareAnalytics = async () => { const data = await response.json(); return data?.data?.viewer?.accounts?.[0]?.series?.[0]?.sum?.visits; }; - -// ----------------------------------------------------------------------------- -// Cached -// ----------------------------------------------------------------------------- - -export const getCachedCloudflareAnalytics = unstable_cache( - getCloudflareAnalytics, - ["cloudflare", "cloudflare-analytics"], - { - revalidate: 300, - }, -); diff --git a/src/services/notion.ts b/src/services/notion.ts index 50fa5e63..9a16eb70 100644 --- a/src/services/notion.ts +++ b/src/services/notion.ts @@ -22,7 +22,6 @@ import type { QueryDatabaseParameters, QueryDatabaseResponse, } from "@notionhq/client/build/src/api-endpoints.d"; -import { unstable_cache } from "next/cache"; // ----------------------------------------------------------------------------- // Types @@ -103,6 +102,8 @@ export const retrieveDatabase = async ({ database_id, // biome-ignore lint/style/useNamingConvention: }: { database_id: string }) => { + "use cache"; + const response = await notion.databases.retrieve({ // biome-ignore lint/style/useNamingConvention: database_id: database_id, @@ -110,7 +111,7 @@ export const retrieveDatabase = async ({ return response; }; -export const getCachedQueryDatabase = async ({ +export const getQueryDatabase = async ({ database_id, filter, sorts, @@ -131,18 +132,24 @@ export const getCachedQueryDatabase = async ({ }; export const getPage = async (pageId: string) => { + "use cache"; + // biome-ignore lint/style/useNamingConvention: const response = await notion.pages.retrieve({ page_id: pageId }); return response; }; export const getPageTitle = (property: NotionProperty) => { + "use cache"; + return property.Name.type === "title" ? property.Name.title[0].plain_text : ""; }; export const getPageDate = (page: NotionPage) => { + "use cache"; + //@ts-ignore let dateString = page.last_edited_time; if ( @@ -180,6 +187,8 @@ export const getBlocks = async (blockId: string) => { }; export const getDatabaseStats = async () => { + "use cache"; + const response = await fetch( "https://shunkakinoki.notion.site/api/v3/queryCollection", { @@ -195,31 +204,3 @@ export const getDatabaseStats = async () => { const data = await response.json(); return data?.result?.reducerResults; }; - -// ----------------------------------------------------------------------------- -// Cached -// ----------------------------------------------------------------------------- - -export const getCachedgetCachedQueryDatabase = unstable_cache( - getCachedQueryDatabase, - ["notion", "query-database"], - { - revalidate: 300, - }, -); - -export const getCachedBlocks = unstable_cache(getBlocks, ["notion", "blocks"], { - revalidate: 30, -}); - -export const getCachedPage = unstable_cache(getPage, ["notion", "page"], { - revalidate: 300, -}); - -export const getCachedDatabaseStats = unstable_cache( - getDatabaseStats, - ["notion", "stats"], - { - revalidate: 300, - }, -); diff --git a/src/services/ogs.ts b/src/services/ogs.ts index bf386785..f6e79e9c 100644 --- a/src/services/ogs.ts +++ b/src/services/ogs.ts @@ -12,18 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { unstable_cache } from "next/cache"; import ogs from "open-graph-scraper"; -export const getCachedOpenGraphData = unstable_cache( - async ({ url }: { url: string }) => { - const ogData = await ogs({ url: url }); - if (!ogData.error) { - return JSON.stringify(ogData); - } - // Throw an error if the URL is not valid - throw new Error("Invalid URL"); - }, - ["ogs", "open-graph-data"], - { revalidate: false }, -); +export const getOpenGraphData = async ({ url }: { url: string }) => { + "use cache"; + + const ogData = await ogs({ url: url }); + if (!ogData.error) { + return JSON.stringify(ogData); + } + // Throw an error if the URL is not valid + throw new Error("Invalid URL"); +}; diff --git a/src/services/twitter.ts b/src/services/twitter.ts index ac99fc7d..591e9408 100644 --- a/src/services/twitter.ts +++ b/src/services/twitter.ts @@ -12,10 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// import { TwitterApi } from "twitter-api-v2"; - -import { unstable_cache } from "next/cache"; - // ----------------------------------------------------------------------------- // Client // ----------------------------------------------------------------------------- @@ -27,6 +23,8 @@ import { unstable_cache } from "next/cache"; // ----------------------------------------------------------------------------- export const getFollowerCount = async () => { + "use cache"; + const metrics = await fetch( "https://api2.typefully.com/metric/followers-count/?screen_name=shunkakinoki", ).then((res) => res.json()); @@ -34,6 +32,8 @@ export const getFollowerCount = async () => { }; export const getLatestPublishedTweetCount = async () => { + "use cache"; + const metrics = await fetch( "https://api2.typefully.com/metric/published-tweets-count/?screen_name=shunkakinoki", ).then((res) => res.json()); @@ -41,36 +41,10 @@ export const getLatestPublishedTweetCount = async () => { }; export const getImpressionCount = async () => { + "use cache"; + const metrics = await fetch( "https://api2.typefully.com/metric/impressions/?screen_name=shunkakinoki", ).then((res) => res.json()); return metrics?.value; }; - -// ----------------------------------------------------------------------------- -// Cached -// ----------------------------------------------------------------------------- - -export const getCachedFollowerCount = unstable_cache( - getFollowerCount, - ["twitter", "follower-count"], - { - revalidate: 300, - }, -); - -export const getCachedLatestPublishedTweetCount = unstable_cache( - getLatestPublishedTweetCount, - ["twitter", "latest-published-tweet-count"], - { - revalidate: 300, - }, -); - -export const getCachedImpressionCount = unstable_cache( - getImpressionCount, - ["twitter", "impression-count"], - { - revalidate: 300, - }, -); From d4e270d2066360a23e56fe447d82233b098726b6 Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:09:30 +0900 Subject: [PATCH 05/21] chore: update --- src/services/notion.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/services/notion.ts b/src/services/notion.ts index 9a16eb70..497e85e2 100644 --- a/src/services/notion.ts +++ b/src/services/notion.ts @@ -22,6 +22,7 @@ import type { QueryDatabaseParameters, QueryDatabaseResponse, } from "@notionhq/client/build/src/api-endpoints.d"; +import { unstable_cacheLife as cacheLife } from "next/cache"; // ----------------------------------------------------------------------------- // Types @@ -104,6 +105,8 @@ export const retrieveDatabase = async ({ }: { database_id: string }) => { "use cache"; + cacheLife("minutes"); + const response = await notion.databases.retrieve({ // biome-ignore lint/style/useNamingConvention: database_id: database_id, @@ -118,6 +121,10 @@ export const getQueryDatabase = async ({ start_cursor, page_size, }: QueryDatabaseParameters) => { + "use cache"; + + cacheLife("minutes"); + const response = await notion.databases.query({ // biome-ignore lint/style/useNamingConvention: database_id: database_id, @@ -134,6 +141,8 @@ export const getQueryDatabase = async ({ export const getPage = async (pageId: string) => { "use cache"; + cacheLife("minutes"); + // biome-ignore lint/style/useNamingConvention: const response = await notion.pages.retrieve({ page_id: pageId }); return response; @@ -142,6 +151,8 @@ export const getPage = async (pageId: string) => { export const getPageTitle = (property: NotionProperty) => { "use cache"; + cacheLife("minutes"); + return property.Name.type === "title" ? property.Name.title[0].plain_text : ""; @@ -150,6 +161,8 @@ export const getPageTitle = (property: NotionProperty) => { export const getPageDate = (page: NotionPage) => { "use cache"; + cacheLife("days"); + //@ts-ignore let dateString = page.last_edited_time; if ( @@ -165,6 +178,10 @@ export const getPageDate = (page: NotionPage) => { }; export const getBlocks = async (blockId: string) => { + "use cache"; + + cacheLife("minutes"); + const blocks: blockWithChildren[] = []; let cursor: undefined | string; @@ -189,6 +206,8 @@ export const getBlocks = async (blockId: string) => { export const getDatabaseStats = async () => { "use cache"; + cacheLife("days"); + const response = await fetch( "https://shunkakinoki.notion.site/api/v3/queryCollection", { From 9a46f147c3de660f8c9591ee395ecc6602c2ff2a Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:14:02 +0900 Subject: [PATCH 06/21] chore: update --- src/actions/getBlogAction.ts | 7 ++-- src/actions/getJournalAction.ts | 7 ++-- src/actions/getPostsAction.ts | 7 ++-- src/services/cloudflare.ts | 15 ++++++++- src/services/notion.ts | 60 ++++++++++++++++----------------- src/services/ogs.ts | 23 +++++++------ src/services/twitter.ts | 38 +++++++++++++++++---- 7 files changed, 104 insertions(+), 53 deletions(-) diff --git a/src/actions/getBlogAction.ts b/src/actions/getBlogAction.ts index f21d3544..30f4af65 100644 --- a/src/actions/getBlogAction.ts +++ b/src/actions/getBlogAction.ts @@ -15,7 +15,10 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; +import { + type NotionPageObject, + getCachedQueryDatabase, +} from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -39,7 +42,7 @@ export async function getBlogAction( // Services // --------------------------------------------------------------------------- - const res = await getQueryDatabase({ + const res = await getCachedQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "e4ef762ca07f465e8f5cce906732140b", filter: { diff --git a/src/actions/getJournalAction.ts b/src/actions/getJournalAction.ts index 87ad5a6b..f1802685 100644 --- a/src/actions/getJournalAction.ts +++ b/src/actions/getJournalAction.ts @@ -15,7 +15,10 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; +import { + type NotionPageObject, + getCachedQueryDatabase, +} from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -38,7 +41,7 @@ export async function getJournalAction( // Services // --------------------------------------------------------------------------- - const res = await getQueryDatabase({ + const res = await getCachedQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "badf29d87d2f4e03b2c5451a627d8618", // biome-ignore lint/style/useNamingConvention: diff --git a/src/actions/getPostsAction.ts b/src/actions/getPostsAction.ts index 4683790e..6ce90b57 100644 --- a/src/actions/getPostsAction.ts +++ b/src/actions/getPostsAction.ts @@ -15,7 +15,10 @@ "use server"; import { ITEMS_PER_PAGE } from "@/const"; -import { type NotionPageObject, getQueryDatabase } from "@/services/notion"; +import { + type NotionPageObject, + getCachedQueryDatabase, +} from "@/services/notion"; // ----------------------------------------------------------------------------- // Types @@ -38,7 +41,7 @@ export async function getPostsAction( // Services // --------------------------------------------------------------------------- - const res = await getQueryDatabase({ + const res = await getCachedQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "105dc0a4cffa807ead38c5c5184e9836", // biome-ignore lint/style/useNamingConvention: diff --git a/src/services/cloudflare.ts b/src/services/cloudflare.ts index 935d43a9..f6ce15d7 100644 --- a/src/services/cloudflare.ts +++ b/src/services/cloudflare.ts @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { unstable_cache } from "next/cache"; + // ----------------------------------------------------------------------------- // Utils // ----------------------------------------------------------------------------- export const getCloudflareAnalytics = async () => { - "use cache"; const url = "https://api.cloudflare.com/client/v4/graphql"; const payload = { operationName: "RumAnalyticsTimeseriesBydatetimeHourGroupedByall", @@ -91,3 +92,15 @@ export const getCloudflareAnalytics = async () => { const data = await response.json(); return data?.data?.viewer?.accounts?.[0]?.series?.[0]?.sum?.visits; }; + +// ----------------------------------------------------------------------------- +// Cached +// ----------------------------------------------------------------------------- + +export const getCachedCloudflareAnalytics = unstable_cache( + getCloudflareAnalytics, + ["cloudflare", "cloudflare-analytics"], + { + revalidate: 300, + }, +); diff --git a/src/services/notion.ts b/src/services/notion.ts index 497e85e2..50fa5e63 100644 --- a/src/services/notion.ts +++ b/src/services/notion.ts @@ -22,7 +22,7 @@ import type { QueryDatabaseParameters, QueryDatabaseResponse, } from "@notionhq/client/build/src/api-endpoints.d"; -import { unstable_cacheLife as cacheLife } from "next/cache"; +import { unstable_cache } from "next/cache"; // ----------------------------------------------------------------------------- // Types @@ -103,10 +103,6 @@ export const retrieveDatabase = async ({ database_id, // biome-ignore lint/style/useNamingConvention: }: { database_id: string }) => { - "use cache"; - - cacheLife("minutes"); - const response = await notion.databases.retrieve({ // biome-ignore lint/style/useNamingConvention: database_id: database_id, @@ -114,17 +110,13 @@ export const retrieveDatabase = async ({ return response; }; -export const getQueryDatabase = async ({ +export const getCachedQueryDatabase = async ({ database_id, filter, sorts, start_cursor, page_size, }: QueryDatabaseParameters) => { - "use cache"; - - cacheLife("minutes"); - const response = await notion.databases.query({ // biome-ignore lint/style/useNamingConvention: database_id: database_id, @@ -139,30 +131,18 @@ export const getQueryDatabase = async ({ }; export const getPage = async (pageId: string) => { - "use cache"; - - cacheLife("minutes"); - // biome-ignore lint/style/useNamingConvention: const response = await notion.pages.retrieve({ page_id: pageId }); return response; }; export const getPageTitle = (property: NotionProperty) => { - "use cache"; - - cacheLife("minutes"); - return property.Name.type === "title" ? property.Name.title[0].plain_text : ""; }; export const getPageDate = (page: NotionPage) => { - "use cache"; - - cacheLife("days"); - //@ts-ignore let dateString = page.last_edited_time; if ( @@ -178,10 +158,6 @@ export const getPageDate = (page: NotionPage) => { }; export const getBlocks = async (blockId: string) => { - "use cache"; - - cacheLife("minutes"); - const blocks: blockWithChildren[] = []; let cursor: undefined | string; @@ -204,10 +180,6 @@ export const getBlocks = async (blockId: string) => { }; export const getDatabaseStats = async () => { - "use cache"; - - cacheLife("days"); - const response = await fetch( "https://shunkakinoki.notion.site/api/v3/queryCollection", { @@ -223,3 +195,31 @@ export const getDatabaseStats = async () => { const data = await response.json(); return data?.result?.reducerResults; }; + +// ----------------------------------------------------------------------------- +// Cached +// ----------------------------------------------------------------------------- + +export const getCachedgetCachedQueryDatabase = unstable_cache( + getCachedQueryDatabase, + ["notion", "query-database"], + { + revalidate: 300, + }, +); + +export const getCachedBlocks = unstable_cache(getBlocks, ["notion", "blocks"], { + revalidate: 30, +}); + +export const getCachedPage = unstable_cache(getPage, ["notion", "page"], { + revalidate: 300, +}); + +export const getCachedDatabaseStats = unstable_cache( + getDatabaseStats, + ["notion", "stats"], + { + revalidate: 300, + }, +); diff --git a/src/services/ogs.ts b/src/services/ogs.ts index f6e79e9c..bf386785 100644 --- a/src/services/ogs.ts +++ b/src/services/ogs.ts @@ -12,15 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { unstable_cache } from "next/cache"; import ogs from "open-graph-scraper"; -export const getOpenGraphData = async ({ url }: { url: string }) => { - "use cache"; - - const ogData = await ogs({ url: url }); - if (!ogData.error) { - return JSON.stringify(ogData); - } - // Throw an error if the URL is not valid - throw new Error("Invalid URL"); -}; +export const getCachedOpenGraphData = unstable_cache( + async ({ url }: { url: string }) => { + const ogData = await ogs({ url: url }); + if (!ogData.error) { + return JSON.stringify(ogData); + } + // Throw an error if the URL is not valid + throw new Error("Invalid URL"); + }, + ["ogs", "open-graph-data"], + { revalidate: false }, +); diff --git a/src/services/twitter.ts b/src/services/twitter.ts index 591e9408..ac99fc7d 100644 --- a/src/services/twitter.ts +++ b/src/services/twitter.ts @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +// import { TwitterApi } from "twitter-api-v2"; + +import { unstable_cache } from "next/cache"; + // ----------------------------------------------------------------------------- // Client // ----------------------------------------------------------------------------- @@ -23,8 +27,6 @@ // ----------------------------------------------------------------------------- export const getFollowerCount = async () => { - "use cache"; - const metrics = await fetch( "https://api2.typefully.com/metric/followers-count/?screen_name=shunkakinoki", ).then((res) => res.json()); @@ -32,8 +34,6 @@ export const getFollowerCount = async () => { }; export const getLatestPublishedTweetCount = async () => { - "use cache"; - const metrics = await fetch( "https://api2.typefully.com/metric/published-tweets-count/?screen_name=shunkakinoki", ).then((res) => res.json()); @@ -41,10 +41,36 @@ export const getLatestPublishedTweetCount = async () => { }; export const getImpressionCount = async () => { - "use cache"; - const metrics = await fetch( "https://api2.typefully.com/metric/impressions/?screen_name=shunkakinoki", ).then((res) => res.json()); return metrics?.value; }; + +// ----------------------------------------------------------------------------- +// Cached +// ----------------------------------------------------------------------------- + +export const getCachedFollowerCount = unstable_cache( + getFollowerCount, + ["twitter", "follower-count"], + { + revalidate: 300, + }, +); + +export const getCachedLatestPublishedTweetCount = unstable_cache( + getLatestPublishedTweetCount, + ["twitter", "latest-published-tweet-count"], + { + revalidate: 300, + }, +); + +export const getCachedImpressionCount = unstable_cache( + getImpressionCount, + ["twitter", "impression-count"], + { + revalidate: 300, + }, +); From 00207f48c159d4333a05b8b4be6fe6abcc84cbce Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:15:31 +0900 Subject: [PATCH 07/21] chore: update --- app/[locale]/page.tsx | 7 ------- src/sections/check.tsx | 4 ++-- src/sections/dashboard.tsx | 30 +++++++++++++++--------------- src/sections/mind.tsx | 4 ++-- src/sections/products.tsx | 4 ++-- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index af6c9180..1b66fa0c 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -28,7 +28,6 @@ import { Button } from "@lightdotso/ui/components/button"; import { TwitterLogoIcon } from "@radix-ui/react-icons"; import { ArrowUpRightFromSquareIcon } from "lucide-react"; import { setRequestLocale } from "next-intl/server"; -import { connection } from "next/server"; // ----------------------------------------------------------------------------- // Page @@ -39,12 +38,6 @@ import { connection } from "next/server"; export default async function IndexPage({ params, }: { params: Promise<{ locale: string }> }) { - // --------------------------------------------------------------------------- - // Server - // --------------------------------------------------------------------------- - - await connection(); - // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/src/sections/check.tsx b/src/sections/check.tsx index 41b7ae00..3987a957 100644 --- a/src/sections/check.tsx +++ b/src/sections/check.tsx @@ -14,7 +14,7 @@ import { Checklist } from "@/components/check-list"; import { PageHeader, PageHeaderSubheading } from "@/components/page-header"; -import { getQueryDatabase } from "@/services/notion"; +import { getCachedQueryDatabase } from "@/services/notion"; import { getTranslations } from "next-intl/server"; // ----------------------------------------------------------------------------- @@ -41,7 +41,7 @@ export async function Check({ dateStart }: CheckProps) { // --------------------------------------------------------------------------- const checklist = ( - await getQueryDatabase({ + await getCachedQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "ccf0648ddaab42a38644f209e6cd641f", filter: { diff --git a/src/sections/dashboard.tsx b/src/sections/dashboard.tsx index a27a4349..e44a3196 100644 --- a/src/sections/dashboard.tsx +++ b/src/sections/dashboard.tsx @@ -15,13 +15,13 @@ import { PageHeader, PageHeaderHeading } from "@/components/page-header"; import { InternalConfig } from "@/config/internal"; import { SocialConfig } from "@/config/social"; -import { getCloudflareAnalytics } from "@/services/cloudflare"; -import { getDatabaseStats } from "@/services/notion"; +import { getCachedCloudflareAnalytics } from "@/services/cloudflare"; +import { getCachedDatabaseStats } from "@/services/notion"; import { getTotalViewCount, getTotalVisitorCount } from "@/services/redis"; import { - getFollowerCount, - getImpressionCount, - getLatestPublishedTweetCount, + getCachedFollowerCount, + getCachedImpressionCount, + getCachedLatestPublishedTweetCount, } from "@/services/twitter"; import { DocumentMagnifyingGlassIcon, @@ -140,7 +140,7 @@ export async function VisitorCard() { } export async function TwitterCard() { - const followerCount = await getFollowerCount(); + const followerCount = await getCachedFollowerCount(); return ( database_id: "be3e2449e1324b518f78c21e168f5a78", filter: { diff --git a/src/sections/products.tsx b/src/sections/products.tsx index b4a707b8..13983e10 100644 --- a/src/sections/products.tsx +++ b/src/sections/products.tsx @@ -14,7 +14,7 @@ import { PageHeader, PageHeaderHeading } from "@/components/page-header"; import { SectionHeaderHeading } from "@/components/section-header"; -import { getQueryDatabase } from "@/services/notion"; +import { getCachedQueryDatabase } from "@/services/notion"; import { ArrowUpRightIcon } from "@heroicons/react/24/outline"; import { getTranslations } from "next-intl/server"; @@ -41,7 +41,7 @@ export async function Products({ isPartial }: ProductsProps) { // Services // --------------------------------------------------------------------------- - const res = await getQueryDatabase({ + const res = await getCachedQueryDatabase({ // biome-ignore lint/style/useNamingConvention: database_id: "bd49167ff0b140aea87c4548f3fbbc82", sorts: [ From 402354c27b40c584580ef7aafca97cb44eda7c26 Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:16:05 +0900 Subject: [PATCH 08/21] chore: update --- app/[locale]/[slug]/page.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/[locale]/[slug]/page.tsx b/app/[locale]/[slug]/page.tsx index 446bea42..3200e7fb 100644 --- a/app/[locale]/[slug]/page.tsx +++ b/app/[locale]/[slug]/page.tsx @@ -17,8 +17,12 @@ import { ViewCount } from "@/components/view-count"; import { extractValidUUID } from "@/lib/utils"; import { Check } from "@/sections/check"; import { Mind } from "@/sections/mind"; -import { type blockWithChildren, getBlocks, getPage } from "@/services/notion"; -import { getOpenGraphData } from "@/services/ogs"; +import { + type blockWithChildren, + getCachedBlocks, + getCachedPage, +} from "@/services/notion"; +import { getCachedOpenGraphData } from "@/services/ogs"; import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { Suspense } from "react"; @@ -30,7 +34,7 @@ import { Suspense } from "react"; export async function generateMetadata({ params, }: { params: Promise<{ slug: string }> }): Promise { - const page = await getPage((await params).slug); + const page = await getCachedPage((await params).slug); return { //@ts-ignore @@ -60,20 +64,20 @@ export default async function SlugPage({ } // Get the page - const page = await getPage(pageId); + const page = await getCachedPage(pageId); // @ts-ignore const pageEmoji = page?.icon?.emoji ?? "📄"; - const getBlocksRecursively = async ( + const getCachedBlocksRecursively = async ( blockId: string, ): Promise => { - const blocks = await getBlocks(blockId); + const blocks = await getCachedBlocks(blockId); return await Promise.all( blocks.map(async (block) => { // @ts-ignore if (block.has_children) { - const children = await getBlocksRecursively(block.id); + const children = await getCachedBlocksRecursively(block.id); return { ...block, children }; } return block; @@ -85,7 +89,7 @@ export default async function SlugPage({ // @ts-ignore const url = block.bookmark?.url ?? block.link_preview?.url; if (url) { - const ogData = await getOpenGraphData({ url }); + const ogData = await getCachedOpenGraphData({ url }); block.openGraphData = ogData; } return block; @@ -112,7 +116,7 @@ export default async function SlugPage({ const getProcessedBlocks = async ( slug: string, ): Promise => { - const blocks = await getBlocksRecursively(slug); + const blocks = await getCachedBlocksRecursively(slug); return await Promise.all(blocks.map(processBlockRecursively)); }; From f8cf9767ea77d65eb55dc82a462d80707c257ddd Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:43:15 +0900 Subject: [PATCH 09/21] chore: udpate --- app/[locale]/layout.tsx | 7 +++++++ src/components/notion.tsx | 1 + 2 files changed, 8 insertions(+) diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index b9ff0854..b2e2f9d7 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -22,6 +22,7 @@ import { getTranslations, setRequestLocale, } from "next-intl/server"; +import { connection } from "next/server"; import type { ReactNode } from "react"; // ----------------------------------------------------------------------------- @@ -71,6 +72,12 @@ export default async function RootLayout({ children, params, }: LocaleLayoutProps) { + // --------------------------------------------------------------------------- + // Server + // --------------------------------------------------------------------------- + + await connection(); + // --------------------------------------------------------------------------- // i18n // --------------------------------------------------------------------------- diff --git a/src/components/notion.tsx b/src/components/notion.tsx index 5a80a6ad..cabcc6a0 100644 --- a/src/components/notion.tsx +++ b/src/components/notion.tsx @@ -204,6 +204,7 @@ const renderBlock = ( block: blockWithChildren, theme: string, isNested = false, + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ) => { //@ts-ignore switch (block.type) { From 23f582829b1bb1270e7dec4d62022d5762cd65b4 Mon Sep 17 00:00:00 2001 From: Shun Kakinoki Date: Sun, 27 Oct 2024 11:54:50 +0900 Subject: [PATCH 10/21] chore: update --- app/layout.tsx | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index d53134b7..565c6399 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -104,33 +104,28 @@ export default function RootLayout({ children }: RootLayoutProps) { // --------------------------------------------------------------------------- return ( - <> - - + +