Skip to content

Conversation

@crutch12
Copy link

@crutch12 crutch12 commented Dec 9, 2025

  • allow prerender typings: async function prerender({}: PrerenderOptions): Promise<PrerenderResult | string>
  • better result checks
  • console output fixes

@crutch12
Copy link
Author

crutch12 commented Dec 9, 2025

@rschristian check it out, please 🙏

@crutch12 crutch12 force-pushed the feat/prerender-types branch from bb095cf to 75046d8 Compare December 9, 2025 13:21
Copy link
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick skim, I'm not sure any of this is useful? It's a lot of minor formatting changes or just moving around jsdoc casts, neither of which are valuable.

@crutch12
Copy link
Author

crutch12 commented Dec 9, 2025

@rschristian it's because of prettier. looks like nobody called "pnpm format" for a long time. I can format all the code in additional commit, it you want

The sense of PR is in exported types

@rschristian
Copy link
Member

Don't change the formatting at all please, revert the unrelated changes entirely and then I'll take another look.

@crutch12 crutch12 force-pushed the feat/prerender-types branch from 75046d8 to 40d3251 Compare December 9, 2025 16:19
@crutch12
Copy link
Author

crutch12 commented Dec 9, 2025

Returned formatting

Comment on lines -497 to +502
result.renderTarget == 'body'
renderTarget == 'body'
? '`renderTarget` was not specified in plugin options and <body> does not exist in input HTML template'
: `Unable to detect prerender renderTarget "${result.selector}" in input HTML template`,
: `Unable to detect prerender renderTarget "${renderTarget}" in input HTML template`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, good spot on both (or good spot from the types). Changed this API ages ago and I guess it slipped through.

Comment on lines +24 to +32
export interface PrerenderResult {
html?: string;
head?: Partial<Head>;
links?: Set<string>;
/**
* @description Caution: should be a valid JSON object
*/
data?: any;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you spotted above in the source file, this should be a union with a string. return '<h1>Hello World</h1>'; is perfectly valid too.

Comment on lines +426 to +428
/** @type {import('./types.d.ts').PrerenderOptions} */
const options = { ssr: true, url: route.url, route };
result = await prerender(options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for this line to change

Suggested change
/** @type {import('./types.d.ts').PrerenderOptions} */
const options = { ssr: true, url: route.url, route };
result = await prerender(options);
result = await prerender({ ssr: true, url: route.url, route });


// Add any discovered links to the list of routes to pre-render:
if (result.links) {
if (typeof result === 'object' && result.links) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for this line to change

Suggested change
if (typeof result === 'object' && result.links) {
if (result.links) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants