Skip to content

Commit

Permalink
fix: bad import of pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 30, 2023
1 parent 7f98f46 commit 62a524d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export class App {
defaultStatus = 404;
}

let page = await this.#manifest.pageMap.get(routeData.component)!();
let mod = await page.page();
let mod = await this.#manifest.pageMap.get(routeData.component)!();
// let mod = await page.page();

if (routeData.type === 'page') {
let response = await this.#renderPage(request, routeData, mod, defaultStatus);
Expand All @@ -147,8 +147,8 @@ export class App {
if (response.status === 500 || response.status === 404) {
const errorPageData = matchRoute('/' + response.status, this.#manifestData);
if (errorPageData && errorPageData.route !== routeData.route) {
page = await this.#manifest.pageMap.get(errorPageData.component)!();
mod = await page.page();
mod = await this.#manifest.pageMap.get(errorPageData.component)!();
// mod = await page.page();
try {
let errorResponse = await this.#renderPage(
request,
Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
SSRLoadedRenderer,
SSRResult,
} from '../../@types/astro';
import type { SinglePageBuiltModule } from '../build/types';
import type { ComponentInstance } from '../../@types/astro';

export type ComponentPath = string;

Expand All @@ -31,7 +31,6 @@ export interface RouteInfo {
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
routeData: SerializedRouteData;
};
type ImportComponentInstance = () => Promise<SinglePageBuiltModule>;

export interface SSRManifest {
adapterName: string;
Expand All @@ -40,7 +39,7 @@ export interface SSRManifest {
base?: string;
assetsPrefix?: string;
markdown: MarkdownRenderingOptions;
pageMap: Map<ComponentPath, ImportComponentInstance>;
pageMap: Map<ComponentPath, () => ComponentInstance>;
renderers: SSRLoadedRenderer[];
/**
* Map of directive name (e.g. `load`) to the directive script code
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function vitePluginMiddleware(
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
);
if (middlewareId) {
return middlewareId.id;
return middlewareId;
}
}
},
Expand Down
12 changes: 7 additions & 5 deletions packages/astro/src/core/build/plugins/plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function vitePluginSSR(
let middleware;
const middlewareModule = await this.resolve(MIDDLEWARE_MODULE_ID);
if (middlewareModule) {
imports.push(`import * as _middleware from "${middlewareModule.id}"`);
imports.push(`import * as _middleware from '${MIDDLEWARE_MODULE_ID}'`);
middleware = 'middleware: _middleware';
}
let i = 0;
Expand All @@ -60,12 +60,14 @@ function vitePluginSSR(
const virtualModuleName = getVirtualModulePageNameFromPath(path);
let module = await this.resolve(virtualModuleName);
if (module) {
const variable = `_page${i}`;
// we need to use the non-resolved ID in order to resolve correctly the virtual module
imports.push(`const ${variable} = () => import("${virtualModuleName}");`);

const pageData = internals.pagesByComponent.get(path);
if (pageData) {
const variable = `_page${i}`;
// we need to use the non-resolved ID in order to resolve correctly the virtual module
imports.push(
`const ${variable} = () => import(${JSON.stringify(pageData.moduleSpecifier)});`
);

pageMap.push(`[${JSON.stringify(pageData.component)}, ${variable}]`);
}
i++;
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ async function ssrBuild(
return makeAstroPageEntryPointFileName(chunkInfo.facadeModuleId);
} else if (
// checks if the path of the module we have middleware, e.g. middleware.js / middleware/index.js
chunkInfo.facadeModuleId?.includes('middleware') &&
chunkInfo.moduleIds.find((m) => m.includes('middleware')) !== undefined &&
// checks if the file actually export the `onRequest` function
chunkInfo.exports.includes('onRequest')
chunkInfo.exports.includes('_middleware')
) {
return 'middleware.mjs';
} else if (chunkInfo.facadeModuleId === SSR_VIRTUAL_MODULE_ID) {
Expand Down

0 comments on commit 62a524d

Please sign in to comment.