Skip to content

Commit

Permalink
feat: introduce dynamicIO
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Oct 29, 2024
1 parent eb2e08c commit d0165c5
Show file tree
Hide file tree
Showing 121 changed files with 349 additions and 166 deletions.
4 changes: 2 additions & 2 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { NextConfig } from 'next';
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
// logging: {
// fetches: {
// fullUrl: true,
// },
// },
transpilePackages: ["shiki"],
experimental: {
dynamicIO: true,
taint: true,
// typedRoutes: true,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@shikijs/transformers": "^1.22.2",
"algoliasearch": "^4.24.0",
"instantsearch.js": "^4.75.3",
"next": "15.0.1",
"next": "canary",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-instantsearch": "^7.13.6",
Expand Down
98 changes: 49 additions & 49 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ self.addEventListener("fetch", (e) => {
e.respondWith(
(async () => {
const res = await fetch(e.request);
const createdAt = Date.now();
const createdAt = performance.now();

// res.text() fails is when trying to read the same response stream twice.
const clone = res.clone();
Expand Down
12 changes: 6 additions & 6 deletions src/app/search/page.tsx → src/app/_search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { Result } from "@/app/_components/search/result";
import { SearchBox } from "@/app/_components/search/searchBox";
import { client } from "@/app/_utils/algolia";
import { Suspense, useState } from "react";
import { Configure } from "react-instantsearch";
import { InstantSearchNext } from "react-instantsearch-nextjs";
// TODO: need to upgrade below
// Error: Route "/(.)search" used `headers().get('x-nonce')`. `headers()` should be awaited before using its value.
// import { Configure } from "react-instantsearch";
// import { InstantSearchNext } from "react-instantsearch-nextjs";
import { meta } from "../examples/data";

export const dynamic = "force-dynamic";

export default function Page() {
const [tag, setTag] = useState<string | null>(null);

Expand Down Expand Up @@ -42,7 +42,7 @@ export default function Page() {
))}
</ul>
<div className="flex-1 w-full md:w-0">
<Suspense>
{/* <Suspense>
<InstantSearchNext indexName="examples" searchClient={client}>
<Configure tagFilters={tag ?? undefined} />
<div className="text-gray-200 flex flex-col gap-4">
Expand All @@ -55,7 +55,7 @@ export default function Page() {
</footer>
</div>
</InstantSearchNext>
</Suspense>
</Suspense> */}
</div>
</div>
);
Expand Down
4 changes: 1 addition & 3 deletions src/app/api/now/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { NextResponse } from "next/server";

export const revalidate = 0;

export async function GET() {
return NextResponse.json({
now: Date.now(),
now: performance.now(),
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export async function getNow(id?: string) {
return Date.now();
return performance.now();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use cache";

// [!code word:force-dynamic]
import { Boundary } from "@/app/_components/boundary";
import { Suspense } from "react";

export const dynamic = "force-dynamic";
// or
// export const revalidate = 0;

export default function Page() {
export default async function Page() {
return (
<div className="flex gap-4">
<Suspense fallback={<Loading />}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use cache";

import { Boundary } from "@/app/_components/boundary";
import { Link } from "@/app/_components/link";
import type { PropsWithChildren } from "react";

export default function Page() {
export default async function Page() {
return (
<Boundary label="Page">
<div className="flex flex-col gap-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// [!code word:revalidate]
import { Boundary } from "@/app/_components/boundary";

export default async function Page() {
"use cache";

return <Boundary label="Page">{performance.now()}</Boundary>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use cache";

import { Boundary } from "@/app/_components/boundary";
import { Suspense } from "react";

export default function Page() {
export default async function Page() {
return (
<div className="flex gap-4 w-full">
<Suspense fallback={<Loading />}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// [!code word:use cache]

export default async function Page() {
return (
<div className="space-y-4">
<NoCached />
<Cached />
</div>
);
}

async function NoCached() {
return <p>no cached: {performance.now()}</p>;
}

async function Cached() {
"use cache";

return <p>cached: {performance.now()}</p>;
}
16 changes: 16 additions & 0 deletions src/app/examples/(caching)/dynamicIO/directive/file-level/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// [!code word:use cache]

"use cache";

export default async function Page() {
return (
<div>
<p>{performance.now()}</p>
<Child />
</div>
);
}

function Child() {
return <p>{performance.now()}</p>;
}
Loading

0 comments on commit d0165c5

Please sign in to comment.