Skip to content

Commit

Permalink
handle escaping of nested template literals when bundling and packing…
Browse files Browse the repository at this point in the history
… SSR page templates (#1155)
  • Loading branch information
thescientist13 authored Oct 14, 2023
1 parent eb5b77f commit f1781e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ async function bundleSsrPages(compilation) {
staticHtml = await getAppTemplate(staticHtml, compilation.context, imports, [], false, title);
staticHtml = await getUserScripts(staticHtml, compilation.context);
staticHtml = await (await htmlOptimizer.optimize(new URL(`http://localhost:8080${route}`), new Response(staticHtml))).text();
staticHtml = staticHtml.replace(/[`\\$]/g, '\\$&'); // https://stackoverflow.com/a/75688937/417806

// better way to write out this inline code?
await fs.writeFile(entryFileUrl, `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Serve Greenwood With: ', function() {
it('should have the expected number of <script> tags in the <head>', function() {
const scripts = artistsPageDom.window.document.querySelectorAll('head > script');

expect(scripts.length).to.equal(3);
expect(scripts.length).to.equal(4);
});

it('should have the expected <app-header> tag from the app template in the <head>', function() {
Expand All @@ -194,8 +194,8 @@ describe('Serve Greenwood With: ', function() {
const scripts = Array.from(artistsPageDom.window.document.querySelectorAll('head > script'))
.filter(tag => !tag.getAttribute('type'));

expect(scripts.length).to.equal(1);
expect(scripts[0].textContent).to.contain('console.log');
expect(scripts.length).to.equal(2);
expect(scripts[1].textContent).to.contain('console.log');
});

it('should have the expected number of table rows of content', function() {
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('Serve Greenwood With: ', function() {
it('should append the expected graph resource scripts for the page from a template', function() {
const { resources } = artistsPageGraphData;

expect(resources.length).to.equal(4);
expect(resources.length).to.equal(5);
expect(resources.find(resource => resource.endsWith('/header.js'))).to.not.be.undefined;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script type="module" src="../components/header.js"></script>
<script>
// https://github.com/ProjectEvergreen/greenwood/issues/1154
const message = `The current time is ${new Date().getTime()}`;

alert(message);
</script>
</head>
<body>
<app-header></app-header>
Expand Down

0 comments on commit f1781e0

Please sign in to comment.