Skip to content

Commit

Permalink
Merge pull request #232 from withastro/main
Browse files Browse the repository at this point in the history
a1256
  • Loading branch information
akshit20421 authored Sep 25, 2024
2 parents f998cf8 + 1720c5b commit 04a226c
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-flowers-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes injected endpoint `prerender` option detection
2 changes: 1 addition & 1 deletion .github/workflows/check-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Get changed files in the .changeset folder
id: changed-files
uses: tj-actions/changed-files@v44
uses: tj-actions/changed-files@v45
if: steps.blocked.outputs.result != 'true'
with:
files: |
Expand Down
15 changes: 8 additions & 7 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export interface AstroUserConfig {
/**
* @docs
* @name security
* @type {boolean}
* @type {object}
* @default `{}`
* @version 4.9.0
* @description
Expand All @@ -838,7 +838,7 @@ export interface AstroUserConfig {
* @name security.checkOrigin
* @kind h4
* @type {boolean}
* @default 'false'
* @default `false`
* @version 4.9.0
* @description
*
Expand Down Expand Up @@ -1088,7 +1088,7 @@ export interface AstroUserConfig {
* ```js
* {
* build: {
* inlineStylesheets: `never`,
* inlineStylesheets: 'never',
* },
* }
* ```
Expand All @@ -1106,7 +1106,7 @@ export interface AstroUserConfig {
*
* ```js
* {
* server: { port: 1234, host: true}
* server: { port: 1234, host: true }
* }
* ```
*
Expand Down Expand Up @@ -1340,7 +1340,7 @@ export interface AstroUserConfig {
* @docs
* @name image.domains
* @type {string[]}
* @default `{domains: []}`
* @default `[]`
* @version 2.10.10
* @description
* Defines a list of permitted image source domains for remote image optimization. No other remote images will be optimized by Astro.
Expand Down Expand Up @@ -1387,6 +1387,7 @@ export interface AstroUserConfig {
* ```
*
* You can use wildcards to define the permitted `hostname` and `pathname` values as described below. Otherwise, only the exact values provided will be configured:
*
* `hostname`:
* - Start with '**.' to allow all subdomains ('endsWith').
* - Start with '*.' to allow only one level of subdomain.
Expand Down Expand Up @@ -1447,7 +1448,7 @@ export interface AstroUserConfig {
* import remarkToc from 'remark-toc';
* {
* markdown: {
* remarkPlugins: [ [remarkToc, { heading: "contents"} ] ]
* remarkPlugins: [ [remarkToc, { heading: "contents" }] ]
* }
* }
* ```
Expand Down Expand Up @@ -1517,7 +1518,7 @@ export interface AstroUserConfig {
* {
* markdown: {
* // Example: Translate the footnotes text to another language, here are the default English values
* remarkRehype: { footnoteLabel: "Footnotes", footnoteBackLabel: "Back to reference 1"},
* remarkRehype: { footnoteLabel: "Footnotes", footnoteBackLabel: "Back to reference 1" },
* },
* };
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function isPage(file: URL, settings: AstroSettings): boolean {
}

export function isEndpoint(file: URL, settings: AstroSettings): boolean {
if (!isInPagesDir(file, settings.config)) return false;
if (!isInPagesDir(file, settings.config) && !isInjectedRoute(file, settings)) return false;
if (!isPublicRoute(file, settings.config)) return false;
return !endsWithPageExt(file, settings) && !file.toString().includes('?astro');
}
Expand Down
10 changes: 9 additions & 1 deletion packages/astro/src/vite-plugin-scanner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ async function getPageOptions(
settings: AstroSettings,
logger: Logger,
): Promise<PageOptions> {
const fileUrlStr = fileURL.toString();
const injectedRoute = settings.resolvedInjectedRoutes.find(
(route) => route.resolvedEntryPoint && fileUrlStr === route.resolvedEntryPoint.toString(),
);

// Run initial scan
const pageOptions = await scan(code, id, settings);
const pageOptions =
injectedRoute?.prerender != null
? { prerender: injectedRoute.prerender }
: await scan(code, id, settings);

// Run integration hooks to alter page options
const route: RouteOptions = {
Expand Down
22 changes: 22 additions & 0 deletions packages/astro/test/fixtures/ssr-manifest/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'astro/config';
import testAdapter from '../../test-adapter.js';
import { fileURLToPath } from 'url';

export default defineConfig({
output: 'server',
adapter: testAdapter(),
integrations: [
{
name: 'test',
hooks: {
'astro:config:setup'({ injectRoute }) {
injectRoute({
entrypoint: fileURLToPath(new URL('./entrypoint-test.js', import.meta.url)),
pattern: '[...slug]',
prerender: true,
});
},
},
},
],
});
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/ssr-manifest/entrypoint-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const prerender = true;

export function getStaticPaths() {
return [{ params: { slug: 'test' } }];
}

export function GET() {
return new Response('OK — test');
}
17 changes: 0 additions & 17 deletions packages/astro/test/fixtures/ssr-manifest/src/pages/index.astro

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { manifest } from 'astro:ssr-manifest';

export function GET() {
return Response.json(manifest);
}
34 changes: 22 additions & 12 deletions packages/astro/test/ssr-manifest.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

describe('astro:ssr-manifest', () => {
Expand All @@ -11,27 +9,39 @@ describe('astro:ssr-manifest', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-manifest/',
output: 'server',
adapter: testAdapter(),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
await fixture.build();
});

it('works', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/');
const request = new Request('http://example.com/manifest.json');
const response = await app.render(request);
const html = await response.text();

const $ = cheerio.load(html);
assert.match($('#assets').text(), /\["\/_astro\/index.([\w-]{8})\.css"\]/);
const manifest = await response.json();
assert.equal(typeof manifest, 'object');
assert.equal(manifest.adapterName, 'my-ssr-adapter');
});

it('includes compressHTML', async () => {
const app = await fixture.loadTestAdapterApp();
// NOTE: `app.manifest` is actually a private property
assert.equal(app.manifest.compressHTML, true);
assert.equal(app.manifest.compressHTML, true);
});

it('includes correct routes', async () => {
const app = await fixture.loadTestAdapterApp();
// NOTE: `app.manifest` is actually a private property

const manifestJsonEndpoint = app.manifest.routes.find(
(route) => route.routeData.route === '/manifest.json',
);
assert.ok(manifestJsonEndpoint);
assert.equal(manifestJsonEndpoint.routeData.prerender, false);

// There should be no route for prerendered injected routes
const injectedEndpoint = app.manifest.routes.find(
(route) => route.routeData.route === '/[...slug]',
);
assert.equal(injectedEndpoint, undefined);
});
});

0 comments on commit 04a226c

Please sign in to comment.