Skip to content

Commit e25488c

Browse files
committed
Update description for app directory
1 parent a1676b1 commit e25488c

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

README.md

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# 🔌 NEXT SUPERJSON PLUGIN
1+
<h1 align="middle"> Next SuperJSON Plugin</h1>
2+
<h3 align="middle">🔌 SuperJSON Plugin for Next.js (SWC)</h3>
3+
4+
### /pages (Pages Directory)
25

36
```jsx
47
export default function Page({ date }) {
@@ -15,15 +18,21 @@ export const getServerSideProps = () => {
1518
};
1619
```
1720

18-
<p align="middle">
19-
<strong> SWC Plugin for Next.js (Canary Recommended)</strong>
20-
</p>
21+
- Allows pre-rendering functions to return props including [Non-JSON Values](https://github.com/blitz-js/superjson#parse)(Date, Map, Set..)
22+
23+
### /app (App Directory)
2124

22-
This plugin allows the pre-rendering functions to return props **including complex objects(Date, Map, Set..) that cannot be serialized by standard JSON.**
25+
```jsx
26+
// Use "data-superjson" attribute to pass non-serializable props to client components
27+
// No needs to change the propsType of Client Component (It's type-safe!)
2328

24-
**👀 See [how it works](#how-it-works)**
29+
export default function ServerComponent() {
30+
const date = new Date();
31+
return <ClientComponent date={date} data-superjson />;
32+
}
33+
```
2534

26-
**Supported object types: [Here](https://github.com/blitz-js/superjson#parse)**
35+
- Provides `data-superjson` attribute for [Server Component > Client Component Serialization](https://beta.nextjs.org/docs/rendering/server-and-client-components#passing-props-from-server-to-client-components-serialization).
2736

2837
## Usage
2938

@@ -54,22 +63,6 @@ You can use the `excluded` option to exclude specific properties from serializat
5463
['next-superjson-plugin', { excluded: ["someProp"] }],
5564
```
5665

57-
### Server Component -> Client Component
58-
59-
```jsx
60-
export default function ServerComponent() {
61-
const date = new Date();
62-
return (
63-
<>
64-
<AnotherServerComponent date={date} />
65-
66-
{/* Use "data-superjson" attribute to pass non-serializable props to client components */}
67-
<ClientComponent date={date} data-superjson />
68-
</>
69-
);
70-
}
71-
```
72-
7366
## How it works
7467

7568
```mermaid
@@ -78,19 +71,23 @@ sequenceDiagram
7871
participant SWC Plugin
7972
participant SuperJSON
8073
Next.js->>SWC Plugin: Request Transform
81-
SWC Plugin->>SWC Plugin: Transform Pages <br> To Use SuperJSON
82-
SWC Plugin->>Next.js: Take Pages
74+
SWC Plugin->>SWC Plugin: Transform Pages/Components <br> To Use SuperJSON
75+
SWC Plugin->>Next.js: Take Modules
8376
Next.js-->SuperJSON: Connected
8477
Next.js->>SuperJSON: Serialize Props <br> (Date, BigInt, Set, Map..)
85-
Note over SWC Plugin: getInitialProps <br> getServerSideProps <br> getStaticProps
78+
Note over SWC Plugin: getInitialProps <br> getServerSideProps <br> getStaticProps <br> Server Components
8679
SuperJSON->>Next.js: Deserialize Props
87-
Note over SWC Plugin: Page Component
80+
Note over SWC Plugin: Pages <br> Client Components
8881
8982
```
9083

91-
## Contributing
84+
## Bug Report
85+
86+
⚠️ Keep in mind: SWC Plugin is still an experimental feature for Next.js
87+
88+
Plugin always ensures compatibility with [Next.js Canary version](https://nextjs.org/docs/messages/opening-an-issue) only.
9289

93-
[Leave an issue](https://github.com/orionmiz/next-superjson-plugin/issues)
90+
[Leave an Issue](https://github.com/orionmiz/next-superjson-plugin/issues)
9491

9592
## Special Thanks
9693

0 commit comments

Comments
 (0)