Skip to content

Commit

Permalink
better handling for JSON.stringify in SSR page bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Dec 27, 2024
1 parent f77b894 commit d683663
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { hashString } from '../lib/hashing-utils.js';
import { checkResourceExists, mergeResponse, normalizePathnameForWindows, trackResourcesForRoute } from '../lib/resource-utils.js';
import path from 'path';
import { rollup } from 'rollup';
import { pruneGraph } from '../lib/content-utils.js';

async function interceptPage(url, request, plugins, body) {
let response = new Response(body, {
Expand Down Expand Up @@ -309,8 +310,8 @@ async function bundleSsrPages(compilation, optimizePlugins) {
const moduleUrl = new URL('${relativeDepth}${pagesPathDiff}${pagePath.replace('./', '')}', import.meta.url);
export async function handler(request) {
const compilation = JSON.parse('${JSON.stringify(compilation)}');
const page = JSON.parse('${JSON.stringify(page)}');
const compilation = JSON.parse(\`${JSON.stringify({ ...compilation, graph: pruneGraph(compilation.graph) }).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
const page = JSON.parse(\`${JSON.stringify(pruneGraph([page])[0]).replace(/\\"/g, '&quote').replace(/\\n/g, '')}\`);
const data = await executeRouteModule({ moduleUrl, compilation, page, request });
let staticHtml = \`${staticHtml}\`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ describe('Serve Greenwood With: ', function() {
});
});

// https://github.com/ProjectEvergreen/greenwood/issues/1351
describe('Serve command with HTML route response for the about page using various frontmatter syntaxes', function() {
let response;
let dom;

before(async function() {
response = await fetch(`${hostname}/about/`);
const body = await response.clone().text();
dom = new JSDOM(body);
});

it('should have the expected output for the page', function() {
const headings = dom.window.document.querySelectorAll('body > h1');

expect(headings.length).to.equal(1);
expect(headings[0].textContent).to.equal('Welcome to the about page!');
});
});

describe('Serve command with HTML route response for artists page using "get" functions', function() {
let response;
let dom;
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/test/cases/serve.default.ssr/src/pages/about.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## About Page
---
title: |
Greenwood's Super Cool About Page
imports:
- ../components/counter.js type="module"
sidebar:
order: 1
---

Lorum Ipsum.
# Welcome to the about page!

0 comments on commit d683663

Please sign in to comment.