fix(vue-renderer): parse JSON values before passing to bundle-renderer

prevent error that occuers in rare cases: TypeError: Cannot read property 'sections' of undefined

Related to #4439
This commit is contained in:
Pooya Parsa 2018-12-01 14:11:10 +03:30
parent 0f104aa588
commit c0721c0174

View File

@ -389,19 +389,23 @@ export default class VueRenderer {
transform: (src, { readResource, oldValue = { files: {}, maps: {} } }) => {
const serverManifest = JSON.parse(src)
const resolveAssets = (obj, oldObj, encoding) => {
const resolveAssets = (obj, oldObj, isJSON) => {
Object.keys(obj).forEach((name) => {
obj[name] = readResource(obj[name], encoding)
obj[name] = readResource(obj[name])
// Try to reuse deleted MFS files if no new version exists
if (!obj[name]) {
obj[name] = oldObj[name]
}
// Parse JSON
if (isJSON) {
obj[name] = JSON.parse(obj[name])
}
})
return obj
}
const files = resolveAssets(serverManifest.files, oldValue.files)
const maps = resolveAssets(serverManifest.maps, oldValue.maps, 'utf-8')
const maps = resolveAssets(serverManifest.maps, oldValue.maps, true)
return {
...serverManifest,