-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for React Server Components (#331)
- Loading branch information
1 parent
eace2a3
commit ae6c486
Showing
15 changed files
with
507 additions
and
210 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
__tests__/fixtures/basic/app/app-dir-mdx/compile-mdx/page.js
This file contains 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,35 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import dynamic from 'next/dynamic' | ||
import Test from '../../../components/test' | ||
import { paragraphCustomAlerts } from '@hashicorp/remark-plugins' | ||
import { Provider, Consumer } from '../provider' | ||
import { compileMDX } from 'next-mdx-remote/rsc' | ||
|
||
const MDX_COMPONENTS = { | ||
Test, | ||
ContextConsumer: Consumer, | ||
strong: (props) => <strong className="custom-strong" {...props} />, | ||
Dynamic: dynamic(() => import('../../../components/dynamic')), | ||
} | ||
|
||
export default async function Page() { | ||
const fixturePath = path.join(process.cwd(), 'mdx/test.mdx') | ||
const source = await fs.promises.readFile(fixturePath, 'utf8') | ||
|
||
const { content, frontmatter } = await compileMDX({ | ||
source, | ||
components: MDX_COMPONENTS, | ||
options: { | ||
mdxOptions: { remarkPlugins: [paragraphCustomAlerts] }, | ||
parseFrontmatter: true, | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
<h1>{frontmatter.title}</h1> | ||
<Provider>{content}</Provider> | ||
</> | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
__tests__/fixtures/basic/app/app-dir-mdx/mdxremote/page.js
This file contains 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,33 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import dynamic from 'next/dynamic' | ||
import Test from '../../../components/test' | ||
import { paragraphCustomAlerts } from '@hashicorp/remark-plugins' | ||
import { Provider, Consumer } from '../provider' | ||
import { MDXRemote } from 'next-mdx-remote/rsc' | ||
|
||
const MDX_COMPONENTS = { | ||
Test, | ||
ContextConsumer: Consumer, | ||
strong: (props) => <strong className="custom-strong" {...props} />, | ||
Dynamic: dynamic(() => import('../../../components/dynamic')), | ||
} | ||
|
||
export default async function Page() { | ||
const fixturePath = path.join(process.cwd(), 'mdx/test.mdx') | ||
const source = await fs.promises.readFile(fixturePath, 'utf8') | ||
|
||
return ( | ||
<> | ||
<Provider> | ||
<MDXRemote | ||
source={source} | ||
components={MDX_COMPONENTS} | ||
options={{ | ||
mdxOptions: { remarkPlugins: [paragraphCustomAlerts] }, | ||
}} | ||
/> | ||
</Provider> | ||
</> | ||
) | ||
} |
This file contains 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,35 @@ | ||
'use client' | ||
import { createContext, useEffect, useState } from 'react' | ||
|
||
const TestContext = createContext('test') | ||
const PROVIDER = { | ||
component: TestContext.Provider, | ||
props: { value: 'foo' }, | ||
} | ||
|
||
export default function Provider({ children }) { | ||
const [providerOptions, setProviderOptions] = useState(PROVIDER) | ||
|
||
useEffect(() => { | ||
setProviderOptions({ | ||
...PROVIDER, | ||
props: { | ||
value: 'bar', | ||
}, | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<TestContext.Provider {...providerOptions.props}> | ||
{children} | ||
</TestContext.Provider> | ||
) | ||
} | ||
|
||
export function Consumer() { | ||
return ( | ||
<TestContext.Consumer> | ||
{(value) => <p className="context">Context value: "{value}"</p>} | ||
</TestContext.Consumer> | ||
) | ||
} |
This file contains 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,9 @@ | ||
export default function Head() { | ||
return ( | ||
<> | ||
<title></title> | ||
<meta content="width=device-width, initial-scale=1" name="viewport" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</> | ||
) | ||
} |
This file contains 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,8 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<head /> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains 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,3 +1,4 @@ | ||
'use client' | ||
import { useState } from 'react' | ||
|
||
export default function Test({ name }) { | ||
|
This file contains 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 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |
This file contains 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
This file contains 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.