@@ -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,24 @@ 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
+ output . type . $$typeof ;
661
+ let rendered = output . type ( ) ;
662
+ let link = rendered . props . children [ 0 ] ;
676
663
assert . equal ( link . type , 'link' ) ;
677
664
assert . equal ( link . props . rel , 'stylesheet' ) ;
678
665
assert . equal ( link . props . precedence , 'default' ) ;
@@ -687,14 +674,17 @@ describe('react server components', function () {
687
674
688
675
it ( 'should generate an inline script for bootstrap with "use client-entry"' , async function ( ) {
689
676
await fsFixture ( overlayFS , dir ) `
677
+ index.jsx:
678
+ import {Server} from './Page';
679
+ output = {Server};
680
+
690
681
Page.jsx:
682
+ "use server-entry";
691
683
import {Client} from './Client';
692
- import {Resources} from '@parcel/runtime-rsc';
693
684
import './client-entry.jsx';
694
685
export function Server() {
695
- return <><Resources />< Client />< />;
686
+ return <Client />;
696
687
}
697
- output = {Resources};
698
688
699
689
client-entry.jsx:
700
690
"use client-entry";
@@ -707,7 +697,7 @@ describe('react server components', function () {
707
697
}
708
698
` ;
709
699
710
- let b = await bundle ( path . join ( dir , '/Page .jsx' ) , {
700
+ let b = await bundle ( path . join ( dir , '/index .jsx' ) , {
711
701
inputFS : overlayFS ,
712
702
targets : [ 'default' ] ,
713
703
defaultTargetOptions : {
@@ -719,7 +709,10 @@ describe('react server components', function () {
719
709
b ,
720
710
[
721
711
{
722
- assets : [ 'Page.jsx' , 'resources.js' ] ,
712
+ assets : [ 'index.jsx' ] ,
713
+ } ,
714
+ {
715
+ assets : [ 'Page.jsx' ] ,
723
716
} ,
724
717
{
725
718
assets : [ 'client-entry.jsx' , 'Client.jsx' ] ,
@@ -729,12 +722,11 @@ describe('react server components', function () {
729
722
) ;
730
723
731
724
let res = await run ( b , null , { require : false } ) ;
732
- let resources = res . output . Resources ( ) ;
733
725
let parcelRequireName = nullthrows (
734
726
Object . keys ( res ) . find ( k => / ^ p a r c e l R e q u i r e ( .+ ) $ / . test ( k ) ) ,
735
727
) ;
736
728
let clientEntry ;
737
- b . getBundles ( ) [ 1 ] . traverseAssets ( a => {
729
+ b . getBundles ( ) [ 2 ] . traverseAssets ( a => {
738
730
if (
739
731
Array . isArray ( a . meta . directives ) &&
740
732
a . meta . directives . includes ( 'use client-entry' )
@@ -743,41 +735,35 @@ describe('react server components', function () {
743
735
}
744
736
} ) ;
745
737
746
- let script = resources . props . children ;
747
- assert . equal ( script . type , 'script' ) ;
748
- assert . equal ( script . props . type , 'module' ) ;
749
738
assert . equal (
750
- script . props . children ,
751
- `import "/${ path . basename (
752
- b . getBundles ( ) [ 1 ] . filePath ,
753
- ) } "; ${ parcelRequireName } ("${ b . getAssetPublicId (
739
+ res . output . Server . bootstrapScript ,
740
+ `Promise.all([ import( "/${ path . basename (
741
+ b . getBundles ( ) [ 2 ] . filePath ,
742
+ ) } ")]).then(()=> ${ parcelRequireName } ("${ b . getAssetPublicId (
754
743
nullthrows ( clientEntry ) ,
755
- ) } ")`,
744
+ ) } ")) `,
756
745
) ;
757
746
} ) ;
758
747
759
- it ( 'dynamic import works with client components ' , async function ( ) {
748
+ it ( 'dynamic import of server component to client component ' , async function ( ) {
760
749
await fsFixture ( overlayFS , dir ) `
761
750
Page.jsx:
762
- import {Resources} from '@parcel/runtime-rsc/resources';
763
751
import './server.css';
764
752
export async function Server() {
765
753
let {Client} = await import('./Client');
766
- return [<Resources />, < Client />] ;
754
+ return < Client />;
767
755
}
768
- output = {Server, Resources };
756
+ output = {Server};
769
757
770
758
server.css:
771
759
.server { color: red }
772
760
773
761
Client.jsx:
774
762
"use client";
775
- import {Resources} from '@parcel/runtime-rsc/resources';
776
763
import './client.css';
777
764
export function Client() {
778
- return <p><Resources /> Client</p>;
765
+ return <p>Client</p>;
779
766
}
780
- output = {Resources};
781
767
782
768
client.css:
783
769
.client { color: green }
@@ -795,10 +781,10 @@ describe('react server components', function () {
795
781
b ,
796
782
[
797
783
{
798
- assets : [ 'Page.jsx' , 'resources.js' ] ,
784
+ assets : [ 'Page.jsx' ] ,
799
785
} ,
800
786
{
801
- assets : [ 'Client.jsx' , 'resources.js' ] ,
787
+ assets : [ 'Client.jsx' ] ,
802
788
} ,
803
789
{
804
790
assets : [ 'server.css' ] ,
@@ -811,19 +797,20 @@ describe('react server components', function () {
811
797
) ;
812
798
813
799
let res = ( await run ( b , null , { require : false } ) ) . output ;
814
- let result = await res . Server ( ) ;
800
+ let output = await res . Server ( ) ;
801
+ output . type . $$typeof ;
802
+ let result = output . type ( ) ;
815
803
assert . equal (
816
- result [ 1 ] . type . $$typeof ,
804
+ result . props . children [ 1 ] . type . $$typeof ,
817
805
Symbol . for ( 'react.client.reference' ) ,
818
806
) ;
819
- assert . equal ( result [ 1 ] . type . $$name , 'Client' ) ;
820
- assert . equal ( typeof result [ 1 ] . type . $$id , 'string' ) ;
821
- assert . deepEqual ( result [ 1 ] . type . $$bundles , [
807
+ assert . equal ( result . props . children [ 1 ] . type . $$name , 'Client' ) ;
808
+ assert . equal ( typeof result . props . children [ 1 ] . type . $$id , 'string' ) ;
809
+ assert . deepEqual ( result . props . children [ 1 ] . type . $$bundles , [
822
810
path . basename ( b . getBundles ( ) [ 1 ] . filePath ) ,
823
811
] ) ;
824
812
825
- let resources = res . Resources ( ) ;
826
- let link = resources . props . children ;
813
+ let link = result . props . children [ 0 ] ;
827
814
assert . equal ( link . type , 'link' ) ;
828
815
assert . equal ( link . props . rel , 'stylesheet' ) ;
829
816
assert . equal ( link . props . precedence , 'default' ) ;
@@ -834,31 +821,61 @@ describe('react server components', function () {
834
821
nullthrows (
835
822
b
836
823
. getBundles ( )
837
- . find ( b => b . type === 'css' && b . name . startsWith ( 'Page ' ) ) ,
824
+ . find ( b => b . type === 'css' && b . name . startsWith ( 'Client ' ) ) ,
838
825
) . filePath ,
839
826
) ,
840
827
) ;
828
+ } ) ;
841
829
842
- let entryAsset ;
843
- b . getBundles ( ) [ 1 ] . traverseAssets ( a => {
844
- if ( a . filePath . endsWith ( 'Client.jsx' ) ) {
845
- entryAsset = a ;
830
+ it ( 'dynamic import of server component to server component' , async function ( ) {
831
+ await fsFixture ( overlayFS , dir ) `
832
+ Page.jsx:
833
+ export async function Server() {
834
+ let {Dynamic} = await import('./Dynamic');
835
+ return <Dynamic />;
836
+ }
837
+ output = {Server};
838
+
839
+ Dynamic.jsx:
840
+ import './dynamic.css';
841
+ export function Dynamic() {
842
+ return <p>Dynamic</p>;
846
843
}
844
+
845
+ dynamic.css:
846
+ .dynamic { color: green }
847
+ ` ;
848
+
849
+ let b = await bundle ( path . join ( dir , '/Page.jsx' ) , {
850
+ inputFS : overlayFS ,
851
+ targets : [ 'default' ] ,
852
+ defaultTargetOptions : {
853
+ shouldScopeHoist,
854
+ } ,
847
855
} ) ;
848
856
849
- let client = ( await runBundle (
857
+ assertBundles (
850
858
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' ) ) ,
859
+ [
860
+ {
861
+ assets : [ 'Page.jsx' ] ,
862
+ } ,
863
+ {
864
+ assets : [ 'Dynamic.jsx' ] ,
865
+ } ,
866
+ {
867
+ assets : [ 'dynamic.css' ] ,
868
+ } ,
869
+ ] ,
870
+ { skipNodeModules : true } ,
857
871
) ;
858
- client [ parcelRequire ] ( b . getAssetPublicId ( nullthrows ( entryAsset ) ) ) ;
859
- resources = client . output . Resources ( ) ;
860
872
861
- link = resources . props . children ;
873
+ let res = ( await run ( b , null , { require : false } ) ) . output ;
874
+ let output = await res . Server ( ) ;
875
+ output . type . $$typeof ;
876
+ let result = output . type ( ) ;
877
+
878
+ let link = result . props . children [ 0 ] ;
862
879
assert . equal ( link . type , 'link' ) ;
863
880
assert . equal ( link . props . rel , 'stylesheet' ) ;
864
881
assert . equal ( link . props . precedence , 'default' ) ;
@@ -869,7 +886,9 @@ describe('react server components', function () {
869
886
nullthrows (
870
887
b
871
888
. getBundles ( )
872
- . find ( b => b . type === 'css' && b . name . startsWith ( 'Client' ) ) ,
889
+ . find (
890
+ b => b . type === 'css' && b . name . startsWith ( 'Dynamic' ) ,
891
+ ) ,
873
892
) . filePath ,
874
893
) ,
875
894
) ;
0 commit comments