diff --git a/packages/react-server/examples/basic/deps/cjs/README.md b/packages/react-server/examples/basic/deps/cjs/README.md
new file mode 100644
index 000000000..0951d1715
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/README.md
@@ -0,0 +1,17 @@
+```jsx
+// in server component
+import { TestServer } from "@hiogawa/test-dep-cjs/server"
+
+export default function Page() {
+ return // should show [ok]
+}
+```
+
+```jsx
+// in server component
+import { TestServer } from "@hiogawa/test-dep-cjs/server2"
+
+export default function Page() {
+ return // should show [ok]
+}
+```
diff --git a/packages/react-server/examples/basic/deps/cjs/client-dep.cjs b/packages/react-server/examples/basic/deps/cjs/client-dep.cjs
new file mode 100644
index 000000000..f29f7b542
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/client-dep.cjs
@@ -0,0 +1 @@
+exports.test = "[ok]";
diff --git a/packages/react-server/examples/basic/deps/cjs/client.js b/packages/react-server/examples/basic/deps/cjs/client.js
new file mode 100644
index 000000000..e885dba61
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/client.js
@@ -0,0 +1,8 @@
+"use client";
+
+import React from "react";
+import dep from "./client-dep.cjs";
+
+export function TestClient() {
+ return React.createElement("span", null, dep.test);
+}
diff --git a/packages/react-server/examples/basic/deps/cjs/package.json b/packages/react-server/examples/basic/deps/cjs/package.json
new file mode 100644
index 000000000..573131b9c
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "@hiogawa/test-dep-cjs",
+ "private": true,
+ "type": "module",
+ "exports": {
+ "./server": "./server.js",
+ "./server2": "./server2.js",
+ "./client": "./client.js"
+ },
+ "dependencies": {
+ "react": "*"
+ },
+ "peerDependencies": {
+ "react": "*"
+ }
+}
diff --git a/packages/react-server/examples/basic/deps/cjs/server.js b/packages/react-server/examples/basic/deps/cjs/server.js
new file mode 100644
index 000000000..658470a2e
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/server.js
@@ -0,0 +1,9 @@
+import React from "react";
+
+// when consuming client component internally,
+// this cannot be optimized and thus cjs dep fails.
+import { TestClient } from "./client.js";
+
+export function TestServer() {
+ return React.createElement(TestClient);
+}
diff --git a/packages/react-server/examples/basic/deps/cjs/server2.js b/packages/react-server/examples/basic/deps/cjs/server2.js
new file mode 100644
index 000000000..84eab6515
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/cjs/server2.js
@@ -0,0 +1,6 @@
+import { TestClient } from "@hiogawa/test-dep-cjs/client";
+import React from "react";
+
+export function TestServer() {
+ return React.createElement(TestClient);
+}
diff --git a/packages/react-server/examples/basic/deps/context/README.md b/packages/react-server/examples/basic/deps/context/README.md
new file mode 100644
index 000000000..e9dcd77c0
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/context/README.md
@@ -0,0 +1,21 @@
+```jsx
+// in server component
+
+import { TestServer } from "@hiogawa/test-dep-context/server"
+import { TestClient } from "@hiogawa/test-dep-context/client"
+
+export default function Page() {
+ return // should show [ok]
+}
+```
+
+```jsx
+// in server component
+
+import { TestServer } from "@hiogawa/test-dep-context/server2"
+import { TestClient } from "@hiogawa/test-dep-context/client"
+
+export default function Page() {
+ return // should show [ok]
+}
+```
diff --git a/packages/react-server/examples/basic/deps/context/client.js b/packages/react-server/examples/basic/deps/context/client.js
new file mode 100644
index 000000000..d76e25098
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/context/client.js
@@ -0,0 +1,19 @@
+"use client";
+
+import React from "react";
+
+const MyContext = React.createContext("not-ok");
+
+export function MyContextProvider(props) {
+ return React.createElement(
+ MyContext.Provider,
+ { value: "ok" },
+ props.children,
+ );
+}
+
+// consume own context in client entry
+export function TestClient() {
+ const value = React.useContext(MyContext);
+ return React.createElement("span", null, `[context: ${value}]`);
+}
diff --git a/packages/react-server/examples/basic/deps/context/package.json b/packages/react-server/examples/basic/deps/context/package.json
new file mode 100644
index 000000000..9e55bf4c1
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/context/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "@hiogawa/test-dep-context",
+ "private": true,
+ "type": "module",
+ "exports": {
+ "./server": "./server.js",
+ "./server2": "./server2.js",
+ "./client": "./client.js"
+ },
+ "dependencies": {
+ "react": "*"
+ },
+ "peerDependencies": {
+ "react": "*"
+ }
+}
diff --git a/packages/react-server/examples/basic/deps/context/server.js b/packages/react-server/examples/basic/deps/context/server.js
new file mode 100644
index 000000000..528f5fd74
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/context/server.js
@@ -0,0 +1,6 @@
+import React from "react";
+import { MyContextProvider } from "./client.js";
+
+export function TestServer(props) {
+ return React.createElement(MyContextProvider, null, props.children);
+}
diff --git a/packages/react-server/examples/basic/deps/context/server2.js b/packages/react-server/examples/basic/deps/context/server2.js
new file mode 100644
index 000000000..5deffdffd
--- /dev/null
+++ b/packages/react-server/examples/basic/deps/context/server2.js
@@ -0,0 +1,10 @@
+// difference from `server.js` is that
+// this uses self exports reference `@hiogawa/test-dep-context/client`
+// instead of relative reference `./client.js`
+import { MyContextProvider } from "@hiogawa/test-dep-context/client";
+import React from "react";
+
+// consume own provider in server entr
+export function TestServer(props) {
+ return React.createElement(MyContextProvider, null, props.children);
+}
diff --git a/packages/react-server/examples/basic/package.json b/packages/react-server/examples/basic/package.json
index 4d3f1a0d2..cb4948dd7 100644
--- a/packages/react-server/examples/basic/package.json
+++ b/packages/react-server/examples/basic/package.json
@@ -24,6 +24,8 @@
},
"dependencies": {
"@hiogawa/react-server": "latest",
+ "@hiogawa/test-dep-cjs": "file:deps/cjs",
+ "@hiogawa/test-dep-context": "file:deps/context",
"@hiogawa/test-dep-mixed": "file:deps/mixed",
"@hiogawa/test-dep-server-component": "file:deps/server-component",
"@hiogawa/test-dep-use-client": "file:deps/use-client",
diff --git a/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs/page.tsx b/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs/page.tsx
new file mode 100644
index 000000000..94f27f278
--- /dev/null
+++ b/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs/page.tsx
@@ -0,0 +1,10 @@
+// @ts-ignore
+import { TestServer } from "@hiogawa/test-dep-cjs/server";
+
+export default function Page() {
+ return (
+
+
+
+ );
+}
diff --git a/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs2/page.tsx b/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs2/page.tsx
new file mode 100644
index 000000000..056df9b33
--- /dev/null
+++ b/packages/react-server/examples/basic/src/routes/test/deps/examples/cjs2/page.tsx
@@ -0,0 +1,10 @@
+// @ts-ignore
+import { TestServer } from "@hiogawa/test-dep-cjs/server2";
+
+export default function Page() {
+ return (
+
+
+
+ );
+}
diff --git a/packages/react-server/examples/basic/src/routes/test/deps/examples/context/page.tsx b/packages/react-server/examples/basic/src/routes/test/deps/examples/context/page.tsx
new file mode 100644
index 000000000..dc2ba73c1
--- /dev/null
+++ b/packages/react-server/examples/basic/src/routes/test/deps/examples/context/page.tsx
@@ -0,0 +1,12 @@
+// @ts-ignore
+import { TestClient } from "@hiogawa/test-dep-context/client";
+// @ts-ignore
+import { TestServer } from "@hiogawa/test-dep-context/server";
+
+export default function Page() {
+ return (
+
+
+
+ );
+}
diff --git a/packages/react-server/examples/basic/src/routes/test/deps/examples/context2/page.tsx b/packages/react-server/examples/basic/src/routes/test/deps/examples/context2/page.tsx
new file mode 100644
index 000000000..1a414ee62
--- /dev/null
+++ b/packages/react-server/examples/basic/src/routes/test/deps/examples/context2/page.tsx
@@ -0,0 +1,14 @@
+// @ts-ignore
+import { TestClient } from "@hiogawa/test-dep-context/client";
+// @ts-ignore
+import { TestServer } from "@hiogawa/test-dep-context/server2";
+
+export default function Page() {
+ return (
+
+
+
+
+
+ );
+}
diff --git a/packages/react-server/examples/basic/src/routes/test/deps/layout.tsx b/packages/react-server/examples/basic/src/routes/test/deps/layout.tsx
index a9fd53757..f389b7fb9 100644
--- a/packages/react-server/examples/basic/src/routes/test/deps/layout.tsx
+++ b/packages/react-server/examples/basic/src/routes/test/deps/layout.tsx
@@ -5,7 +5,16 @@ export default function Layout(props: LayoutProps) {
return (
Test Dependencies
-
+
{props.children}
);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d7aed141c..b4e641d51 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -209,6 +209,12 @@ importers:
'@hiogawa/react-server':
specifier: latest
version: link:../..
+ '@hiogawa/test-dep-cjs':
+ specifier: file:deps/cjs
+ version: file:packages/react-server/examples/basic/deps/cjs(react@19.0.0)
+ '@hiogawa/test-dep-context':
+ specifier: file:deps/context
+ version: file:packages/react-server/examples/basic/deps/context(react@19.0.0)
'@hiogawa/test-dep-mixed':
specifier: file:deps/mixed
version: '@hiogawa/test-deps-mixed@file:packages/react-server/examples/basic/deps/mixed(react@19.0.0)'
@@ -1978,6 +1984,16 @@ packages:
'@trpc/server':
optional: true
+ '@hiogawa/test-dep-cjs@file:packages/react-server/examples/basic/deps/cjs':
+ resolution: {directory: packages/react-server/examples/basic/deps/cjs, type: directory}
+ peerDependencies:
+ react: ^19.0.0
+
+ '@hiogawa/test-dep-context@file:packages/react-server/examples/basic/deps/context':
+ resolution: {directory: packages/react-server/examples/basic/deps/context, type: directory}
+ peerDependencies:
+ react: ^19.0.0
+
'@hiogawa/test-deps-mixed@file:packages/react-server/examples/basic/deps/mixed':
resolution: {directory: packages/react-server/examples/basic/deps/mixed, type: directory}
peerDependencies:
@@ -6227,6 +6243,14 @@ snapshots:
'@hiogawa/query-proxy@0.1.1-pre.3': {}
+ '@hiogawa/test-dep-cjs@file:packages/react-server/examples/basic/deps/cjs(react@19.0.0)':
+ dependencies:
+ react: 19.0.0
+
+ '@hiogawa/test-dep-context@file:packages/react-server/examples/basic/deps/context(react@19.0.0)':
+ dependencies:
+ react: 19.0.0
+
'@hiogawa/test-deps-mixed@file:packages/react-server/examples/basic/deps/mixed(react@19.0.0)':
dependencies:
react: 19.0.0