File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,22 @@ component singleton {
92
92
93
93
// Return assets from components
94
94
if ( local .httpRequestState .assets .count () ) {
95
- local .componentsResult [ " assets" ] = local .httpRequestState .assets ;
95
+ var alreadyLoadedAssets = payload .components .reduce ( function ( _agg , _comp ) {
96
+ if ( _comp .snapshot .memo .keyExists ( " assets" ) ) {
97
+ _comp .snapshot .memo .assets .each ( function ( _asset ) {
98
+ _agg .append ( _asset );
99
+ } );
100
+ }
101
+ return _agg ;
102
+ }, [] );
103
+
104
+ local .componentsResult [ " assets" ] = local .httpRequestState .assets .filter ( function ( key , value ) {
105
+ return ! arrayFindNoCase ( alreadyLoadedAssets , key );
106
+ } );
107
+
108
+ if ( ! local .componentsResult [ " assets" ].count () ) {
109
+ local .componentsResult [ " assets" ] = [];
110
+ }
96
111
}
97
112
98
113
// Set the response headers to prevent caching
Original file line number Diff line number Diff line change @@ -1135,8 +1135,8 @@ component output="true" {
1135
1135
} ).each ( function ( key , value , result ) {
1136
1136
// Extract the counter from the tag name
1137
1137
local .counter = key .replaceNoCase ( " assets" , " " );
1138
- // Create assets tag id based on compile time id and counter
1139
- local .assetsTagId = variables . _compileTimeKey & " - " & local . counter ;
1138
+ // Create assets tag id based on hash of assets
1139
+ local .assetsTagId = hash ( value ) ;
1140
1140
// Track the assets tag
1141
1141
variables ._assets [ local .assetsTagId ] = value ;
1142
1142
local .requestAssets = variables ._CBWIREController .getRequestAssets ();
Original file line number Diff line number Diff line change @@ -497,11 +497,29 @@ component extends="coldbox.system.testing.BaseTestCase" {
497
497
updates = {}
498
498
);
499
499
var result = cbwireController .handleRequest ( payload , event );
500
+ expect ( isStruct ( result .assets ) );
500
501
expect ( result .assets .count () ).toBe ( 1 );
501
502
var keys = result .assets .keyArray ();
502
503
expect ( result .assets [ key s .first () ] ).toInclude ( " tailwind.min.css" );
503
504
} );
504
505
506
+ it ( " it should NOT return assets if they were already rendered" , function () {
507
+ var payload = incomingRequest (
508
+ memo = {
509
+ " name" : " test.should_track_cbwire_assets_in_http_response" ,
510
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
511
+ " children" : [],
512
+ " assets" : [ " FC8550AF548BA7D81CAA8C2333141FDA" ]
513
+ },
514
+ data = {},
515
+ calls = [],
516
+ updates = {}
517
+ );
518
+ var result = cbwireController .handleRequest ( payload , event );
519
+ expect ( isArray ( result .assets ) ).toBeTrue ();
520
+ expect ( result .assets .len () ).toBe ( 0 );
521
+ } );
522
+
505
523
it ( " should support $refresh action" , function () {
506
524
var payload = incomingRequest (
507
525
memo = {
Original file line number Diff line number Diff line change 12
12
13
13
<cbwire:assets >
14
14
<
link rel =
" stylesheet" href =
" https://cdn.jsdelivr.net/npm/[email protected] /dist/tailwind.min.css" >
15
- </cbwire:script >
15
+ </cbwire:assets >
You can’t perform that action at this time.
0 commit comments