-
Notifications
You must be signed in to change notification settings - Fork 141
Conversation
iilei
commented
Jun 8, 2017
- Add tests for Hooks execution order and amount
- follow-up on Multiple link rel headers #140
I altered the integration test so it checks fragments serving fewer javascript files than permitted by |
lib/fragment.js
Outdated
this.scriptRefs.forEach((uri)=> { | ||
const id = this.index; | ||
const attributes = Object.assign({}, this.getPipeAttributes(), { id: this.attributes.id || id }); | ||
const attributes = Object.assign({}, this.getPipeAttributes(), { id: this.attributes.id || id, range, fragmentId }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We should combine both id and fragmentId
- Use index only for script ordering
- Id/fragmentId for all the other cases - context, perf hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## master #159 +/- ##
==========================================
+ Coverage 91.77% 96.57% +4.79%
==========================================
Files 13 13
Lines 523 525 +2
Branches 90 90
==========================================
+ Hits 480 507 +27
+ Misses 43 18 -25
Continue to review full report at Codecov.
|
There is an interesting bug here, If a fragment( Link: <module-1.js>; rel="fragment-script", <module-2.js>; rel="fragment-script", <module-3.js>; rel="fragment-script";
In this scenario, The hooks except This was not a problem before because we ignore if the fragment does not expose any default exports and fire all-done at last. |
Good catch ... I haven't used require.js before and I wonder if there is some callback that would be able to handle the load event of arbitrary stuff. |
Oops Sadly, this was broken before as well.. 'all-done' was never called if there was a script without a default export. I will try to find some hooks for require.js in the meanwhile. |
I am also trying to find a way on another branch 'fix_hooks_wip'. |
We need to handle three cases
We can handle the first one only if we can hook in to the |
I am starting to think, this logic should not be in tailor
Thoughts? @iilei |
I will create a new PR with your commits and some of my own. |
I agree. That would be a good way of separating concerns and reducing the footprint of tailor. therefore 👍 |
var init = i && i.__esModule ? i.default : i; | ||
// early return | ||
if (typeof init !== 'function') { | ||
initState.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fix the issue when onDone was not called for script without dependencies.
if (this.scriptRefs.length > 0) { | ||
const range = [this.index - this.scriptRefs.length, this.index - 1]; | ||
this.index--; | ||
const fragmentId = this.attributes.id || range[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By keeping the id consistent, It ll become easy to measure the fragment perf. I will update the fragment-performance script to handle this case.
@iilei Its ready, have added some changes to your PR. Let me know your thoughts, We can merge once you review it. |
@vigneshshanmugam great stuff 👍 I just added implicit testing the amount of hook execution by appending semicolons to the log lines. |
@iilei I did manually remove it :) All good |
Final rebase done. Merging it |