Skip to content

Commit e122bf4

Browse files
feat(nextjs-mf): update module share for rsc
1 parent 10f2b73 commit e122bf4

File tree

11 files changed

+120
-110
lines changed

11 files changed

+120
-110
lines changed

apps/next-app-router-4000/app/context/context-click-counter.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { useCounter } from './counter-context';
44
import React from 'react';
55
import { Boundary } from '#/ui/boundary';
6+
import dynamic from 'next/dynamic';
7+
const Button = dynamic(() => import('remote_4001/Button'), { ssr: true });
68

79
const ContextClickCounter = () => {
810
const [count, setCount] = useCounter();
@@ -14,6 +16,7 @@ const ContextClickCounter = () => {
1416
size="small"
1517
animateRerendering={false}
1618
>
19+
<Button>testing</Button>
1720
<button
1821
onClick={() => setCount(count + 1)}
1922
className="rounded-lg bg-gray-700 px-3 py-1 text-sm font-medium tabular-nums text-gray-100 hover:bg-gray-500 hover:text-white"

apps/next-app-router-4000/app/error-handling/[categorySlug]/[subCategorySlug]/error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { Boundary } from '#/ui/boundary';
4-
import Button from '#/ui/button';
4+
import Button from 'remote_4001/Button';
55
import React from 'react';
66

77
export default function Error({ error, reset }: any) {

apps/next-app-router-4000/app/error-handling/[categorySlug]/error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { Boundary } from '#/ui/boundary';
4-
import Button from '#/ui/button';
4+
import Button from 'remote_4001/Button';
55
import React from 'react';
66

77
export default function Error({ error, reset }: any) {

apps/next-app-router-4000/app/error-handling/error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { Boundary } from '#/ui/boundary';
4-
import Button from '#/ui/button';
4+
import Button from 'remote_4001/Button';
55
import React from 'react';
66

77
export default function Error({ error, reset }: any) {

apps/next-app-router-4000/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '#/styles/globals.css';
22
import { AddressBar } from '#/ui/address-bar';
33
import Byline from '#/ui/byline';
4-
import { GlobalNav } from '#/ui/global-nav';
4+
// import { GlobalNav } from 'remote_4001/GlobalNav(rsc)';
55
import { Metadata } from 'next';
66

77
export const metadata: Metadata = {
@@ -31,7 +31,7 @@ export default function RootLayout({
3131
return (
3232
<html lang="en" className="[color-scheme:dark]">
3333
<body className="overflow-y-scroll bg-gray-1100 bg-[url('/grid.svg')] pb-36">
34-
<GlobalNav />
34+
{/*<GlobalNav />*/}
3535

3636
<div className="lg:pl-72">
3737
<div className="mx-auto max-w-4xl space-y-8 px-2 pt-20 lg:px-8 lg:py-8">

apps/next-app-router-4000/ui/buggy-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import Button from '#/ui/button';
3+
import Button from 'remote_4001/Button';
44
import React from 'react';
55

66
export default function BuggyButton() {

apps/next-app-router-4001/app/demo/page.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,58 @@ import dynamic from 'next/dynamic';
66
// Dynamically import remote components
77
const Button = dynamic(() => import('remote_4001/Button'), { ssr: true });
88
const Header = dynamic(() => import('remote_4001/Header'), { ssr: true });
9-
const ProductCard = dynamic(() => import('remote_4001/ProductCard'), { ssr: true });
9+
const ProductCard = dynamic(() => import('remote_4001/ProductCard'), {
10+
ssr: true,
11+
});
1012
const TabGroup = dynamic(() => import('remote_4001/TabGroup'), { ssr: true });
11-
const TabNavItem = dynamic(() => import('remote_4001/TabNavItem'), { ssr: true });
13+
const TabNavItem = dynamic(() => import('remote_4001/TabNavItem'), {
14+
ssr: true,
15+
});
1216
const CountUp = dynamic(() => import('remote_4001/CountUp'), { ssr: true });
13-
const RenderingInfo = dynamic(() => import('remote_4001/RenderingInfo'), { ssr: true });
17+
const RenderingInfo = dynamic(() => import('remote_4001/RenderingInfo'), {
18+
ssr: true,
19+
});
1420

1521
export default function DemoPage() {
1622
return (
1723
<div className="p-4">
1824
<Header />
1925

20-
<main className="max-w-4xl mx-auto mt-8">
21-
<h1 className="text-2xl font-bold mb-6">Remote Components Demo</h1>
26+
<main className="mx-auto mt-8 max-w-4xl">
27+
<h1 className="mb-6 text-2xl font-bold">Remote Components Demo</h1>
2228

2329
<section className="mb-8">
24-
<h2 className="text-xl font-semibold mb-4">Basic UI Components</h2>
30+
<h2 className="mb-4 text-xl font-semibold">Basic UI Components</h2>
2531
<div className="space-x-4">
2632
<Button>Primary Button</Button>
2733
<Button>Secondary Button</Button>
2834
</div>
2935
</section>
3036

3137
<section className="mb-8">
32-
<h2 className="text-xl font-semibold mb-4">Navigation Components</h2>
38+
<h2 className="mb-4 text-xl font-semibold">Navigation Components</h2>
3339
<TabGroup>
34-
<TabNavItem href="/demo/tab1" isActive={true}>Tab 1</TabNavItem>
35-
<TabNavItem href="/demo/tab2" isActive={false}>Tab 2</TabNavItem>
36-
<TabNavItem href="/demo/tab3" isActive={false}>Tab 3</TabNavItem>
40+
<TabNavItem href="/demo/tab1" isActive={true}>
41+
Tab 1
42+
</TabNavItem>
43+
<TabNavItem href="/demo/tab2" isActive={false}>
44+
Tab 2
45+
</TabNavItem>
46+
<TabNavItem href="/demo/tab3" isActive={false}>
47+
Tab 3
48+
</TabNavItem>
3749
</TabGroup>
3850
</section>
3951

4052
<section className="mb-8">
41-
<h2 className="text-xl font-semibold mb-4">Product Components</h2>
53+
<h2 className="mb-4 text-xl font-semibold">Product Components</h2>
4254
<div className="grid grid-cols-2 gap-4">
4355
<ProductCard
4456
product={{
4557
name: 'Demo Product',
4658
price: 99.99,
47-
description: 'This is a demo product to showcase the ProductCard component',
59+
description:
60+
'This is a demo product to showcase the ProductCard component',
4861
image: 'https://via.placeholder.com/300',
4962
rating: 4.5,
5063
}}
@@ -62,14 +75,14 @@ export default function DemoPage() {
6275
</section>
6376

6477
<section className="mb-8">
65-
<h2 className="text-xl font-semibold mb-4">Interactive Components</h2>
78+
<h2 className="mb-4 text-xl font-semibold">Interactive Components</h2>
6679
<div className="space-y-4">
67-
<div className="p-4 border rounded">
68-
<h3 className="font-medium mb-2">Count Up Animation</h3>
80+
<div className="rounded border p-4">
81+
<h3 className="mb-2 font-medium">Count Up Animation</h3>
6982
<CountUp start={0} end={1000} />
7083
</div>
71-
<div className="p-4 border rounded">
72-
<h3 className="font-medium mb-2">Rendering Information</h3>
84+
<div className="rounded border p-4">
85+
<h3 className="mb-2 font-medium">Rendering Information</h3>
7386
<RenderingInfo />
7487
</div>
7588
</div>

apps/next-app-router-4001/next.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ const nextConfig = {
2222
exposes: {
2323
// Core UI Components
2424
'./Button': './ui/button',
25-
// './Header': './ui/header',
26-
// './Footer': './ui/footer',
27-
// './GlobalNav': './ui/global-nav',
25+
// './Header': isServer ? './ui/header?rsc' : './ui/header?shared',
26+
'./Footer': './ui/footer',
27+
// './GlobalNav(rsc)': isServer ? './ui/global-nav?rsc' : './ui/global-nav',
28+
// './GlobalNav(ssr)': isServer ? './ui/global-nav?ssr' : './ui/global-nav',
29+
'./GlobalNav': './ui/global-nav',
2830
//
2931
// // Product Related Components
3032
// './ProductCard': './ui/product-card',

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@ class ConsumeSharedPlugin {
334334
return createConsumeSharedModule(context, request, match);
335335
}
336336
for (const [prefix, options] of prefixedConsumes) {
337-
if (request.startsWith(prefix)) {
338-
const remainder = request.slice(prefix.length);
337+
const lookup = options.request || prefix;
338+
if (request.startsWith(lookup)) {
339+
const remainder = request.slice(lookup.length);
339340
return createConsumeSharedModule(context, request, {
340341
...options,
341342
import: options.import

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ class ProvideSharedPlugin {
229229
}
230230
}
231231
for (const [prefix, config] of prefixMatchProvides) {
232-
if (request.startsWith(prefix) && resource) {
233-
const remainder = request.slice(prefix.length);
232+
const lookup = config.request || prefix;
233+
if (request.startsWith(lookup) && resource) {
234+
const remainder = request.slice(lookup.length);
235+
debugger;
234236
provideSharedModule(
235237
resource,
236238
{

0 commit comments

Comments
 (0)