-
Notifications
You must be signed in to change notification settings - Fork 84
feat: static assets incremental cache #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
65251e7
feat: static assets incremental cache
james-elicx cbab649
copying cache assets for population
james-elicx 6661205
e2e
james-elicx e26f47d
changeset
james-elicx 54f7956
Apply suggestions from code review
james-elicx c86e2bc
use for ssg app
james-elicx e0dbf2e
align with other inc cache changes
james-elicx efbacab
only use cpSync
james-elicx a2410f4
update comment
james-elicx 05fa161
remove kv from ssg app
james-elicx aa77eff
lint
james-elicx 0690ff9
remove .next files
james-elicx 8b047c8
copy entire directory
james-elicx 1f8aac2
Update packages/cloudflare/src/api/overrides/incremental-cache/static…
james-elicx 49dcb51
Update examples/overrides/static-assets-incremental-cache/wrangler.jsonc
james-elicx 836d162
Update examples/overrides/static-assets-incremental-cache/wrangler.jsonc
james-elicx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@opennextjs/cloudflare": patch | ||
| --- | ||
|
|
||
| feat: static assets incremental cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
examples/overrides/static-assets-incremental-cache/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/versions | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
|
|
||
| # playwright | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ |
11 changes: 11 additions & 0 deletions
11
examples/overrides/static-assets-incremental-cache/app/action.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| "use server"; | ||
|
|
||
| import { revalidatePath, revalidateTag } from "next/cache"; | ||
|
|
||
| export async function revalidateTagAction() { | ||
| revalidateTag("date"); | ||
| } | ||
|
|
||
| export async function revalidatePathAction() { | ||
| revalidatePath("/"); | ||
| } |
27 changes: 27 additions & 0 deletions
27
examples/overrides/static-assets-incremental-cache/app/components/revalidationButtons.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| "use client"; | ||
|
|
||
| import { revalidateTagAction, revalidatePathAction } from "../action"; | ||
|
|
||
| export default function RevalidationButtons() { | ||
| return ( | ||
| <div> | ||
| <button | ||
| data-testid="revalidate-tag" | ||
| onClick={async () => { | ||
| await revalidateTagAction(); | ||
| }} | ||
| > | ||
| Invalidate tag | ||
| </button> | ||
|
|
||
| <button | ||
| data-testid="revalidate-path" | ||
| onClick={async () => { | ||
| await revalidatePathAction(); | ||
| }} | ||
| > | ||
| Invalidate Path | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
examples/overrides/static-assets-incremental-cache/app/globals.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| html, | ||
| body { | ||
| max-width: 100vw; | ||
| overflow-x: hidden; | ||
| height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| footer { | ||
| padding: 1rem; | ||
| display: flex; | ||
| justify-content: end; | ||
| } |
28 changes: 28 additions & 0 deletions
28
examples/overrides/static-assets-incremental-cache/app/layout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type { Metadata } from "next"; | ||
| import "./globals.css"; | ||
|
|
||
| import { getCloudflareContext } from "@opennextjs/cloudflare"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "SSG App", | ||
| description: "An app in which all the routes are SSG'd", | ||
| }; | ||
|
|
||
| export default async function RootLayout({ | ||
| children, | ||
| }: Readonly<{ | ||
| children: React.ReactNode; | ||
| }>) { | ||
| const cloudflareContext = await getCloudflareContext({ | ||
| async: true, | ||
| }); | ||
|
|
||
| return ( | ||
| <html lang="en"> | ||
| <body> | ||
| {children} | ||
| <footer data-testid="app-version">{cloudflareContext.env.APP_VERSION}</footer> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
17 changes: 17 additions & 0 deletions
17
examples/overrides/static-assets-incremental-cache/app/page.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| .page { | ||
| display: grid; | ||
| grid-template-rows: 20px 1fr 20px; | ||
| align-items: center; | ||
| justify-items: center; | ||
| flex: 1; | ||
| border: 3px solid gray; | ||
| margin: 1rem; | ||
| margin-block-end: 0; | ||
| } | ||
|
|
||
| .main { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 32px; | ||
| grid-row-start: 2; | ||
| } |
26 changes: 26 additions & 0 deletions
26
examples/overrides/static-assets-incremental-cache/app/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { unstable_cache } from "next/cache"; | ||
| import styles from "./page.module.css"; | ||
| import RevalidationButtons from "./components/revalidationButtons"; | ||
|
|
||
| const fetchedDateCb = unstable_cache( | ||
| async () => { | ||
| return Date.now(); | ||
| }, | ||
| ["date"], | ||
| { tags: ["date"] } | ||
| ); | ||
|
|
||
| export default async function Home() { | ||
| const fetchedDate = await fetchedDateCb(); | ||
| return ( | ||
| <div className={styles.page}> | ||
| <main className={styles.main}> | ||
| <h1>Hello from a Statically generated page</h1> | ||
| <p data-testid="date-local">{Date.now()}</p> | ||
| <p data-testid="date-fetched">{fetchedDate}</p> | ||
|
|
||
| <RevalidationButtons /> | ||
| </main> | ||
| </div> | ||
| ); | ||
| } |
41 changes: 41 additions & 0 deletions
41
examples/overrides/static-assets-incremental-cache/e2e/base.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
|
|
||
| test.describe("static-assets-incremental-cache", () => { | ||
| test("the index page should work", async ({ page }) => { | ||
| await page.goto("/"); | ||
| await expect(page.getByText("Hello from a Statically generated page")).toBeVisible(); | ||
| }); | ||
|
|
||
| test("the index page should keep the same date on reload", async ({ page }) => { | ||
| await page.goto("/"); | ||
| const date = await page.getByTestId("date-local").textContent(); | ||
| expect(date).not.toBeNull(); | ||
| await page.reload(); | ||
| const newDate = await page.getByTestId("date-local").textContent(); | ||
| expect(date).toEqual(newDate); | ||
| }); | ||
|
|
||
| test("the index page should keep the same data on reload when trying to use revalidateTag", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto("/"); | ||
| const date = await page.getByTestId("date-fetched").textContent(); | ||
| await page.getByTestId("revalidate-tag").click(); | ||
| await page.waitForTimeout(100); | ||
| await page.reload(); | ||
| const newDate = await page.getByTestId("date-fetched").textContent(); | ||
| expect(date).toEqual(newDate); | ||
| }); | ||
|
|
||
| test("the index page should keep the same data on reload when trying to use revalidatePath", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto("/"); | ||
| const date = await page.getByTestId("date-fetched").textContent(); | ||
| await page.getByTestId("revalidate-path").click(); | ||
| await page.waitForTimeout(100); | ||
| await page.reload(); | ||
| const newDate = await page.getByTestId("date-fetched").textContent(); | ||
| expect(date).toEqual(newDate); | ||
| }); | ||
| }); |
7 changes: 7 additions & 0 deletions
7
examples/overrides/static-assets-incremental-cache/e2e/playwright.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { configurePlaywright } from "../../../common/config-e2e"; | ||
|
|
||
| // Here we don't want to run the tests in parallel | ||
| export default configurePlaywright("static-assets-incremental-cache", { | ||
| isCI: !!process.env.CI, | ||
| parallel: false, | ||
| }); |
5 changes: 5 additions & 0 deletions
5
examples/overrides/static-assets-incremental-cache/next-env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
11 changes: 11 additions & 0 deletions
11
examples/overrides/static-assets-incremental-cache/next.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { NextConfig } from "next"; | ||
| import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare"; | ||
|
|
||
| initOpenNextCloudflareForDev(); | ||
|
|
||
| const nextConfig: NextConfig = { | ||
| typescript: { ignoreBuildErrors: true }, | ||
| eslint: { ignoreDuringBuilds: true }, | ||
| }; | ||
|
|
||
| export default nextConfig; |
6 changes: 6 additions & 0 deletions
6
examples/overrides/static-assets-incremental-cache/open-next.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineCloudflareConfig } from "@opennextjs/cloudflare"; | ||
| import staticAssetsIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache"; | ||
|
|
||
| export default defineCloudflareConfig({ | ||
| incrementalCache: staticAssetsIncrementalCache, | ||
| }); |
29 changes: 29 additions & 0 deletions
29
examples/overrides/static-assets-incremental-cache/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "static-assets-incremental-cache", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start", | ||
| "lint": "next lint", | ||
| "build:worker": "pnpm opennextjs-cloudflare build", | ||
| "preview:worker": "pnpm opennextjs-cloudflare preview", | ||
| "preview": "pnpm build:worker && pnpm preview:worker", | ||
| "e2e": "playwright test -c e2e/playwright.config.ts" | ||
| }, | ||
| "dependencies": { | ||
| "react": "catalog:e2e", | ||
| "react-dom": "catalog:e2e", | ||
| "next": "catalog:e2e" | ||
| }, | ||
| "devDependencies": { | ||
| "@opennextjs/cloudflare": "workspace:*", | ||
| "@playwright/test": "catalog:", | ||
| "@types/node": "catalog:", | ||
| "@types/react": "catalog:e2e", | ||
| "@types/react-dom": "catalog:e2e", | ||
| "typescript": "catalog:", | ||
| "wrangler": "catalog:" | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
examples/overrides/static-assets-incremental-cache/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2017", | ||
| "lib": ["dom", "dom.iterable", "esnext"], | ||
| "allowJs": true, | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "noEmit": true, | ||
| "esModuleInterop": true, | ||
| "module": "esnext", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "jsx": "preserve", | ||
| "incremental": true, | ||
| "plugins": [ | ||
| { | ||
| "name": "next" | ||
| } | ||
| ], | ||
| "paths": { | ||
| "@/*": ["./*"] | ||
| } | ||
| }, | ||
| "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
| "exclude": ["node_modules"] | ||
| } |
17 changes: 17 additions & 0 deletions
17
examples/overrides/static-assets-incremental-cache/wrangler.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "main": ".open-next/worker.js", | ||
| "name": "static-assets-incremental-cache", | ||
| "compatibility_date": "2025-02-04", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| "assets": { | ||
| "directory": ".open-next/assets", | ||
| "binding": "ASSETS" | ||
| }, | ||
| "services": [ | ||
| { | ||
| "binding": "WORKER_SELF_REFERENCE", | ||
| "service": "static-assets-incremental-cache" | ||
| } | ||
| ] | ||
james-elicx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { defineCloudflareConfig } from "@opennextjs/cloudflare"; | ||
| import kvIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/kv-incremental-cache"; | ||
| import staticAssetsIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache"; | ||
|
|
||
| export default defineCloudflareConfig({ | ||
| incrementalCache: kvIncrementalCache, | ||
| incrementalCache: staticAssetsIncrementalCache, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.