also looking at this
fix(layouts): keep a page's @push content when its layout extends another layout
#2105
2 files
+106
-3
| @@ -962,6 +962,13 @@ async function processDirectivesInternal( | ||
| 962 | 962 | |
| 963 | 963 | let output = template |
| 964 | 964 | |
| 965 | // What the page and the layouts so far pushed, when this call renders the | |
| 966 | // layout that a layout extends (see the nested-layout branch). Taken off the | |
| 967 | // context before anything else runs, so view composers, middleware, | |
| 968 | // components and includes never see it. | |
| 969 | const inheritedStacks = context.__stx_layout_stacks as { stacks: Record<string, string[]>, htmlComments: string[] } | undefined | |
| 970 | delete context.__stx_layout_stacks | |
| 971 | ||
| 965 | 972 | await runViewComposersForTemplate(filePath, context) |
| 966 | 973 | prepareDirectiveContext(context, opts) |
| 967 | 974 | |
| @@ -1052,8 +1059,16 @@ async function processDirectivesInternal( | ||
| 1052 | 1059 | // and: <link href="./file.css" stx-inline /> |
| 1053 | 1060 | output = await processInlineAssets(output, filePath, dependencies) |
| 1054 | 1061 | |
| 1055 | // Store stacks for @push/@stack directives | |
| 1062 | // Store stacks for @push/@stack directives, starting with the inherited | |
| 1063 | // ones. Their HTML comments are masked against the caller's table, so each | |
| 1064 | // one moves into this call's table under a new index. | |
| 1056 | 1065 | const stacks: Record<string, string[]> = {} |
| 1066 | for (const [name, entries] of Object.entries(inheritedStacks?.stacks ?? {})) { | |
| 1067 | stacks[name] = entries.map(entry => entry.replace(/\x00STX_HTML_COMMENT_(\d+)\x00/g, (_, i) => { | |
| 1068 | htmlComments.push(inheritedStacks!.htmlComments[Number(i)] ?? '') | |
| 1069 | return `\x00STX_HTML_COMMENT_${htmlComments.length - 1}\x00` | |
| 1070 | })) | |
| 1071 | } | |
| 1057 | 1072 | |
| 1058 | 1073 | // Process @push and @prepend directives first |
| 1059 | 1074 | output = processStackPushDirectives(output, stacks) |
| @@ -1461,8 +1476,8 @@ async function processDirectivesInternal( | ||
| 1461 | 1476 | } |
| 1462 | 1477 | } |
| 1463 | 1478 | |
| 1464 | // Create a new context with merged sections for the nested layout | |
| 1465 | const nestedContext = { ...context, __sections: sections } | |
| 1479 | // Create a new context with merged sections and the pushes so far for the nested layout | |
| 1480 | const nestedContext = { ...context, __sections: sections, __stx_layout_stacks: { stacks, htmlComments } } | |
| 1466 | 1481 | |
| 1467 | 1482 | // Process the nested layout by recursively calling processDirectives |
| 1468 | 1483 | // with the modified template that includes the @layout directive |