@@ -31,15 +31,8 @@ describe('react server components', function () {
31
31
targets : {
32
32
default : {
33
33
context : 'react-server' ,
34
- outputFormat : 'commonjs' ,
35
34
} ,
36
35
} ,
37
- '@parcel/resolver-default' : {
38
- packageExports : true ,
39
- } ,
40
- '@parcel/bundler-default' : {
41
- minBundleSize : 0 ,
42
- } ,
43
36
} ) ,
44
37
) ;
45
38
@@ -383,7 +376,6 @@ describe('react server components', function () {
383
376
'client.jsx' ,
384
377
'react-jsx-dev-runtime.development.js' ,
385
378
'index.js' ,
386
- 'jsx-dev-runtime.js' ,
387
379
'react.development.js' ,
388
380
] ,
389
381
} ,
@@ -487,7 +479,6 @@ describe('react server components', function () {
487
479
assets : [
488
480
'client.jsx' ,
489
481
'index.js' ,
490
- 'jsx-dev-runtime.js' ,
491
482
'react-jsx-dev-runtime.development.js' ,
492
483
'react.development.js' ,
493
484
] ,
@@ -610,7 +601,6 @@ describe('react server components', function () {
610
601
// Client: shared bundle.
611
602
assets : [
612
603
'index.js' ,
613
- 'jsx-dev-runtime.js' ,
614
604
'react-jsx-dev-runtime.development.js' ,
615
605
'react.development.js' ,
616
606
] ,
@@ -620,32 +610,27 @@ describe('react server components', function () {
620
610
) ;
621
611
} ) ;
622
612
623
- it ( 'should support <Resources> ' , async function ( ) {
613
+ it ( 'should support inject CSS resources ' , async function ( ) {
624
614
await fsFixture ( overlayFS , dir ) `
615
+ index.jsx:
616
+ import {Server} from './Page.jsx';
617
+ function render() {
618
+ return <Server />;
619
+ }
620
+ output = {render};
621
+
625
622
Page.jsx:
626
- import {Client} from './Client';
627
- import {Resources} from '@parcel/runtime-rsc';
623
+ "use server-entry";
628
624
import './server.css';
629
625
export function Server() {
630
- return <><Resources /><Client /></ >;
626
+ return <h1>Server</h1 >;
631
627
}
632
- output = {Resources};
633
628
634
629
server.css:
635
630
.server { color: red }
636
-
637
- Client.jsx:
638
- "use client";
639
- import './client.css';
640
- export function Client() {
641
- return <p>Client</p>;
642
- }
643
-
644
- client.css:
645
- .client { color: green }
646
631
` ;
647
632
648
- let b = await bundle ( path . join ( dir , '/Page .jsx' ) , {
633
+ let b = await bundle ( path . join ( dir , '/index .jsx' ) , {
649
634
inputFS : overlayFS ,
650
635
targets : [ 'default' ] ,
651
636
defaultTargetOptions : {
@@ -657,22 +642,22 @@ describe('react server components', function () {
657
642
b ,
658
643
[
659
644
{
660
- assets : [ 'Page .jsx' , 'resources.js '] ,
645
+ assets : [ 'index .jsx' ] ,
661
646
} ,
662
647
{
663
- assets : [ 'Client .jsx' ] ,
648
+ assets : [ 'Page .jsx' ] ,
664
649
} ,
665
650
{
666
- assets : [ 'server.css' , 'client.css' ] ,
651
+ assets : [ 'server.css' ] ,
667
652
} ,
668
653
] ,
669
654
{ skipNodeModules : true } ,
670
655
) ;
671
656
672
- let res = ( await run ( b , null , { require : false } ) ) . output ;
673
- let resources = res . Resources ( ) ;
657
+ let res = ( await run ( b , { output : null } , { require : false } ) ) . output ;
658
+ let output = res . render ( ) ;
674
659
675
- let link = resources . props . children ;
660
+ let link = output . props . children [ 0 ] ;
676
661
assert . equal ( link . type , 'link' ) ;
677
662
assert . equal ( link . props . rel , 'stylesheet' ) ;
678
663
assert . equal ( link . props . precedence , 'default' ) ;
@@ -687,14 +672,17 @@ describe('react server components', function () {
687
672
688
673
it ( 'should generate an inline script for bootstrap with "use client-entry"' , async function ( ) {
689
674
await fsFixture ( overlayFS , dir ) `
675
+ index.jsx:
676
+ import {Server} from './Page';
677
+ output = {Server};
678
+
690
679
Page.jsx:
680
+ "use server-entry";
691
681
import {Client} from './Client';
692
- import {Resources} from '@parcel/runtime-rsc';
693
682
import './client-entry.jsx';
694
683
export function Server() {
695
- return <><Resources />< Client />< />;
684
+ return <Client />;
696
685
}
697
- output = {Resources};
698
686
699
687
client-entry.jsx:
700
688
"use client-entry";
@@ -707,7 +695,7 @@ describe('react server components', function () {
707
695
}
708
696
` ;
709
697
710
- let b = await bundle ( path . join ( dir , '/Page .jsx' ) , {
698
+ let b = await bundle ( path . join ( dir , '/index .jsx' ) , {
711
699
inputFS : overlayFS ,
712
700
targets : [ 'default' ] ,
713
701
defaultTargetOptions : {
@@ -719,7 +707,10 @@ describe('react server components', function () {
719
707
b ,
720
708
[
721
709
{
722
- assets : [ 'Page.jsx' , 'resources.js' ] ,
710
+ assets : [ 'index.jsx' ] ,
711
+ } ,
712
+ {
713
+ assets : [ 'Page.jsx' ] ,
723
714
} ,
724
715
{
725
716
assets : [ 'client-entry.jsx' , 'Client.jsx' ] ,
@@ -729,12 +720,11 @@ describe('react server components', function () {
729
720
) ;
730
721
731
722
let res = await run ( b , null , { require : false } ) ;
732
- let resources = res . output . Resources ( ) ;
733
723
let parcelRequireName = nullthrows (
734
724
Object . keys ( res ) . find ( k => / ^ p a r c e l R e q u i r e ( .+ ) $ / . test ( k ) ) ,
735
725
) ;
736
726
let clientEntry ;
737
- b . getBundles ( ) [ 1 ] . traverseAssets ( a => {
727
+ b . getBundles ( ) [ 2 ] . traverseAssets ( a => {
738
728
if (
739
729
Array . isArray ( a . meta . directives ) &&
740
730
a . meta . directives . includes ( 'use client-entry' )
@@ -743,41 +733,35 @@ describe('react server components', function () {
743
733
}
744
734
} ) ;
745
735
746
- let script = resources . props . children ;
747
- assert . equal ( script . type , 'script' ) ;
748
- assert . equal ( script . props . type , 'module' ) ;
749
736
assert . equal (
750
- script . props . children ,
751
- `import "/${ path . basename (
752
- b . getBundles ( ) [ 1 ] . filePath ,
753
- ) } "; ${ parcelRequireName } ("${ b . getAssetPublicId (
737
+ res . output . Server . bootstrapScript ,
738
+ `Promise.all([ import( "/${ path . basename (
739
+ b . getBundles ( ) [ 2 ] . filePath ,
740
+ ) } ")]).then(()=> ${ parcelRequireName } ("${ b . getAssetPublicId (
754
741
nullthrows ( clientEntry ) ,
755
- ) } ")`,
742
+ ) } ")) `,
756
743
) ;
757
744
} ) ;
758
745
759
- it ( 'dynamic import works with client components ' , async function ( ) {
746
+ it ( 'dynamic import of server component to client component ' , async function ( ) {
760
747
await fsFixture ( overlayFS , dir ) `
761
748
Page.jsx:
762
- import {Resources} from '@parcel/runtime-rsc/resources';
763
749
import './server.css';
764
750
export async function Server() {
765
751
let {Client} = await import('./Client');
766
- return [<Resources />, < Client />] ;
752
+ return < Client />;
767
753
}
768
- output = {Server, Resources };
754
+ output = {Server};
769
755
770
756
server.css:
771
757
.server { color: red }
772
758
773
759
Client.jsx:
774
760
"use client";
775
- import {Resources} from '@parcel/runtime-rsc/resources';
776
761
import './client.css';
777
762
export function Client() {
778
- return <p><Resources /> Client</p>;
763
+ return <p>Client</p>;
779
764
}
780
- output = {Resources};
781
765
782
766
client.css:
783
767
.client { color: green }
@@ -795,10 +779,10 @@ describe('react server components', function () {
795
779
b ,
796
780
[
797
781
{
798
- assets : [ 'Page.jsx' , 'resources.js' ] ,
782
+ assets : [ 'Page.jsx' ] ,
799
783
} ,
800
784
{
801
- assets : [ 'Client.jsx' , 'resources.js' ] ,
785
+ assets : [ 'Client.jsx' ] ,
802
786
} ,
803
787
{
804
788
assets : [ 'server.css' ] ,
@@ -813,17 +797,16 @@ describe('react server components', function () {
813
797
let res = ( await run ( b , null , { require : false } ) ) . output ;
814
798
let result = await res . Server ( ) ;
815
799
assert . equal (
816
- result [ 1 ] . type . $$typeof ,
800
+ result . props . children [ 1 ] . type . $$typeof ,
817
801
Symbol . for ( 'react.client.reference' ) ,
818
802
) ;
819
- assert . equal ( result [ 1 ] . type . $$name , 'Client' ) ;
820
- assert . equal ( typeof result [ 1 ] . type . $$id , 'string' ) ;
821
- assert . deepEqual ( result [ 1 ] . type . $$bundles , [
803
+ assert . equal ( result . props . children [ 1 ] . type . $$name , 'Client' ) ;
804
+ assert . equal ( typeof result . props . children [ 1 ] . type . $$id , 'string' ) ;
805
+ assert . deepEqual ( result . props . children [ 1 ] . type . $$bundles , [
822
806
path . basename ( b . getBundles ( ) [ 1 ] . filePath ) ,
823
807
] ) ;
824
808
825
- let resources = res . Resources ( ) ;
826
- let link = resources . props . children ;
809
+ let link = result . props . children [ 0 ] ;
827
810
assert . equal ( link . type , 'link' ) ;
828
811
assert . equal ( link . props . rel , 'stylesheet' ) ;
829
812
assert . equal ( link . props . precedence , 'default' ) ;
@@ -834,31 +817,59 @@ describe('react server components', function () {
834
817
nullthrows (
835
818
b
836
819
. getBundles ( )
837
- . find ( b => b . type === 'css' && b . name . startsWith ( 'Page ' ) ) ,
820
+ . find ( b => b . type === 'css' && b . name . startsWith ( 'Client ' ) ) ,
838
821
) . filePath ,
839
822
) ,
840
823
) ;
824
+ } ) ;
841
825
842
- let entryAsset ;
843
- b . getBundles ( ) [ 1 ] . traverseAssets ( a => {
844
- if ( a . filePath . endsWith ( 'Client.jsx' ) ) {
845
- entryAsset = a ;
826
+ it ( 'dynamic import of server component to server component' , async function ( ) {
827
+ await fsFixture ( overlayFS , dir ) `
828
+ Page.jsx:
829
+ export async function Server() {
830
+ let {Dynamic} = await import('./Dynamic');
831
+ return <Dynamic />;
832
+ }
833
+ output = {Server};
834
+
835
+ Dynamic.jsx:
836
+ import './dynamic.css';
837
+ export function Dynamic() {
838
+ return <p>Dynamic</p>;
846
839
}
840
+
841
+ dynamic.css:
842
+ .dynamic { color: green }
843
+ ` ;
844
+
845
+ let b = await bundle ( path . join ( dir , '/Page.jsx' ) , {
846
+ inputFS : overlayFS ,
847
+ targets : [ 'default' ] ,
848
+ defaultTargetOptions : {
849
+ shouldScopeHoist,
850
+ } ,
847
851
} ) ;
848
852
849
- let client = ( await runBundle (
853
+ assertBundles (
850
854
b ,
851
- b . getBundles ( ) [ 1 ] ,
852
- { output : null } ,
853
- { require : false , entryAsset} ,
854
- ) : any ) ;
855
- let parcelRequire = nullthrows (
856
- Object . keys ( client ) . find ( k => k . startsWith ( 'parcelRequire' ) ) ,
855
+ [
856
+ {
857
+ assets : [ 'Page.jsx' ] ,
858
+ } ,
859
+ {
860
+ assets : [ 'Dynamic.jsx' ] ,
861
+ } ,
862
+ {
863
+ assets : [ 'dynamic.css' ] ,
864
+ } ,
865
+ ] ,
866
+ { skipNodeModules : true } ,
857
867
) ;
858
- client [ parcelRequire ] ( b . getAssetPublicId ( nullthrows ( entryAsset ) ) ) ;
859
- resources = client . output . Resources ( ) ;
860
868
861
- link = resources . props . children ;
869
+ let res = ( await run ( b , null , { require : false } ) ) . output ;
870
+ let result = await res . Server ( ) ;
871
+
872
+ let link = result . props . children [ 0 ] ;
862
873
assert . equal ( link . type , 'link' ) ;
863
874
assert . equal ( link . props . rel , 'stylesheet' ) ;
864
875
assert . equal ( link . props . precedence , 'default' ) ;
@@ -869,7 +880,9 @@ describe('react server components', function () {
869
880
nullthrows (
870
881
b
871
882
. getBundles ( )
872
- . find ( b => b . type === 'css' && b . name . startsWith ( 'Client' ) ) ,
883
+ . find (
884
+ b => b . type === 'css' && b . name . startsWith ( 'Dynamic' ) ,
885
+ ) ,
873
886
) . filePath ,
874
887
) ,
875
888
) ;
0 commit comments