This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Fix hooks #159
Merged
Merged
Fix hooks #159
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,21 @@ | |
starts[index] = currentScript(); | ||
if (script) { | ||
initState.push(index); | ||
hooks.onStart(attributes); | ||
hooks.onStart(attributes, index); | ||
require([script]); | ||
} | ||
} | ||
|
||
// OnDone will be called once the document is completed parsed and there are no other fragments getting streamed. | ||
function fireDone() { | ||
if (initState.length === 0 | ||
&& doc.readyState | ||
&& (doc.readyState === 'complete' | ||
|| doc.readyState === 'interactive') ) { | ||
hooks.onDone(); | ||
} | ||
} | ||
|
||
function end(index, script, attributes) { | ||
var placeholder = placeholders[index]; | ||
var start = starts[index]; | ||
|
@@ -63,10 +73,12 @@ | |
start.parentNode.removeChild(start); | ||
end.parentNode.removeChild(end); | ||
script && require([script], function (i) { | ||
// Exposed fragment initialization Function/Promise | ||
// Exported AMD fragment initialization Function/Promise | ||
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 commentThe 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. |
||
fireDone(); | ||
return; | ||
} | ||
|
||
|
@@ -76,18 +88,12 @@ | |
} | ||
|
||
function doInit(init, node) { | ||
hooks.onBeforeInit(attributes); | ||
hooks.onBeforeInit(attributes, index); | ||
var fragmentRendering = init(node); | ||
var handlerFn = function() { | ||
initState.pop(); | ||
hooks.onAfterInit(attributes); | ||
// OnDone will be called once the document is completed parsed and there are no other fragments getting streamed. | ||
if (initState.length === 0 | ||
&& doc.readyState | ||
&& (doc.readyState === 'complete' | ||
|| doc.readyState === 'interactive') ) { | ||
hooks.onDone(); | ||
} | ||
hooks.onAfterInit(attributes, index); | ||
fireDone(attributes); | ||
}; | ||
// Check if the response from fragment is a Promise to allow lazy rendering | ||
if (isPromise(fragmentRendering)) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.