@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
22
33import type { Application } from '../models/application' ;
44import { appConfigs } from '../presets' ;
5+ import { linkPackage } from '../presets/utils' ;
56
67type RenderingModeTestCase = {
78 name : string ;
@@ -23,6 +24,69 @@ function getIndicator(buildOutput: string, type: 'Static' | 'Dynamic') {
2324 . split ( ' ' ) [ 0 ] ;
2425}
2526
27+ test . describe ( 'next build - bundled UI with react-server condition @nextjs' , ( ) => {
28+ test . describe . configure ( { mode : 'parallel' } ) ;
29+ let app : Application ;
30+
31+ test . beforeAll ( async ( ) => {
32+ test . setTimeout ( 90_000 ) ; // Wait for app to be ready
33+ app = await appConfigs . next . appRouter
34+ . clone ( )
35+ . addDependency ( '@clerk/ui' , linkPackage ( 'ui' ) )
36+ . addFile (
37+ 'src/app/layout.tsx' ,
38+ ( ) => `import './globals.css';
39+ import { Inter } from 'next/font/google';
40+ import { ClerkProvider } from '@clerk/nextjs';
41+ import { ui } from '@clerk/ui';
42+
43+ const inter = Inter({ subsets: ['latin'] });
44+
45+ export const metadata = {
46+ title: 'Create Next App',
47+ description: 'Generated by create next app',
48+ };
49+
50+ export default function RootLayout({ children }: { children: React.ReactNode }) {
51+ return (
52+ <ClerkProvider ui={ui}>
53+ <html lang='en'>
54+ <body className={inter.className}>{children}</body>
55+ </html>
56+ </ClerkProvider>
57+ );
58+ }
59+ ` ,
60+ )
61+ . commit ( ) ;
62+ await app . setup ( ) ;
63+ await app . withEnv ( appConfigs . envs . withEmailCodes ) ;
64+ await app . build ( ) ;
65+ } ) ;
66+
67+ test . afterAll ( async ( ) => {
68+ await app . teardown ( ) ;
69+ } ) ;
70+
71+ test ( 'When ui prop is used in server component layout, builds successfully' , ( ) => {
72+ // The layout.tsx imports { ui } from "@clerk/ui" and passes ui={ui} to ClerkProvider
73+ // This tests the react-server conditional export which provides a server-safe marker
74+ // The build should succeed without errors about client-only modules in server components
75+ expect ( app . buildOutput ) . not . toMatch ( / e r r o r / i) ;
76+ expect ( app . buildOutput ) . toContain ( 'Generating static pages' ) ;
77+ } ) ;
78+
79+ test ( 'Static pages remain static with bundled UI' , ( ) => {
80+ // Get the static indicator from the build output
81+ const staticIndicator = getIndicator ( app . buildOutput , 'Static' ) ;
82+
83+ // /_not-found should still be static even with bundled UI
84+ const notFoundPageLine = app . buildOutput . split ( '\n' ) . find ( msg => msg . includes ( '/_not-found' ) ) ;
85+
86+ expect ( notFoundPageLine ) . toContain ( staticIndicator ) ;
87+ } ) ;
88+ } ) ;
89+
2690test . describe ( 'next build - provider as client component @nextjs' , ( ) => {
2791 test . describe . configure ( { mode : 'parallel' } ) ;
2892 let app : Application ;
0 commit comments