fix: preview fails when page has missing author #1886
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.
After importing a WP blog into Publii, the preview changes process failed with the following error:
Details
TypeError: Cannot read properties of undefined (reading 'name') at RendererContextPage.setContext (/home/git/fork-Publii/app/back-end/modules/render-html/contexts/page.js:110:86) at RendererContextPage.getContext (/home/git/fork-Publii/app/back-end/modules/render-html/contexts/page.js:144:14) at Renderer.generatePages (/home/git/fork-Publii/app/back-end/modules/render-html/renderer.js:1279:44) at Renderer.generateWWW (/home/git/fork-Publii/app/back-end/modules/render-html/renderer.js:242:18) at Renderer.renderFullPreview (/home/git/fork-Publii/app/back-end/modules/render-html/renderer.js:193:20) at Renderer.renderSite (/home/git/fork-Publii/app/back-end/modules/render-html/renderer.js:174:28) at Renderer.render (/home/git/fork-Publii/app/back-end/modules/render-html/renderer.js:119:24) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async process. (/home/git/fork-Publii/app/back-end/workers/renderer/preview.js:17:22)
To fix it, I added optional chaining operators in
app/back-end/modules/render-html/contexts/page.js
when accessing a page's author's name