Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 404957

Summary: Minified builds have "blank page syndrome" with RequireJS 2
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: ClientAssignee: Mark Macdonald <mamacdon>
Status: RESOLVED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: ken_walker, simon_kaegi
Version: 3.0   
Target Milestone: 3.0 M1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2013-04-04 18:48:16 EDT
The client-side minified pages do not load after the upgrade to RequireJS 2 (see bug 402976). The symptom is:

1. Download the build, run orion.exe
2. Go to any page
3. Page is blank -- UI never loads

Here is one of the broken builds:
http://download.eclipse.org/orion/drops/I201304041509/

Not even the index page (/index.html) will display correctly. The callback for the main module never fires. Some of its dependencies are loaded (but not all of them).

If you revert to RequireJS 1.x (by dropping the old version into 'plugins/org.eclipse.orion.client.core_xxxxx/web/requirejs' and refreshing) the same minified pages will load correctly.
Comment 1 Mark Macdonald CLA 2013-04-04 19:41:59 EDT
Correction: none of the module's callbacks (factory functions) are ever called.
Comment 2 Mark Macdonald CLA 2013-04-04 19:46:41 EDT
I think [1] describes our problem. To quote:

> So this is interesting: the data-main="index.js", but the module ID
> for the main module is "index". With the new "only execute modules
> that have been required" logic in 2.0[1], only a module called
> 'index.js' is executed.
> 
> (In requirejs 1.0, it would execute all define()s even if they were
> not explicitly require()'d. The data-main processing is an implicit
> require())
> 
> There is no define() with the the name 'index.js' after the build.
> Before the build, since the define() in index.js is anonymous, it gets
> the 'index.js' name, and it runs.
> 
> The fix is to use data-main="index", then it works in both cases. 

[1] http://groups.google.com/group/requirejs/browse_thread/thread/e64a2817e7071495/6e5ad736e72a7c45
Comment 3 Mark Macdonald CLA 2013-04-04 19:56:20 EDT
In Orion's case, "built-index.js" (the concatenated file) is the module that our page asks for:

> <script>
>   require({
>     /* .. */
>   });
> 
>   require(["built-index.js"]); // !!
> </script>

... But if you look at the source of built-index.js, there is no module named "built-index.js", rather it's named "index.js":

> /* .. */
> 
> define('index.js',['orion/bootstrap', 'domReady!'], function(mBootstrap) {
> 	mBootstrap.startup().then(function(core) {
> 		window.location = "navigate/table.html";
> 	});
> });

Nobody ever asks for "index.js", so the module is never loaded, and the page ultimately does nothing. The fix is to change the module name to built-index.js in the concatenated file:

> define('built-index.js',['orion/bootstrap', 'domReady!'], function(mBootstrap) {
>         ^^^^^^^^^^^^^^

^^ Like this, the page loads OK.
Comment 5 Mark Macdonald CLA 2013-04-05 19:34:48 EDT
Fixed in build I20130405-1735 by these commits
* http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=94e11f4287e6926523a58bba98c9abc09fba7ff4
* http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=5e836da3ddb617dcbd71cc2683177c5a4dc8ddb7
* http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=9c14180531c97cd6646f85af616ab92f5ebc7b1e
* http://git.eclipse.org/c/orion/org.eclipse.orion.server.git/commit/?id=25415125ea80e747cbda3d14ddd6cf43abce4b71

The fix is basically to find+replace the module name as explained in Comment 3. The build script now does this for us.

This works but it's a fragile approach. Simon thinks that we should be moving our pages to the data-main="" style and using the `paths` option to sub in the optimized version of the page module.

It might also be better to move more of the work currently done by Orion's Ant build script into our r.js build file. For example, r.js has API for processing an entire project that we should look into, rather than invoking r.js repeatedly from Ant. Apparently r.js can run in browsers now too. So the more work we can shift onto it (and ultimately the browser, at dev time) the better.