Skip to content

Commit e383bce

Browse files
better handling for JSON.stringify in SSR page bundles
1 parent 95d8613 commit e383bce

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/cli/src/lifecycles/bundle.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { hashString } from '../lib/hashing-utils.js';
66
import { checkResourceExists, mergeResponse, normalizePathnameForWindows, trackResourcesForRoute } from '../lib/resource-utils.js';
77
import path from 'path';
88
import { rollup } from 'rollup';
9+
import { pruneGraph } from '../lib/content-utils.js';
910

1011
async function interceptPage(url, request, plugins, body) {
1112
let response = new Response(body, {
@@ -304,8 +305,8 @@ async function bundleSsrPages(compilation, optimizePlugins) {
304305
const moduleUrl = new URL('${relativeDepth}${pagesPathDiff}${pagePath.replace('./', '')}', import.meta.url);
305306
306307
export async function handler(request) {
307-
const compilation = JSON.parse('${JSON.stringify(compilation)}');
308-
const page = JSON.parse('${JSON.stringify(page)}');
308+
const compilation = JSON.parse(\`${JSON.stringify({ ...compilation, graph: pruneGraph(compilation.graph) }).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
309+
const page = JSON.parse(\`${JSON.stringify(pruneGraph([page])[0]).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
309310
const data = await executeRouteModule({ moduleUrl, compilation, page, request });
310311
let staticHtml = \`${staticHtml}\`;
311312

packages/cli/test/cases/serve.default.ssr/serve.default.ssr.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ describe('Serve Greenwood With: ', function() {
100100
});
101101
});
102102

103+
// https://github.com/ProjectEvergreen/greenwood/issues/1351
104+
describe('Serve command with HTML route response for the about page using various frontmatter syntaxes', function() {
105+
let response;
106+
let dom;
107+
108+
before(async function() {
109+
response = await fetch(`${hostname}/about/`);
110+
const body = await response.clone().text();
111+
dom = new JSDOM(body);
112+
});
113+
114+
it('should have the expected output for the page', function() {
115+
const headings = dom.window.document.querySelectorAll('body > h1');
116+
117+
expect(headings.length).to.equal(1);
118+
expect(headings[0].textContent).to.equal('Welcome to the about page!');
119+
});
120+
});
121+
103122
describe('Serve command with HTML route response for artists page using "get" functions', function() {
104123
let response;
105124
let dom;
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
## About Page
1+
---
2+
title: |
3+
Greenwood's Super Cool About Page
4+
imports:
5+
- ../components/counter.js type="module"
6+
sidebar:
7+
order: 1
8+
---
29

3-
Lorum Ipsum.
10+
# Welcome to the about page!

0 commit comments

Comments
 (0)