This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
feat: send data for fallback if hmr apply fails #687
Merged
Merged
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 hidden or 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 |
---|---|---|
|
@@ -6,9 +6,9 @@ const log = { | |
}; | ||
const refresh = 'Application needs to be restarted in order to apply the changes.'; | ||
const hotOptions = { | ||
ignoreUnaccepted: true, | ||
ignoreDeclined: true, | ||
ignoreErrored: true, | ||
ignoreUnaccepted: false, | ||
ignoreDeclined: false, | ||
ignoreErrored: false, | ||
onUnaccepted(data) { | ||
const chain = [].concat(data.chain); | ||
const last = chain[chain.length - 1]; | ||
|
@@ -30,10 +30,11 @@ const hotOptions = { | |
}, | ||
}; | ||
|
||
let lastHash; | ||
let nextHash; | ||
let currentHash; | ||
|
||
function upToDate() { | ||
return lastHash.indexOf(__webpack_hash__) >= 0; | ||
return nextHash.indexOf(__webpack_hash__) >= 0; | ||
} | ||
|
||
function result(modules, appliedModules) { | ||
|
@@ -90,17 +91,16 @@ function check(options) { | |
result(modules, appliedModules); | ||
|
||
if (upToDate()) { | ||
log.info('App is up to date.'); | ||
//Do not modify message - CLI depends on this exact content to determine hmr operation status. | ||
log.info(`Successfully applied update with hmr hash ${currentHash}. App is up to date.`); | ||
} | ||
}) | ||
.catch((err) => { | ||
const status = module.hot.status(); | ||
if (['abort', 'fail'].indexOf(status) >= 0) { | ||
log.warn(`Cannot apply update. ${refresh}`); | ||
//Do not modify message - CLI depends on this exact content to determine hmr operation status. | ||
log.warn(`Cannot apply update with hmr hash ${currentHash}.`); | ||
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. Add comment to not change - it will break CLI |
||
log.warn(err.stack || err.message); | ||
if (options.reload) { | ||
window.location.reload(); | ||
} | ||
} else { | ||
log.warn(`Update failed: ${err.stack || err.message}`); | ||
} | ||
|
@@ -123,13 +123,14 @@ if (module.hot) { | |
log.error('Hot Module Replacement is disabled.'); | ||
} | ||
|
||
function update(currentHash, options) { | ||
lastHash = currentHash; | ||
function update(latestHash, options) { | ||
nextHash = latestHash; | ||
if (!upToDate()) { | ||
const status = module.hot.status(); | ||
|
||
if (status === 'idle') { | ||
log.info('Checking for updates to the bundle.'); | ||
//Do not modify message - CLI depends on this exact content to determine hmr operation status. | ||
log.info(`Checking for updates to the bundle with hmr hash ${currentHash}.`); | ||
check(options); | ||
} else if (['abort', 'fail'].indexOf(status) >= 0) { | ||
log.warn( | ||
|
@@ -139,24 +140,24 @@ function update(currentHash, options) { | |
} | ||
}; | ||
|
||
function getCurrentHash(currentHash, getFileContent) { | ||
const file = getFileContent(`${currentHash}.hot-update.json`); | ||
function getNextHash(hash, getFileContent) { | ||
const file = getFileContent(`${hash}.hot-update.json`); | ||
return file.readText().then(hotUpdateContent => { | ||
if(hotUpdateContent) { | ||
const manifest = JSON.parse(hotUpdateContent); | ||
const newHash = manifest.h; | ||
return getCurrentHash(newHash, getFileContent); | ||
return getNextHash(newHash, getFileContent); | ||
} else { | ||
return Promise.resolve(currentHash); | ||
return Promise.resolve(hash); | ||
} | ||
}).catch(error => Promise.reject(error)); | ||
} | ||
|
||
module.exports = function checkState(initialHash, getFileContent) { | ||
getCurrentHash(initialHash, getFileContent).then(currentHash => { | ||
if(currentHash != initialHash) { | ||
update(currentHash, {}); | ||
currentHash = initialHash; | ||
getNextHash(initialHash, getFileContent).then(nextHash => { | ||
if(nextHash != initialHash) { | ||
update(nextHash, {}); | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Can you extract the messages to constants?