[ 
https://issues.apache.org/jira/browse/SHINDIG-1260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803217#action_12803217
 ] 

Jacky Wang commented on SHINDIG-1260:
-------------------------------------

Hi James, thank you for your effort on putting them together!

I've just did a quick review and here are some of the findings.  Please feel 
free to correct me.

1. the features are not constructed in the same routine:
  a) in GadgetFactory.php, the initial feature list is put together by 
combining both requiredFeatures and optionalFeatures.
  b) in GadgetBaseRenderer.php, where you modified, the forcedJsLibs are added 
and expended as well.
  c) in JsServlet.php, the features are fetched and expended again.  (this may 
introduce the multi-inclusion)

2. actually, the features are expended by 
GadgetFeatureRegistry->resolveFeatures, which calls 
GadgetFeatureRegistry->addFeatureToResults.

Your patch seems like to corrected the item 1.b with 2?

Thanks,
- Jacky

> Improper JavaScript inclusion logic leads to out-of-order and duplicate 
> includes / JavaScript errors
> ----------------------------------------------------------------------------------------------------
>
>                 Key: SHINDIG-1260
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-1260
>             Project: Shindig
>          Issue Type: Bug
>          Components: PHP
>    Affects Versions: 1.1-BETA5, 1.1-BETA6, 1.1-RC1
>         Environment: RedHat Linux 5.3, Apache 2.2.3, PHP 5.2.10
>            Reporter: James McIninch
>         Attachments: shindig-1260.patch
>
>
> The logic for selecting and inserting JavaScript using the 
> GadgetFeatureRegistry and GadgetBaseRender is incorrect. The result is that 
> JavaScript for features is included out-of-order of their dependencies, 
> sometimes multiply included, and the 'gadgets' JavaScript object is not 
> defined.
> Consider the following simple gadget:
> <?xml version="1.0" encoding="UTF-8"?>
> <Module>
>       <ModulePrefs title="Hello" description="An example of a simple gadget" 
> author="James McIninch" author_email="[email protected]" />
>       <UserPref name="firstname" display_name="Your name" datatype="string" 
> default_value="stranger" />
>       <Content type="html" preferred_height="50" preferred_width="200">
>               <![CDATA[
>                   <script type="text/javascript">
>                      var prefs = new gadgets.Prefs();
>                      var name  = prefs.getString("firstname");
>                      document.getElementById("placeholder").innerHTML = name;
>                   </script>
>                   
>                   Hello, <span id="placeholder">name goes here</span>!
>               ]]>
>       </Content>
> </Module>
> This is rendered as:
> Hello, name goes here!
> Inspecting the JavaScript error console shows that 'gadgets' is undefined. 
> However, the first instance of 'gadgets' being undefined lies in the 
> Shindig-included JavaScript. This is because auth-init.js is included before 
> config.js (both in features/src/main/javascript/features/core.*), but 
> auth-init.js contains the line (28):
> shindig.auth = new shindig.Auth();
> which, in turn calls (auth.js line 159):
> gadgets.config.register("shindig.auth", null, init);
> ... but the 'gadgets' and 'gadgets.config' objects are not yet defined at 
> that point. Despite being dependencies for the auth.js, they aren't  included 
> in the order where the dependencies precede the code that depends on them.
> Also looking at the source of the rendered gadget, the taming.js code is 
> included 5 separate times.
> Correcting the bug will entail re-thinking the logic of the feature ordering 
> to include the dependency information and order the features based on the 
> dependencies.
> All gadgets requiring the 'gadgets' object to be defined currently fail. 
> Gadgets using the legacy model still function, though there exists redundant 
> and erroneous JavaScript.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to