From 4e0e7d0dc3576a220af2249d8948f6be7c5aab09 Mon Sep 17 00:00:00 2001 From: kqito <29191111+kqito@users.noreply.github.com> Date: Sat, 22 Mar 2025 14:36:16 +0900 Subject: [PATCH 1/9] Fix app workflows --- .github/workflows/create_heroku_review_app.yaml | 2 +- .github/workflows/destroy_heroku_review_app.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create_heroku_review_app.yaml b/.github/workflows/create_heroku_review_app.yaml index 61605fb65..aac9136fa 100644 --- a/.github/workflows/create_heroku_review_app.yaml +++ b/.github/workflows/create_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: create-review-app: runs-on: ubuntu-latest steps: - - uses: fastruby/manage-heroku-review-app@9fa49f0320460f278c3687bc348dd0cbb18555dc # v1.3 + - uses: kqito/manage-heroku-review-app@bd802202dcc426578871d210d8f0106ecae70068 with: action: create env: diff --git a/.github/workflows/destroy_heroku_review_app.yaml b/.github/workflows/destroy_heroku_review_app.yaml index b2bf67949..efdedb166 100644 --- a/.github/workflows/destroy_heroku_review_app.yaml +++ b/.github/workflows/destroy_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: destroy-review-app: runs-on: ubuntu-latest steps: - - uses: fastruby/manage-heroku-review-app@9fa49f0320460f278c3687bc348dd0cbb18555dc # v1.3 + - uses: kqito/manage-heroku-review-app@bd802202dcc426578871d210d8f0106ecae70068 with: action: destroy env: From 7a390ed805478cc13c65ef78cbe9a090ca4ea047 Mon Sep 17 00:00:00 2001 From: kqito <29191111+kqito@users.noreply.github.com> Date: Sat, 22 Mar 2025 15:41:28 +0900 Subject: [PATCH 2/9] Fix version of kqito/manage-heroku-review-app temporary --- .github/workflows/create_heroku_review_app.yaml | 2 +- .github/workflows/destroy_heroku_review_app.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create_heroku_review_app.yaml b/.github/workflows/create_heroku_review_app.yaml index aac9136fa..c5ba3cead 100644 --- a/.github/workflows/create_heroku_review_app.yaml +++ b/.github/workflows/create_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: create-review-app: runs-on: ubuntu-latest steps: - - uses: kqito/manage-heroku-review-app@bd802202dcc426578871d210d8f0106ecae70068 + - uses: kqito/manage-heroku-review-app@main with: action: create env: diff --git a/.github/workflows/destroy_heroku_review_app.yaml b/.github/workflows/destroy_heroku_review_app.yaml index efdedb166..7b31edba9 100644 --- a/.github/workflows/destroy_heroku_review_app.yaml +++ b/.github/workflows/destroy_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: destroy-review-app: runs-on: ubuntu-latest steps: - - uses: kqito/manage-heroku-review-app@bd802202dcc426578871d210d8f0106ecae70068 + - uses: kqito/manage-heroku-review-app@main with: action: destroy env: From 92f579be4be81e8a74a970e7b151885afde6691a Mon Sep 17 00:00:00 2001 From: kqito <29191111+kqito@users.noreply.github.com> Date: Sat, 22 Mar 2025 17:08:56 +0900 Subject: [PATCH 3/9] Pin version of kqito/manage-heroku-review-app to specific commit hash --- .github/workflows/create_heroku_review_app.yaml | 2 +- .github/workflows/destroy_heroku_review_app.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create_heroku_review_app.yaml b/.github/workflows/create_heroku_review_app.yaml index c5ba3cead..7e3ade03a 100644 --- a/.github/workflows/create_heroku_review_app.yaml +++ b/.github/workflows/create_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: create-review-app: runs-on: ubuntu-latest steps: - - uses: kqito/manage-heroku-review-app@main + - uses: kqito/manage-heroku-review-app@55e434ad5ac86f21cf2f7654de1566973fbc7046 with: action: create env: diff --git a/.github/workflows/destroy_heroku_review_app.yaml b/.github/workflows/destroy_heroku_review_app.yaml index 7b31edba9..cbcec744a 100644 --- a/.github/workflows/destroy_heroku_review_app.yaml +++ b/.github/workflows/destroy_heroku_review_app.yaml @@ -7,7 +7,7 @@ jobs: destroy-review-app: runs-on: ubuntu-latest steps: - - uses: kqito/manage-heroku-review-app@main + - uses: kqito/manage-heroku-review-app@55e434ad5ac86f21cf2f7654de1566973fbc7046 with: action: destroy env: From d863f461dd03f36e4db1025f4771a96589c54ce5 Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 10:07:50 +0900 Subject: [PATCH 4/9] Remove inline source map from webpack configuration --- workspaces/client/webpack.config.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/workspaces/client/webpack.config.mjs b/workspaces/client/webpack.config.mjs index 9164a996e..a90d0fddc 100644 --- a/workspaces/client/webpack.config.mjs +++ b/workspaces/client/webpack.config.mjs @@ -4,7 +4,6 @@ import webpack from 'webpack'; /** @type {import('webpack').Configuration} */ const config = { - devtool: 'inline-source-map', entry: './src/main.tsx', mode: 'none', module: { From a281d04fea22b85da8be845a1d39a771d1b8850f Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 10:14:37 +0900 Subject: [PATCH 5/9] Remove unused image preloading logic from SSR --- workspaces/server/src/ssr.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/workspaces/server/src/ssr.tsx b/workspaces/server/src/ssr.tsx index 7603aafdd..32cb5b2ce 100644 --- a/workspaces/server/src/ssr.tsx +++ b/workspaces/server/src/ssr.tsx @@ -59,13 +59,6 @@ export function registerSsr(app: FastifyInstance): void { , ); - const rootDir = path.resolve(__dirname, '../../../'); - const imagePaths = [ - getFilePaths('public/images', rootDir), - getFilePaths('public/animations', rootDir), - getFilePaths('public/logos', rootDir), - ].flat(); - reply.type('text/html').send(/* html */ ` @@ -73,7 +66,6 @@ export function registerSsr(app: FastifyInstance): void { - ${imagePaths.map((imagePath) => ``).join('\n')} From f37d50afaf5135e28ad7ff2c5ccda57bd4c8e122 Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 17:55:13 +0900 Subject: [PATCH 6/9] Remove unused file handling functions from SSR --- workspaces/server/src/ssr.tsx | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/workspaces/server/src/ssr.tsx b/workspaces/server/src/ssr.tsx index 32cb5b2ce..80cb955a3 100644 --- a/workspaces/server/src/ssr.tsx +++ b/workspaces/server/src/ssr.tsx @@ -1,4 +1,3 @@ -import { readdirSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -13,18 +12,6 @@ import { StrictMode } from 'react'; import { renderToString } from 'react-dom/server'; import { createStaticHandler, createStaticRouter, StaticRouterProvider } from 'react-router'; -function getFiles(parent: string): string[] { - const dirents = readdirSync(parent, { withFileTypes: true }); - return dirents - .filter((dirent) => dirent.isFile() && !dirent.name.startsWith('.')) - .map((dirent) => path.join(parent, dirent.name)); -} - -function getFilePaths(relativePath: string, rootDir: string): string[] { - const files = getFiles(path.resolve(rootDir, relativePath)); - return files.map((file) => path.join('/', path.relative(rootDir, file))); -} - export function registerSsr(app: FastifyInstance): void { app.register(fastifyStatic, { prefix: '/public/', From 89763588311dc73e21b5652fafdfbabd0732f140 Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 17:58:45 +0900 Subject: [PATCH 7/9] SSR: Update hydration data handling and refactor HomePage data fetching --- workspaces/client/src/main.tsx | 4 +++- .../src/pages/home/components/HomePage.tsx | 4 ++-- workspaces/server/src/ssr.tsx | 19 ++----------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/workspaces/client/src/main.tsx b/workspaces/client/src/main.tsx index 601b7a6a5..d1a53b942 100644 --- a/workspaces/client/src/main.tsx +++ b/workspaces/client/src/main.tsx @@ -17,7 +17,9 @@ declare global { function main() { const store = createStore({}); - const router = createBrowserRouter(createRoutes(store), {}); + const router = createBrowserRouter(createRoutes(store), { + hydrationData: window.__staticRouterHydrationData, + }); hydrateRoot( document, diff --git a/workspaces/client/src/pages/home/components/HomePage.tsx b/workspaces/client/src/pages/home/components/HomePage.tsx index 86cb77e6c..dc8c891c5 100644 --- a/workspaces/client/src/pages/home/components/HomePage.tsx +++ b/workspaces/client/src/pages/home/components/HomePage.tsx @@ -1,6 +1,6 @@ import { createStore } from '@wsh-2025/client/src/app/createStore'; import { RecommendedSection } from '@wsh-2025/client/src/features/recommended/components/RecommendedSection'; -import { useRecommended } from '@wsh-2025/client/src/features/recommended/hooks/useRecommended'; +import { useLoaderData } from 'react-router'; export const prefetch = async (store: ReturnType) => { const modules = await store @@ -10,7 +10,7 @@ export const prefetch = async (store: ReturnType) => { }; export const HomePage = () => { - const modules = useRecommended({ referenceId: 'entrance' }); + const { modules } = useLoaderData>>(); return ( <> diff --git a/workspaces/server/src/ssr.tsx b/workspaces/server/src/ssr.tsx index 80cb955a3..bd2cc599c 100644 --- a/workspaces/server/src/ssr.tsx +++ b/workspaces/server/src/ssr.tsx @@ -7,7 +7,6 @@ import { createRoutes } from '@wsh-2025/client/src/app/createRoutes'; import { createStore } from '@wsh-2025/client/src/app/createStore'; import type { FastifyInstance } from 'fastify'; import { createStandardRequest } from 'fastify-standard-request-reply'; -import htmlescape from 'htmlescape'; import { StrictMode } from 'react'; import { renderToString } from 'react-dom/server'; import { createStaticHandler, createStaticRouter, StaticRouterProvider } from 'react-router'; @@ -38,7 +37,7 @@ export function registerSsr(app: FastifyInstance): void { } const router = createStaticRouter(handler.dataRoutes, context); - renderToString( + const html = renderToString( store}> @@ -47,21 +46,7 @@ export function registerSsr(app: FastifyInstance): void { ); reply.type('text/html').send(/* html */ ` - - - - - - - - - - + ${html} `); }); } From 8bc0d1a19c5156a2e516953b08ff7b5d63ecd243 Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 18:02:40 +0900 Subject: [PATCH 8/9] =?UTF-8?q?SSR:=20=E7=94=BB=E5=83=8F=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AECache-Control=E3=83=98=E3=83=83?= =?UTF-8?q?=E3=83=80=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workspaces/server/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/workspaces/server/src/index.ts b/workspaces/server/src/index.ts index e02ab7613..c3401fe27 100644 --- a/workspaces/server/src/index.ts +++ b/workspaces/server/src/index.ts @@ -13,8 +13,14 @@ async function main() { const app = fastify(); + // 画像のみキャッシュする app.addHook('onSend', async (_req, reply) => { - reply.header('cache-control', 'no-store'); + const contentType = reply.getHeader('Content-Type'); + if (reply.statusCode === 200 && typeof contentType === 'string' && contentType.startsWith('image/')) { + reply.header('Cache-Control', 'public, max-age=31536000'); + } else { + reply.header('Cache-Control', 'no-store'); + } }); app.register(cors, { origin: true, From f95d7d8756b7815ecb8ed24f028e8c16ab5bf4e6 Mon Sep 17 00:00:00 2001 From: apple-yagi Date: Sun, 23 Mar 2025 18:14:56 +0900 Subject: [PATCH 9/9] SSR: Remove version query from episode and series thumbnail URLs --- .../src/features/recommended/components/EpisodeItem.tsx | 3 ++- .../client/src/features/recommended/components/SeriesItem.tsx | 3 ++- workspaces/client/src/utils/remove-version-query.ts | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 workspaces/client/src/utils/remove-version-query.ts diff --git a/workspaces/client/src/features/recommended/components/EpisodeItem.tsx b/workspaces/client/src/features/recommended/components/EpisodeItem.tsx index 74b08745c..d79d0a16b 100644 --- a/workspaces/client/src/features/recommended/components/EpisodeItem.tsx +++ b/workspaces/client/src/features/recommended/components/EpisodeItem.tsx @@ -3,6 +3,7 @@ import { Flipped } from 'react-flip-toolkit'; import { NavLink } from 'react-router'; import { Hoverable } from '@wsh-2025/client/src/features/layout/components/Hoverable'; +import { removeVersionQuery } from '@wsh-2025/client/src/utils/remove-version-query'; interface Props { episode: { @@ -25,7 +26,7 @@ export const EpisodeItem = ({ episode }: Props) => { <>
- + {episode.premium ? ( diff --git a/workspaces/client/src/features/recommended/components/SeriesItem.tsx b/workspaces/client/src/features/recommended/components/SeriesItem.tsx index 2477b7a97..9b0732c0d 100644 --- a/workspaces/client/src/features/recommended/components/SeriesItem.tsx +++ b/workspaces/client/src/features/recommended/components/SeriesItem.tsx @@ -3,6 +3,7 @@ import { Flipped } from 'react-flip-toolkit'; import { NavLink } from 'react-router'; import { Hoverable } from '@wsh-2025/client/src/features/layout/components/Hoverable'; +import { removeVersionQuery } from '@wsh-2025/client/src/utils/remove-version-query'; interface Props { series: { @@ -21,7 +22,7 @@ export const SeriesItem = ({ series }: Props) => { <>
- +
diff --git a/workspaces/client/src/utils/remove-version-query.ts b/workspaces/client/src/utils/remove-version-query.ts new file mode 100644 index 000000000..f4f678912 --- /dev/null +++ b/workspaces/client/src/utils/remove-version-query.ts @@ -0,0 +1,4 @@ +// ?version= のクエリを削除する +export const removeVersionQuery = (url: string) => { + return url.replace(/\?version=[^&]+/, ''); +};