MCPcopy Index your code
hub / github.com/blitz-js/next-superjson-plugin

github.com/blitz-js/next-superjson-plugin @v0.6.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.3 ↗ · + Follow
93 symbols 140 edges 47 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Next SuperJSON Plugin

🔌 SuperJSON Plugin for Next.js (SWC)

/pages (Pages Directory)

export default function Page({ date }) {
  return 

Today is {date.toDateString()}

;
}

// You can also use getInitialProps, getStaticProps
export const getServerSideProps = () => {
  return {
    props: {
      date: new Date(),
    },
  };
};
  • Allows pre-rendering functions to return props including Non-JSON Values(Date, Map, Set..)

/app (App Directory)

// Use "data-superjson" attribute to pass non-serializable props to client components
// No needs to change the propsType of Client Component (It's type-safe!)

export default function ServerComponent() {
  const date = new Date();
  return <ClientComponent date={date} data-superjson />;
}

Usage

Install packages first:

npm install superjson next-superjson-plugin
# or Yarn
yarn add superjson next-superjson-plugin

Add the plugin into next.config.js

// next.config.js
module.exports = {
  experimental: {
    swcPlugins: [["next-superjson-plugin", {}]],
  },
};

Options

You can use the excluded option to exclude specific properties from serialization.

['next-superjson-plugin', { excluded: ["someProp"] }],

How it works

sequenceDiagram
    participant Next.js
    participant SWC Plugin
    participant SuperJSON
    Next.js->>SWC Plugin: Request Transform
    SWC Plugin->>SWC Plugin: Transform Pages/Components 

 To Use SuperJSON
    SWC Plugin->>Next.js: Take Modules
    Next.js-->SuperJSON: Connected
    Next.js->>SuperJSON: Serialize Props 

 (Date, BigInt, Set, Map..)
    Note over SWC Plugin: getInitialProps 

 getServerSideProps 

 getStaticProps 

 Server Components
    SuperJSON->>Next.js: Deserialize Props
    Note over SWC Plugin: Pages 

 Client Components

Bug Report

⚠️ Keep in mind: SWC Plugin is still an experimental feature for Next.js

Plugin always ensures compatibility with Next.js Canary version only.

Leave an Issue

Special Thanks

  • kdy1 (Main creator of swc project)

Extension points exported contracts — how you extend this code

JSXUtil (Interface)
(no doc) [2 implementers]
src/app.rs
Wrapper (Interface)
(no doc) [1 implementers]
src/utils.rs
DeclUtil (Interface)
(no doc) [1 implementers]
src/utils.rs

Core symbols most depended-on inside this repo

excluded_expr
called by 12
src/page.rs
wrap_page
called by 7
src/utils.rs
wrap_props
called by 4
src/utils.rs
superjson_import_decl
called by 3
src/utils.rs
wrap_init_props
called by 3
src/utils.rs
as_wrapped_var_decl
called by 3
src/utils.rs
temp_props_item
called by 2
src/utils.rs
temp_import_item
called by 2
src/utils.rs

Shape

Function 51
Method 21
Class 17
Interface 3
Enum 1

Languages

TypeScript67%
Rust33%

Modules by API surface

src/page.rs11 symbols
src/utils.rs9 symbols
tools/tools.tsx6 symbols
src/app.rs6 symbols
tests/fixture/page/skip/gip-in-app-js/output.js5 symbols
tests/fixture/page/skip/gip-in-app-js/code.js5 symbols
tests/fixture/page/transform/get-initial-props/class/code.js4 symbols
tests/fixture/page/transform/general/class/code.js4 symbols
tests/fixture/page/transform/get-initial-props/class/output.js3 symbols
tests/fixture/page/transform/general/class/output.js3 symbols
tests/fixture/page/skip/multiple-exports/init-and-others/output.js3 symbols
tests/fixture/page/skip/multiple-exports/init-and-others/code.js3 symbols

For agents

$ claude mcp add next-superjson-plugin \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact