This is an automated email from the ASF dual-hosted git repository.

Harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0f11b456fd Only load SVGs once.
0f11b456fd is described below

commit 0f11b456fdf2e60f81aadcbb90950eaf72269554
Author: Harbs <[email protected]>
AuthorDate: Wed May 27 12:19:56 2026 +0300

    Only load SVGs once.
---
 .../main/royale/org/apache/royale/style/Icon.as    | 46 ++++++++++++++++++----
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/Icon.as 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/Icon.as
index b5568c0ffd..5d6f79bc0c 100644
--- a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/Icon.as
+++ b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/Icon.as
@@ -67,6 +67,7 @@ package org.apache.royale.style
                {
                        _iconPath = value;
                }
+               COMPILE::JS
                override public function addedToParent():void
                {
                        super.addedToParent();
@@ -91,19 +92,48 @@ package org.apache.royale.style
                                }
                        }
                }
+               // keep a map of paths and requests
+               COMPILE::JS
+               private static var _requests:Map = new Map();
+               COMPILE::JS
                private function loadMarkup():void
                {
                        assert(iconPath, "Icon path must be provided");
-                       // TODO don't make the same request twice.
-                       new 
HttpRequestTask(iconPath).exec(function(task:HttpRequestTask):void
-                               {
-                                       if (task.completed)
+                       // don't make the same request twice.
+                       var existingRequest:HttpRequestTask = 
_requests.get(iconPath);
+                       if (existingRequest){
+                               existingRequest.done(
+                                       function(task:HttpRequestTask):void
                                        {
-                                               parseMarkup(new 
XML(task.resultString));
-                                               // register the loaded markup 
for future use
+                                               var markup:XML = 
_registeredIcons.get (iconPath);
+                                               if (markup)
+                                                       return 
parseMarkup(markup);
+                                               // This shouldn't happen 
because done on the main request should have already registered the markup,
+                                               // but just in case...
+                                               parseTask(task);
                                        }
-                                       // TODO do we want some kind of error 
handling here?
-                               });
+                               );
+                               return;
+                       }
+                       var request:HttpRequestTask = new 
HttpRequestTask(iconPath);
+                       _requests.set(iconPath, request);
+                       request.exec(
+                               function(task:HttpRequestTask):void
+                               {
+                                       parseTask(task);
+                                       _requests.delete(iconPath);
+                               }
+                       );
+               }
+               private function parseTask(task:HttpRequestTask):void
+               {
+                       if (task.completed)
+                       {
+                               var markup:XML = new XML(task.resultString);
+                               parseMarkup(markup);
+                               registerIcon(iconPath, markup);
+                       }
+                       // TODO do we want some kind of error handling here?
                }
                COMPILE::JS
                private var _iconElement:SVGElement;

Reply via email to