-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: types for prerender options and result; better result checks #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -382,7 +382,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere | |||||
| return message; | ||||||
| }; | ||||||
|
|
||||||
| /** @type {import('./types.d.ts').Head} */ | ||||||
| /** @type {Partial<import('./types.d.ts').Head>} */ | ||||||
| let head = { lang: '', title: '', elements: new Set() }; | ||||||
|
|
||||||
| let prerender; | ||||||
|
|
@@ -420,9 +420,12 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere | |||||
| } catch {} | ||||||
| } | ||||||
|
|
||||||
| /** @type {import('./types.d.ts').PrerenderResult | string} */ | ||||||
| let result; | ||||||
| try { | ||||||
| result = await prerender({ ssr: true, url: route.url, route }); | ||||||
| /** @type {import('./types.d.ts').PrerenderOptions} */ | ||||||
| const options = { ssr: true, url: route.url, route }; | ||||||
| result = await prerender(options); | ||||||
| } catch (e) { | ||||||
| const message = await handlePrerenderError(e); | ||||||
| this.error(message); | ||||||
|
|
@@ -438,7 +441,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere | |||||
| head = { lang: '', title: '', elements: new Set() }; | ||||||
|
|
||||||
| // Add any discovered links to the list of routes to pre-render: | ||||||
| if (result.links) { | ||||||
| if (typeof result === 'object' && result.links) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need for this line to change
Suggested change
|
||||||
| for (let url of result.links) { | ||||||
| const parsed = new URL(url, 'http://localhost'); | ||||||
| url = parsed.pathname.replace(/\/$/, '') || '/'; | ||||||
|
|
@@ -494,9 +497,9 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere | |||||
| const target = htmlDoc.querySelector(renderTarget); | ||||||
| if (!target) | ||||||
| this.error( | ||||||
| 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`, | ||||||
|
Comment on lines
-497
to
+502
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
| ); | ||||||
| target.insertAdjacentHTML('afterbegin', body); | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,19 @@ export interface PrerenderedRoute { | |
| url: string; | ||
| _discoveredBy?: PrerenderedRoute; | ||
| } | ||
|
|
||
| export interface PrerenderOptions { | ||
| ssr: true; | ||
| url: string; | ||
| route: PrerenderedRoute; | ||
| } | ||
|
|
||
| export interface PrerenderResult { | ||
| html?: string; | ||
| head?: Partial<Head>; | ||
| links?: Set<string>; | ||
| /** | ||
| * @description Caution: should be a valid JSON object | ||
| */ | ||
| data?: any; | ||
| } | ||
|
Comment on lines
+24
to
+32
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
There was a problem hiding this comment.
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