question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better typing for `renderPage`?

See original GitHub issue

First of all, thank you for this awesome lib (and really useful documentation)!

I was playing around with createPageRenderer (I’m using Typescript + Vercel + SolidJS) like so:

const renderPage = createPageRenderer(...);
...
const pageContext = await renderPage(pageContextInit);

Here, my pageContext should have custom fields that could be returned (like redirectTo as in your examples, or cookies, that is responsible to set Cookies on headers).

So I checked the renderPage typings:

image

Good, there is a PageContextAdded type that I can use:

const pageContext = await renderPage<MyCustomType, typeof pageContextInit>(pageContextInit);

This should have been enough I guess, but the right typing is not quite right IMO:

PageContextInit & (({ httpResponse: HttpResponse } & PageContextAdded) | { httpResponse: null })

Looking closer, PageContextAdded is added to the return type only if httpResponse is of type HttpResponse, which in both of my use cases (redirect and cookies) is not necessarily the case.

Perhaps I’m doing this wrong? But if not, here is the typing I propose:

PageContextInit & { httpResponse: HttpResponse | null } & PageContextAdded
// or with Partial but it could mess some type definitions
PageContextInit & { httpResponse: HttpResponse | null } & Partial<PageContextAdded>
// see https://www.typescriptlang.org/play?#code/C4TwDgpgBACghgcwgYQPYDtgQB7AIIAmBEBUAvFAN4BQUUcAXFOgK4C2ARhAE4A0tUDk1ace-AL5QAPlSgBjYey7co4gNzVqoSFAAa5WHG7AAlnAA2AHnhI0mHPiIkAfBupyMAZ2BRsTfRSU9EwAjLyCTABMqhoe6N5QIEw2KBhYuITEpIHBUGERUNHqmiYAZlAAFNgAdHAAlFQCdAD0zVAAogBKnQDynU3yXj5CzEo8BjUcGuIl5RUgtQ00dC1tAHKoUDzcqCpwnlvYkHJYBANxCSMiygYLU9TiQA

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Oct 30, 2021

Released in v0.3.20.

1reaction
brilloutcommented, Oct 29, 2021

The best would be https://github.com/brillout/vite-plugin-ssr/issues/176 so that all types are automatically stiched together for the user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What to use instead of WebViewPage.RenderPage method in ...
I've always had success using @Html.Partial("~/Views/Shared/_ImportCssInline.cshtml") rather than @RenderPage - I hope there's not usage ...
Read more >
Advanced Features: Custom `Document` - Next.js
Learn more about incrementally adopting app/ . A custom Document can update the <html> ... renderPage // Run the React rendering logic synchronously...
Read more >
MVC RenderPage to process aspx page? - Or is there a better ...
What I want to do is call the view, and have the view render the webpage, but I get the following error: An...
Read more >
renderPage() - vite-plugin-ssr
(The Content-Type is application/json when Client Routing fetches the pageContext of the newly navigated page.) pageContext.httpResponse.body is the HTML string ...
Read more >
PageRender::renderPage() method - ProcessWire API
This type of hook is especially useful for modifying arguments before they are sent to the method. $this->addHookBefore('PageRender::renderPage', function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found