Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/next-app/app/api/tweet/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { NextResponse } from 'next/server'
import { getTweet } from 'react-tweet/api'

export const fetchCache = 'only-cache'
import { cacheLife } from 'next/cache'

export async function GET(
_req: Request,
{ params }: RouteContext<'/api/tweet/[id]'>
) {
'use cache'
cacheLife('days')

try {
const { id } = await params
const tweet = await getTweet(id)
Expand Down
23 changes: 18 additions & 5 deletions apps/next-app/app/light/[tweet]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Tweet } from 'react-tweet'
import { getTweet } from 'react-tweet/api'
import { cacheLife } from 'next/cache'
import { components } from './tweet-components'

type Props = {
params: Promise<{ tweet: string }>
}

export const revalidate = 1800
export async function generateStaticParams() {
return [{ tweet: '1969515038512926823' }]
}

export async function generateMetadata({ params }: Props) {
const id = await params.then((p) => p.tweet)
'use cache'
cacheLife('hours')

const { tweet: id } = await params
const tweet = await getTweet(id).catch(() => undefined)

if (!tweet) return { title: 'Next Tweet' }
Expand All @@ -24,7 +30,14 @@ export async function generateMetadata({ params }: Props) {
return { title: `${text}${username}` }
}

export default async function Page({ params }: Props) {
const id = await params.then((p) => p.tweet)
return <Tweet id={id} components={components} />
async function TweetContent({ params }: Props) {
'use cache'
cacheLife('hours')

const { tweet } = await params
return <Tweet id={tweet} components={components} />
}

export default function Page({ params }: Props) {
return <TweetContent params={params} />
}
8 changes: 5 additions & 3 deletions apps/next-app/app/light/cache/[tweet]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Suspense } from 'react'
import { TweetSkeleton } from 'react-tweet'
import TweetPage from './tweet-page'

export const revalidate = 86400
type Props = {
params: Promise<{ tweet: string }>
}

const Page = ({ params }: { params: { tweet: string } }) => (
const Page = ({ params }: Props) => (
<Suspense fallback={<TweetSkeleton />}>
<TweetPage id={params.tweet} />
<TweetPage params={params} />
</Suspense>
)

Expand Down
19 changes: 11 additions & 8 deletions apps/next-app/app/light/cache/[tweet]/tweet-page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { unstable_cache } from 'next/cache'
import { getTweet as _getTweet } from 'react-tweet/api'
import { cacheLife } from 'next/cache'
import { getTweet } from 'react-tweet/api'
import { EmbeddedTweet, TweetNotFound } from 'react-tweet'

const getTweet = unstable_cache(
async (id: string) => _getTweet(id),
['tweet'],
{ revalidate: 3600 * 24 }
)
type Props = {
params: Promise<{ tweet: string }>
}

const TweetPage = async ({ params }: Props) => {
'use cache'
cacheLife('days')

const { tweet: id } = await params

const TweetPage = async ({ id }: { id: string }) => {
try {
const tweet = await getTweet(id)
return tweet ? <EmbeddedTweet tweet={tweet} /> : <TweetNotFound />
Expand Down
8 changes: 5 additions & 3 deletions apps/next-app/app/light/suspense/[tweet]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Suspense } from 'react'
import { TweetSkeleton } from 'react-tweet'
import TweetPage from './tweet-page'

export const revalidate = 3600
type Props = {
params: Promise<{ tweet: string }>
}

const Page = ({ params }: { params: { tweet: string } }) => (
const Page = ({ params }: Props) => (
<Suspense fallback={<TweetSkeleton />}>
<TweetPage id={params.tweet} />
<TweetPage params={params} />
</Suspense>
)

Expand Down
8 changes: 7 additions & 1 deletion apps/next-app/app/light/suspense/[tweet]/tweet-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { getTweet } from 'react-tweet/api'
import { EmbeddedTweet, TweetNotFound } from 'react-tweet'

const TweetPage = async ({ id }: { id: string }) => {
type Props = {
params: Promise<{ tweet: string }>
}

const TweetPage = async ({ params }: Props) => {
const { tweet: id } = await params

try {
const tweet = await getTweet(id)
return tweet ? <EmbeddedTweet tweet={tweet} /> : <TweetNotFound />
Expand Down
8 changes: 5 additions & 3 deletions apps/next-app/app/light/vercel-kv/[tweet]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Suspense } from 'react'
import { TweetSkeleton } from 'react-tweet'
import TweetPage from './tweet-page'

export const revalidate = 86400
type Props = {
params: Promise<{ tweet: string }>
}

const Page = ({ params }: { params: { tweet: string } }) => (
const Page = ({ params }: Props) => (
<Suspense fallback={<TweetSkeleton />}>
<TweetPage id={params.tweet} />
<TweetPage params={params} />
</Suspense>
)

Expand Down
8 changes: 7 additions & 1 deletion apps/next-app/app/light/vercel-kv/[tweet]/tweet-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { fetchTweet, Tweet } from 'react-tweet/api'
import { EmbeddedTweet, TweetNotFound } from 'react-tweet'
import { kv } from '@vercel/kv'

type Props = {
params: Promise<{ tweet: string }>
}

async function getTweet(
id: string,
fetchOptions?: RequestInit
Expand All @@ -25,7 +29,9 @@ async function getTweet(
return cachedTweet ?? undefined
}

const TweetPage = async ({ id }: { id: string }) => {
const TweetPage = async ({ params }: Props) => {
const { tweet: id } = await params

try {
const tweet = await getTweet(id)
return tweet ? <EmbeddedTweet tweet={tweet} /> : <TweetNotFound />
Expand Down
1 change: 1 addition & 0 deletions apps/next-app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const withMDX = mdx()

/** @type {import('next').NextConfig} */
const nextConfig = {
cacheComponents: true,
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
images: {
remotePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion apps/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@next/mdx": "^15.5.3",
"@vercel/kv": "^3.0.0",
"clsx": "^2.1.1",
"next": "15.6.0-canary.59",
"next": "latest",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"react-tweet": "workspace:*"
Expand Down
3 changes: 2 additions & 1 deletion apps/next-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
".next/types/**/*.ts",
".next/dev/types/**/*.ts"
],
"exclude": [
"node_modules"
Expand Down
Loading