Skip to content

App router share filter #3745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 139 commits into
base: share-filter
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
5b107fa
feat(enhanced): support layers
ScriptedAlchemy Nov 17, 2024
062706f
feat(enhanced): support layers
ScriptedAlchemy Nov 17, 2024
cfd9d01
feat(enhanced): layers for consume shared module
ScriptedAlchemy Nov 21, 2024
3e59c55
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 21, 2024
536b110
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 21, 2024
aed08e9
feat(enhanced): add issuerLayer support to consume shared
ScriptedAlchemy Nov 22, 2024
9fb164b
chore(enhanced): update test
ScriptedAlchemy Nov 25, 2024
a9d899c
chore(enhanced): update test
ScriptedAlchemy Nov 25, 2024
33a36d1
feat(enhanced): ConsumeSharedPlugin issuerLayer support
ScriptedAlchemy Nov 25, 2024
f0c5c50
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
578adbb
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
31f08d0
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
066ffa6
feat(enhanced): support direct layer
ScriptedAlchemy Nov 25, 2024
b70eb8d
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 25, 2024
358ba00
fix(enhanced): update share options of share plugin
ScriptedAlchemy Nov 25, 2024
94d72ed
fix(enhanced): update share options of share plugin
ScriptedAlchemy Nov 25, 2024
91dbb12
chore(enhanced): refactor layers tests
ScriptedAlchemy Nov 25, 2024
514cf03
chore(enhanced): remove layer options from provider
ScriptedAlchemy Nov 25, 2024
359b0ca
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Nov 25, 2024
24ef6d0
Delete .cursorrules
ScriptedAlchemy Nov 25, 2024
9d9bff2
feat(enhanced): support layers in consume share
ScriptedAlchemy Nov 26, 2024
40ae817
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Nov 26, 2024
d1c68b3
fix(enhanced): rename requiredLayer to layer
ScriptedAlchemy Dec 2, 2024
22964f8
Merge remote-tracking branch 'origin/consume-share-layers' into consu…
ScriptedAlchemy Dec 2, 2024
9884030
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 2, 2024
3d8fa21
refactor(enhanced): pr review of consume share layering
ScriptedAlchemy Dec 3, 2024
69a2a52
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 3, 2024
04b8ffd
chore: locks
ScriptedAlchemy Dec 3, 2024
7852878
feat(enhanced): add request to consume share (#3307)
ScriptedAlchemy Dec 5, 2024
f35b1b1
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 5, 2024
b8df73e
chore: remove tt
ScriptedAlchemy Dec 9, 2024
b4b5a7b
chore: remove unused share
ScriptedAlchemy Dec 9, 2024
6f8f45e
refactor(enhanced): refactor type locations
ScriptedAlchemy Dec 10, 2024
875f516
feat(enhanced): ProvideSharedPlugin loader layer support (#3334)
ScriptedAlchemy Dec 12, 2024
673f6ca
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 12, 2024
20bae5b
chore: locks
ScriptedAlchemy Dec 12, 2024
a5774c8
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
d44acbd
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
1a33ac7
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
1fc2b05
thing
ScriptedAlchemy Dec 13, 2024
29f6d73
thing
ScriptedAlchemy Dec 13, 2024
22127ee
chore(node): lint
ScriptedAlchemy Dec 13, 2024
8f9fb99
chore(node): lint
ScriptedAlchemy Dec 13, 2024
243f1bc
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 13, 2024
0c665be
feat(enhanced): layers support in module code generation (#3371)
ScriptedAlchemy Dec 29, 2024
ffdaf0b
chore: changeset
ScriptedAlchemy Dec 31, 2024
687365f
feat(enhanced): Layer via composite shareKey (#3415)
ScriptedAlchemy Dec 31, 2024
4ef6efb
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 31, 2024
81d2365
chore: locks
ScriptedAlchemy Dec 31, 2024
6f952fd
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Jan 1, 2025
5fce760
chore: locks
ScriptedAlchemy Jan 1, 2025
1fba24f
fix(enhanced): cache consume module layer
ScriptedAlchemy Jan 2, 2025
7af571f
fix(nextjs-mf): enable app router shares and disable hard fail
ScriptedAlchemy Jan 2, 2025
7a178c0
chore: add host remote app router
ScriptedAlchemy Jan 2, 2025
10f2b73
feat(nextjs-mf): update module share for rsc
ScriptedAlchemy Jan 3, 2025
e122bf4
feat(nextjs-mf): update module share for rsc
ScriptedAlchemy Jan 21, 2025
c3729a7
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 18, 2025
e6a109d
chore: fix schema validation eror
ScriptedAlchemy Feb 18, 2025
ee0726d
chore: fix schema validation errors
ScriptedAlchemy Feb 18, 2025
2fc6497
fix(enhanced): schema validation
ScriptedAlchemy Feb 18, 2025
baaeb27
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 19, 2025
55abb84
chore: locks
ScriptedAlchemy Feb 19, 2025
cfca731
chore: update schema
ScriptedAlchemy Feb 19, 2025
6e6ef06
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 25, 2025
41e1a84
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 12, 2025
aef1bb2
chore: locks
ScriptedAlchemy Mar 12, 2025
fb936d3
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
0ff2e2c
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
42bf94c
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
2c52030
feat(enhanced): implement multiple share scope support (#3524)
ScriptedAlchemy Mar 14, 2025
83261cc
chore: add next with app router
ScriptedAlchemy Mar 14, 2025
fc201b9
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
a3899fc
chore: add next with app router
ScriptedAlchemy Mar 14, 2025
25277fc
chore: update deps
ScriptedAlchemy Mar 14, 2025
b23bb46
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
f0b2404
chore: update deps
ScriptedAlchemy Mar 14, 2025
01b6767
chore: update deps
ScriptedAlchemy Mar 14, 2025
cc658b9
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
6835348
chore: update deps
ScriptedAlchemy Mar 14, 2025
a8b5055
fix: add next apps to workspace
ScriptedAlchemy Mar 14, 2025
4431551
feat(nextjs-mf): app router support
ScriptedAlchemy Mar 15, 2025
dc6d0c0
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 15, 2025
3fe3803
feat(nextjs-mf): app router support
ScriptedAlchemy Mar 16, 2025
d25ff57
Merge branch 'consume-share-layers' into app-router-support
ScriptedAlchemy Mar 18, 2025
df4a103
Merge branch 'main' into app-router-support
ScriptedAlchemy Apr 21, 2025
133a858
Merge branch 'refs/heads/main' into app-router-support
ScriptedAlchemy Apr 23, 2025
2e2b7cb
fix(nextjs-mf): layered module sharing in next
ScriptedAlchemy Apr 23, 2025
6afefd8
refactor: remove duplicate share groups from internal.ts
ScriptedAlchemy Apr 29, 2025
17e2d05
Merge branch 'main' into app-router-support
ScriptedAlchemy Apr 29, 2025
5b1163d
Merge branch 'share-filter' into app-router-share-filter
ScriptedAlchemy Apr 29, 2025
2430f8d
feat(enhanced): extend schemas with filter version and fallbackVersion
ScriptedAlchemy May 1, 2025
c92250e
feat(enhanced): implement filter logic for module sharing based on ve…
ScriptedAlchemy May 1, 2025
4f2d3f7
feat(enhanced): add tests for module exclusion based on sharing criteria
ScriptedAlchemy May 1, 2025
440e010
chore: ide stuff
ScriptedAlchemy May 1, 2025
7f3fcf2
chore: ide stuff
ScriptedAlchemy May 2, 2025
ea050b0
feat(enhanced): rename filter to exclude in sharing plugins and schem…
ScriptedAlchemy May 2, 2025
142b31f
feat(enhanced): add comprehensive tests for container and sharing plu…
ScriptedAlchemy May 2, 2025
2fcee50
feat(enhanced): refactor and enhance tests for sharing plugins with v…
ScriptedAlchemy May 2, 2025
f0771f7
chore: ignores
ScriptedAlchemy May 2, 2025
31346a4
chore: ignores
ScriptedAlchemy May 2, 2025
d0b262d
chore: lock
ScriptedAlchemy May 2, 2025
33168e6
chore: format
ScriptedAlchemy May 2, 2025
7b7c3d2
chore: format
ScriptedAlchemy May 2, 2025
e847aea
Merge branch 'share-filter-version' into app-router-share-filter
ScriptedAlchemy May 2, 2025
58ee2f0
Merge branch 'main' into app-router-share-filter
ScriptedAlchemy May 2, 2025
2038891
feat(nextjs-mf): x-app module sharing
ScriptedAlchemy May 6, 2025
a1c8aa2
chore: module shareing
ScriptedAlchemy May 8, 2025
455c3e1
chore: module shareing
ScriptedAlchemy May 11, 2025
f7a167d
Merge branch 'share-filter' into app-router-share-filter
ScriptedAlchemy May 14, 2025
e465941
chore: stage tests
ScriptedAlchemy May 14, 2025
e4b6414
chore: stage tests
ScriptedAlchemy May 14, 2025
4fa0830
Merge branch 'share-filter' into app-router-share-filter
ScriptedAlchemy May 16, 2025
73b1714
chore: locks
ScriptedAlchemy May 16, 2025
1eaaf92
chore: clean up package dependencies in 3000-home and update pnpm-loc…
ScriptedAlchemy May 16, 2025
92ef128
chore: format
ScriptedAlchemy May 16, 2025
ba1fccb
chore: update package dependencies and configurations for next-app-ro…
ScriptedAlchemy May 18, 2025
e63e9c4
feat(enhanced): add nodeModulesReconstructedLookup option to share it…
ScriptedAlchemy May 20, 2025
64cfbbd
docs: update advanced-sharing and experiments documentation for nodeM…
ScriptedAlchemy May 20, 2025
c68d2a2
fix: remove warning on exclude / include based on request
ScriptedAlchemy May 21, 2025
c5a097b
refactor: remove singleton filter warning logic from ProvideSharedPlu…
ScriptedAlchemy May 21, 2025
9d5c5f9
feat: update server module sharing
ScriptedAlchemy May 21, 2025
b619097
feat: update server module sharing
ScriptedAlchemy May 21, 2025
075bf8c
chore: add rsc directories for loader to handle
ScriptedAlchemy May 21, 2025
4483b3c
Merge branch 'main' into app-router-share-filter
ScriptedAlchemy May 30, 2025
c2ca9cf
chore: locks
ScriptedAlchemy May 30, 2025
0222c68
Merge branch 'share-filter' into app-router-share-filter
ScriptedAlchemy May 30, 2025
0133d01
chore: locks
ScriptedAlchemy May 30, 2025
f7caf3b
App Router: RSC Flight plugins (#3807)
ScriptedAlchemy May 30, 2025
df1b040
feat(nextjs-mf): add router shares and clean up unused functions
ScriptedAlchemy Jun 16, 2025
5cb153e
chore: no cache on release build
ScriptedAlchemy Jun 16, 2025
aee95ee
Update ai-hungry-bear.md
ScriptedAlchemy Jun 16, 2025
9971eb3
Update ai-sleepy-tiger.md
ScriptedAlchemy Jun 16, 2025
314c475
feat(nextjs-mf): add unlayered React configurations defaulting to pag…
ScriptedAlchemy Jun 16, 2025
ba9ee60
fix: use only issuerLayer for creating unresovledConsumes
ScriptedAlchemy Jun 16, 2025
55b955f
feat(core): add browser cache and nx SHA setup to release workflow
ScriptedAlchemy Jun 16, 2025
13f875e
fix: use only issuerLayer for creating unresovledConsumes
ScriptedAlchemy Jun 16, 2025
71aa021
feat(nextjs-mf): change pages directory shareScope from layer-specifi…
ScriptedAlchemy Jun 16, 2025
7931162
fix: use only issuerLayer for creating unresovledConsumes
ScriptedAlchemy Jun 17, 2025
49dde01
feat(nextjs-mf): enhance sharing configuration for Next.js components…
ScriptedAlchemy Jun 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/ai-eager-wolf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@module-federation/runtime-core": minor
---

Added support for OR ranges in semantic version satisfaction logic with comprehensive unit tests.

- Implemented parsing for OR (||) conditions in version ranges.
- Split input ranges by || to evaluate alternatives individually.
- Ensured logical handling of wildcards '*' and 'x' within ranges.
- Refactored internal parsing to support more complex range constructs.
- Added comprehensive test cases to cover diverse scenarios for OR range support.
- Introduced error handling during range processing, with console logging for tracking issues.
12 changes: 12 additions & 0 deletions .changeset/ai-happy-fox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@module-federation/nextjs-mf": minor
---

Refactor and enhance module federation support for Next.js.

- Introduced `getShareScope` function to dynamically generate the default share scope based on the client or server environment, replacing static DEFAULT_SHARE_SCOPE declarations.
- Implemented `RscManifestInterceptPlugin` to intercept and modify client reference manifests, ensuring proper prefix handling.
- Refined server-side externals handling to ensure shared federation modules are bundled.
- Simplified and modularized sharing logic by creating distinct functions for React, React DOM, React JSX Runtime, and React JSX Dev Runtime package configurations.
- Captured the original webpack public path for potential use in plugins and adjustments.
- Enhanced logging for debug tracing of shared module resolution processes in runtimePlugin.
10 changes: 10 additions & 0 deletions .changeset/ai-hungry-bear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@module-federation/enhanced": minor
---

Enhancements to layer handling in module federation tests and configuration.

- Improved handling of `shareKey` for layers within `ConsumeSharedPlugin` and `ProvideSharedPlugin`.
- Conditionally prepend the `shareKey` with the `layer` if applicable.
- Introduced new layer configurations to support more nuanced federation scenarios that consider multiple layers of dependency.

9 changes: 9 additions & 0 deletions .changeset/ai-sleepy-fox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@module-federation/enhanced": patch
---

Refactored module sharing configuration handling.

- Simplified plugin schema for better maintainability
- Improved layer-based module sharing test coverage
- Removed redundant plugin exports
5 changes: 5 additions & 0 deletions .changeset/ai-sleepy-tiger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@module-federation/runtime": minor
---

- Added a new property 'layer' of type string or null to SharedConfig.
5 changes: 5 additions & 0 deletions .changeset/brown-badgers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': minor
---

support request option on ConsumeSharePlugin. Allows matching requests like the object key of shared does
5 changes: 5 additions & 0 deletions .changeset/shy-snails-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': minor
---

Layer support for Provide Share Plugin
4 changes: 2 additions & 2 deletions .cursor/rules/nx-rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ alwaysApply: true

// This file is automatically generated by Nx Console

You are in an nx workspace using Nx 0.0.0 and npm as the package manager.
You are in an nx workspace using Nx 21.0.3 and pnpm as the package manager.

You have access to the Nx MCP server and the tools it provides. Use them. Follow these guidelines in order to best help the user:

Expand All @@ -17,7 +17,7 @@ You have access to the Nx MCP server and the tools it provides. Use them. Follow
- To help answer questions about the workspace structure or simply help with demonstrating how tasks depend on each other, use the 'nx_visualize_graph' tool

# Generation Guidelines
If the user wants to generate something, use the following flow:
If the user wants to generate something, use the following flow:

- learn about the nx workspace and any specifics the user needs by using the 'nx_workspace' tool and the 'nx_project_details' tool if applicable
- get the available generators using the 'nx_generators' tool
Expand Down
6 changes: 6 additions & 0 deletions .cursor/rules/running-tests.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description:
globs: packages/enhanced/*
alwaysApply: false
---
use pnpm enhanced:jest to test this
2 changes: 1 addition & 1 deletion .cursorignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**/.cache/
**/.temp/
**/coverage/
**/dist/
!**/dist/

# Explicitly ignore specific packages
packages/typescript/
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,25 @@ jobs:
node-version: '18'
cache: 'pnpm'

- name: Cache Browsers
uses: actions/cache@v3
id: browsers-cache
with:
path: |
~/.cache/ms-playwright
~/.cache/Cypress
key: ${{ runner.os }}-browsers-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Set Nx SHA
uses: nrwl/nx-set-shas@v3

- name: Install deps
run: pnpm install

- name: Build and test Packages
run: |
git fetch origin main
npx nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache
npx nx run-many --targets=build --projects=tag:type:pkg
ls -l packages/*/dist packages/*/package.json

- name: Release
Expand Down
2 changes: 1 addition & 1 deletion apps/3000-home/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
40 changes: 20 additions & 20 deletions apps/3000-home/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { Suspense, lazy } from 'react';
import Head from 'next/head';
import CheckoutTitle from 'checkout/CheckoutTitle';
import ButtonOldAnt from 'checkout/ButtonOldAnt';
// import CheckoutTitle from 'checkout/CheckoutTitle';
// import ButtonOldAnt from 'checkout/ButtonOldAnt';
// const CheckoutTitle = lazy(() => import('checkout/CheckoutTitle'));
// const ButtonOldAnt = lazy(() => import('checkout/ButtonOldAnt'));
const WebpackSvgRemote = lazy(() =>
import('shop/WebpackSvg').then((m) => {
return m;
}),
);
const WebpackPngRemote = lazy(() => import('shop/WebpackPng'));
// const WebpackSvgRemote = lazy(() =>
// import('shop/WebpackSvg').then((m) => {
// return m;
// }),
// );
// const WebpackPngRemote = lazy(() => import('shop/WebpackPng'));

const Home = () => {
return (
Expand Down Expand Up @@ -83,9 +83,9 @@ const Home = () => {
<h3>This title came from checkout with hooks data!!!</h3>
</td>
<td>
<Suspense fallback="loading CheckoutTitle">
<CheckoutTitle />
</Suspense>
{/*<Suspense fallback="loading CheckoutTitle">*/}
{/* <CheckoutTitle />*/}
{/*</Suspense>*/}
</td>
</tr>
<tr>
Expand All @@ -95,9 +95,9 @@ const Home = () => {
</td>
<td>[Button from [email protected]]</td>
<td>
<Suspense fallback="loading ButtonOldAnt">
<ButtonOldAnt />
</Suspense>
{/*<Suspense fallback="loading ButtonOldAnt">*/}
{/* <ButtonOldAnt />*/}
{/*</Suspense>*/}
</td>
</tr>
<tr>
Expand All @@ -111,9 +111,9 @@ const Home = () => {
<img className="home-webpack-png" src="./webpack.png" />
</td>
<td>
<Suspense fallback="loading WebpackPngRemote">
<WebpackPngRemote />
</Suspense>
{/*<Suspense fallback="loading WebpackPngRemote">*/}
{/* <WebpackPngRemote />*/}
{/*</Suspense>*/}
</td>
</tr>
<tr>
Expand All @@ -127,9 +127,9 @@ const Home = () => {
<img src="./webpack.svg" />
</td>
<td>
<Suspense fallback="loading WebpackSvgRemote">
<WebpackSvgRemote />
</Suspense>
{/*<Suspense fallback="loading WebpackSvgRemote">*/}
{/* <WebpackSvgRemote />*/}
{/*</Suspense>*/}
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion apps/3001-shop/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
2 changes: 1 addition & 1 deletion apps/3002-checkout/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
83 changes: 59 additions & 24 deletions apps/next-app-router/next-app-router-4000/app/hooks/page.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
'use client';
import Link from 'next/link';
import Image from 'next/image';
import Head from 'next/head';
import Script from 'next/script';
import {
useRouter,
usePathname,
useSearchParams,
useParams,
useSelectedLayoutSegments,
useSelectedLayoutSegment,
} from 'next/navigation';
import { ExternalLink } from '#/ui/external-link';

export default function Page() {
return (
<div className="space-y-9">
<div className="prose prose-sm prose-invert max-w-none">
<h1 className="text-xl font-bold">Client Component Hooks</h1>

<ul>
<li>
Next.js provides a number of hooks for accessing routing information
from client components.
</li>
<li>
Try navigating each page and observing the output of each hook
called from the current routes <code>layout.js</code> and{' '}
<code>page.js</code> files.
</li>
</ul>
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const params = useParams();
const segments = useSelectedLayoutSegments();
const segment = useSelectedLayoutSegment();

<div className="flex gap-2">
<ExternalLink href="https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#revalidating-data">
Docs
</ExternalLink>
<ExternalLink href="https://github.com/vercel/app-playground/tree/main/app/hooks">
Code
</ExternalLink>
return (
<>
<Head>
<title>Client Component Hooks Demo</title>
</Head>
<Script src="https://example.com/script.js" strategy="lazyOnload" />
<div className="space-y-9">
<div className="prose prose-sm prose-invert max-w-none">
<h1 className="text-xl font-bold">Client Component Hooks</h1>
<ul>
<li>
Current pathname: <code>{pathname}</code>
</li>
<li>
Current params: <code>{JSON.stringify(params)}</code>
</li>
<li>
Current search params:{' '}
<code>{searchParams?.toString() ?? ''}</code>
</li>
<li>
Current segments: <code>{segments?.join(', ') ?? ''}</code>
</li>
<li>
Current segment: <code>{segment}</code>
</li>
</ul>
<div className="flex gap-2">
<ExternalLink href="https://nextjs.org/docs/app/api-reference/functions">
Next.js App Router Hooks Docs
</ExternalLink>
</div>
<button onClick={() => router.push('/')}>Go Home</button>
<div className="mt-4">
<Link href="/about">Go to About (with next/link)</Link>
</div>
<div className="mt-4">
<Image src="/logo.png" alt="Logo" width={100} height={100} />
</div>
</div>
</div>
</div>
</>
);
}
1 change: 0 additions & 1 deletion apps/next-app-router/next-app-router-4000/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default function RootLayout({
<html lang="en" className="[color-scheme:dark]">
<body className="overflow-y-scroll bg-gray-1100 bg-[url('/grid.svg')] pb-36">
{/*<GlobalNav />*/}

<div className="lg:pl-72">
<div className="mx-auto max-w-4xl space-y-8 px-2 pt-20 lg:px-8 lg:py-8">
<div className="rounded-lg bg-vc-border-gradient p-px shadow-lg shadow-black/20">
Expand Down
11 changes: 8 additions & 3 deletions apps/next-app-router/next-app-router-4000/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { demos } from '#/lib/demos';
import Link from 'next/link';
import { lazy } from 'react';
import dynamic from 'next/dynamic';
const Button = dynamic(() => import('remote_4001/Button'), { ssr: true });
const RemoteRSCButton = lazy(() => import('remote_4001/rsc/Button'));
const RemoteSSRButton = lazy(() => import('remote_4001/Button'));
import Button from '#/ui/button';

export default function Page() {
return (
<div className="space- y-8">
<Button>Button from remote</Button>
<div className="space-y-8">
<Button>Local RSC Button</Button>
<RemoteRSCButton>Remote Button from RSC</RemoteRSCButton>
<RemoteSSRButton>Remote Button from RSC</RemoteSSRButton>
<h1 className="text-xl font-medium text-gray-300">Examples</h1>

<div className="space-y-10 text-white">
Expand Down
3 changes: 2 additions & 1 deletion apps/next-app-router/next-app-router-4000/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Loading
Loading