Skip to content

Commit 7f71882

Browse files
committed
OEL-4185: Fixed mega menu.
1 parent df87b00 commit 7f71882

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/webpack/twig-wrapper-loader.cjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ module.exports = function twigWrapperLoader(source) {
44

55
let code = source;
66

7+
code = code.replace(
8+
/templates\.set\((['"][^'"]+['"]), (template\d+)\);/g,
9+
"templates.set($1, () => $2);",
10+
);
11+
12+
code = code.replace(
13+
/template\.loadTemplate = \(executionContext, identifier\) => {\s*return templates.has\(identifier\) \? Promise\.resolve\(templates\.get\(identifier\)\) : baseLoadTemplate\(executionContext, identifier\);\s*};/,
14+
`template.loadTemplate = (executionContext, identifier) => {
15+
if (!templates.has(identifier)) {
16+
return baseLoadTemplate(executionContext, identifier);
17+
}
18+
19+
const candidate = templates.get(identifier);
20+
const resolved = typeof candidate === 'function' ? candidate() : candidate;
21+
22+
if (!resolved) {
23+
return baseLoadTemplate(executionContext, identifier);
24+
}
25+
26+
return Promise.resolve(resolved);
27+
};`,
28+
);
29+
730
code = `import environment from '${environmentModulePath}';\n${code}`;
831

932
if (code.includes("export default template;")) {

0 commit comments

Comments
 (0)