diff --git a/src/core/app/index.ts b/src/core/app/index.ts index 8f5113ca97fb..c2f5d9a2e577 100644 --- a/src/core/app/index.ts +++ b/src/core/app/index.ts @@ -19,7 +19,6 @@ import { createModuleScriptElementWithSrcSet, } from '../render/ssr-element.js'; import { prependForwardSlash } from '../path.js'; -import { createRequest } from '../request.js'; export class App { #manifest: Manifest; diff --git a/src/core/build/index.ts b/src/core/build/index.ts index 98c8f1e8db23..de35cb66a4f3 100644 --- a/src/core/build/index.ts +++ b/src/core/build/index.ts @@ -105,7 +105,7 @@ class AstroBuilder { client: new URL('./client/', this.config.outDir), server: new URL('./server/', this.config.outDir), serverEntry: 'entry.mjs', - staticMode: undefined, + staticMode: undefined }; await runHookBuildStart({ config: this.config, buildConfig }); diff --git a/src/core/build/vite-plugin-ssr.ts b/src/core/build/vite-plugin-ssr.ts index 3e7257f02e76..871c2ce08075 100644 --- a/src/core/build/vite-plugin-ssr.ts +++ b/src/core/build/vite-plugin-ssr.ts @@ -13,6 +13,7 @@ import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; export const virtualModuleId = '@astrojs-ssr-virtual-entry'; const resolvedVirtualModuleId = '\0' + virtualModuleId; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; +const replaceExp = new RegExp(`['"](${manifestReplace})['"]`, 'g'); export function vitePluginSSR( buildOpts: StaticBuildOptions, @@ -64,18 +65,16 @@ if(_start in adapter) { } return void 0; }, - generateBundle(_opts, bundle) { const manifest = buildManifest(buildOpts, internals); for (const [_chunkName, chunk] of Object.entries(bundle)) { if (chunk.type === 'asset') continue; if (chunk.modules[resolvedVirtualModuleId]) { - const exp = new RegExp(`['"]${manifestReplace}['"]`); const code = chunk.code; - chunk.code = code.replace(exp, () => { + chunk.code = code.replace(replaceExp, () => { return JSON.stringify(manifest); - }); + }) } } }, diff --git a/src/core/config.ts b/src/core/config.ts index dd33919d85a3..0160c76e1165 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -196,7 +196,7 @@ export const AstroConfigSchema = z.object({ export async function validateConfig( userConfig: any, root: string, - cmd: string + cmd: string, ): Promise { const fileProtocolRoot = pathToFileURL(root + path.sep); // Manual deprecation checks @@ -433,7 +433,7 @@ export async function resolveConfig( userConfig: AstroUserConfig, root: string, flags: CLIFlags = {}, - cmd: string + cmd: string, ): Promise { const mergedConfig = mergeCLIFlags(userConfig, flags, cmd); const validatedConfig = await validateConfig(mergedConfig, root, cmd); diff --git a/test/fixtures/ssr-markdown/package.json b/test/fixtures/ssr-markdown/package.json new file mode 100644 index 000000000000..4c76381919b1 --- /dev/null +++ b/test/fixtures/ssr-markdown/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/ssr-markdown", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/test/fixtures/ssr-markdown/src/layouts/Base.astro b/test/fixtures/ssr-markdown/src/layouts/Base.astro new file mode 100644 index 000000000000..13feea6a61bb --- /dev/null +++ b/test/fixtures/ssr-markdown/src/layouts/Base.astro @@ -0,0 +1,8 @@ + +Testing + +
+ +
+ + diff --git a/test/fixtures/ssr-markdown/src/pages/page.astro b/test/fixtures/ssr-markdown/src/pages/page.astro new file mode 100644 index 000000000000..83ec88d9f7c1 --- /dev/null +++ b/test/fixtures/ssr-markdown/src/pages/page.astro @@ -0,0 +1,14 @@ +--- +import { Markdown } from 'astro/components'; +--- + + +Testing + + + # Something + + else here + + + diff --git a/test/fixtures/ssr-markdown/src/pages/post.md b/test/fixtures/ssr-markdown/src/pages/post.md new file mode 100644 index 000000000000..7c087fd047a7 --- /dev/null +++ b/test/fixtures/ssr-markdown/src/pages/post.md @@ -0,0 +1,9 @@ +--- +layout: ../layouts/Base.astro +--- + +# Hello world + +This is some test + +## Subheading diff --git a/test/ssr-markdown.test.js b/test/ssr-markdown.test.js new file mode 100644 index 000000000000..700135476660 --- /dev/null +++ b/test/ssr-markdown.test.js @@ -0,0 +1,41 @@ +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; +import { loadFixture } from './test-utils.js'; +import testAdapter from './test-adapter.js'; + +describe('Markdown pages in SSR', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-markdown/', + experimental: { + ssr: true, + }, + adapter: testAdapter(), + }); + await fixture.build(); + }); + + async function fetchHTML(path) { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com' + path); + const response = await app.render(request); + const html = await response.text(); + return html; + } + + + it('Renders markdown pages correctly', async () => { + const html = await fetchHTML('/post'); + const $ = cheerioLoad(html); + expect($('#subheading').text()).to.equal('Subheading'); + }); + + it('Renders the Markdown component correctly', async () => { + const html = await fetchHTML('/page'); + const $ = cheerioLoad(html); + expect($('#something')).to.have.lengthOf(1); + }); +}); diff --git a/test/test-adapter.js b/test/test-adapter.js index 99ab34e5df95..2f4868568891 100644 --- a/test/test-adapter.js +++ b/test/test-adapter.js @@ -37,7 +37,7 @@ export default function () { serverEntrypoint: '@my-ssr', exports: ['manifest', 'createApp'], }); - }, + } }, }; }