Skip to content

Commit

Permalink
fix(vue-renderer): parse JSON values before passing to bundle-renderer
Browse files Browse the repository at this point in the history
prevent error that occuers in rare cases: TypeError: Cannot read property 'sections' of undefined

Related to #4439
  • Loading branch information
pi0 committed Dec 1, 2018
1 parent 0f104aa commit c0721c0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vue-renderer/src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c0721c0

Please sign in to comment.