Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/issue 1154 inline template strings in SSR page templates break bundling #1155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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