Skip to content
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

Mark route as "ssr only" #2722

Closed
tomyan opened this issue Nov 2, 2021 · 3 comments
Closed

Mark route as "ssr only" #2722

tomyan opened this issue Nov 2, 2021 · 3 comments
Labels

Comments

@tomyan
Copy link

tomyan commented Nov 2, 2021

Describe the problem

It's currently possible to ensure that a route is server rendered by adding the rel="external" attribute to any links to it. It would be convenient to configure this once in the page that should always be server rendered. A use-case for this is a page that needs to set a cookie (e.g. once #909 is implemented). In my case I have a /login route that does this (sets a cookie and redirects to an OpenID Connect provider). At the moment I implement this as an endpoint, but this isn't ideal as if something goes wrong it would be difficult to ditch the redirect and render a page that explains the error to the user.

Describe the proposed solution

I'm not too sure how it would be implemented (happy to help if I can, but I think #909 might be more tractable for a beginner like me). There's another problem I've come across that endpoints are not server rendered by default (I've also used rel="external" to work around this issue - seems like the solution to this would be similar.

Alternatives considered

I can use an endpoint to work around this limitation (or perhaps hooks) but it won't handle errors as well (or be as convenient).

Importance

would make my life easier

Additional Information

No response

@rmunn
Copy link
Contributor

rmunn commented Nov 2, 2021

At the moment I implement this as an endpoint, but this isn't ideal as if something goes wrong it would be difficult to ditch the redirect and render a page that explains the error to the user.

One thing you might be able to do right now, without waiting for a new feature to be implemented, would be to have your /login endpoint redirect to one of two places:

  • Success: redirect to OpenID Connect provider
  • Failure: redirect to /login-error?errorCode=what-went-wrong

And then your /login-error route is a page, not an endpoint. It would use the load function to take the error code from the query, look up an appropriate human-readable error (or if you have your site translated into multiple languages, the appropriate translation for that error message), and render a nice explanation of the error.

Alternately, so as to not have a different error page for everything, redirect to /error-page?errorFrom=/login&errorCode=what-went-wrong, and then the error-page might look at errorFrom and decide which layout component to load to render the error text, so that the layout of the error looks similar to the layout of the page you came from. Whether that's a better alternative kind of depends on your site and how it's designed.

@benmccann
Copy link
Member

We might be able to solve this with routing hooks when we implement those (#552)

@Rich-Harris
Copy link
Member

#909 isn't going to be implemented. Now that we have page endpoints, I think the set-cookie case is easy enough to implement (with redirect/error handling 'for free') that I reckon we can probably close this issue, unless there are other use cases for SSR-only pages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants