@uniweb/runtime 1.3.11 → 1.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ssr.js +17 -1
- package/dist/ssr.js.map +1 -1
- package/package.json +1 -1
- package/src/page-renderer.js +5 -3
- package/src/ssr-renderer.js +30 -0
package/package.json
CHANGED
package/src/page-renderer.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* - **Anything build-only.** `injectBuildData` stays in the build lane; it is the
|
|
34
34
|
* other half of the head seam and has its own parity guard.
|
|
35
35
|
*/
|
|
36
|
-
import { renderPage, classifyRenderError, injectPageContent } from './ssr-renderer.js'
|
|
36
|
+
import { renderPage, classifyRenderError, failingSectionOf, injectPageContent } from './ssr-renderer.js'
|
|
37
37
|
import { resolveRequestedPage } from './resolve-page.js'
|
|
38
38
|
import { hydrateDataStore } from './wire-foundation.js'
|
|
39
39
|
import { loadPageData } from './load-page-data.js'
|
|
@@ -50,7 +50,9 @@ import { whileReadingIcons } from './page-icons.js'
|
|
|
50
50
|
* @param {Object} opts
|
|
51
51
|
* @param {Object} opts.website - `uniweb.activeWebsite`, already initialized
|
|
52
52
|
* @param {string} opts.shell - the HTML shell to inject into, taken as given
|
|
53
|
-
* @returns {{ website: Object, render: Function }}
|
|
53
|
+
* @returns {{ website: Object, render: Function, failingSection: Function }} `failingSection` asks
|
|
54
|
+
* which section stopped a page `render` reported as `failed` (`failingSectionOf`). A render per
|
|
55
|
+
* block: for a build's report, not for a host answering a request.
|
|
54
56
|
*/
|
|
55
57
|
export function createPageRenderer({ website, shell }) {
|
|
56
58
|
if (!website) throw new Error('createPageRenderer: `website` is required')
|
|
@@ -187,7 +189,7 @@ export function createPageRenderer({ website, shell }) {
|
|
|
187
189
|
return { outcome: missing ? 'notFound' : 'rendered', html, page, error: null }
|
|
188
190
|
}
|
|
189
191
|
|
|
190
|
-
return { website, render }
|
|
192
|
+
return { website, render, failingSection: (page, message) => failingSectionOf(page, message) }
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
/**
|
package/src/ssr-renderer.js
CHANGED
|
@@ -579,6 +579,36 @@ export function renderPage(page, website) {
|
|
|
579
579
|
return { renderedContent, sectionOverrideCSS }
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
+
/**
|
|
583
|
+
* Which section stopped a page from rendering, for a report to whoever can fix it: each block the
|
|
584
|
+
* page renders, alone, and the deepest that fails the same way. Null when none does, so the layout
|
|
585
|
+
* around them did. `renderPage` can say only what went wrong: `renderToString` names no component,
|
|
586
|
+
* and a built foundation's stack names minified ones.
|
|
587
|
+
*
|
|
588
|
+
* One render per block, so it's for a page that has already failed and a caller with time to spend.
|
|
589
|
+
* The same message, since a block alone misses what its layout gives it, and may fail for that.
|
|
590
|
+
*
|
|
591
|
+
* @param {Page} page - The page that failed
|
|
592
|
+
* @param {string} message - What `renderPage` reported
|
|
593
|
+
* @returns {string|null} the section's type
|
|
594
|
+
*/
|
|
595
|
+
export function failingSectionOf(page, message) {
|
|
596
|
+
const fails = (block) => {
|
|
597
|
+
try {
|
|
598
|
+
renderToString(renderBlock(block))
|
|
599
|
+
return false
|
|
600
|
+
} catch (err) {
|
|
601
|
+
return err.message === message
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const deepest = (block) => {
|
|
605
|
+
const child = (block.childBlocks || []).find(fails)
|
|
606
|
+
return child ? deepest(child) : block
|
|
607
|
+
}
|
|
608
|
+
const block = page.getAllBlocks().find(fails)
|
|
609
|
+
return block ? deepest(block).type : null
|
|
610
|
+
}
|
|
611
|
+
|
|
582
612
|
// ============================================================================
|
|
583
613
|
// HTML injection
|
|
584
614
|
// ============================================================================
|