Server Side Rendering #33219
Replies: 10 comments 16 replies
-
Would it be possible to do redirects inside |
Beta Was this translation helpful? Give feedback.
-
One thing I'm really interested on SSR is if we will have support for fallback pages like we do in Next.JS. This is important for my use case where I have an API that is really slow for fetching data and, according to my tests, it's better to SSR only the fast part on the server and leave the rest to the client. I know that React 18 will have similar features and I wonder it better waiting for React 18 to come out. Also, one thing I'm concerned is returning Thanks! |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to access the GraphQL data from SSR? |
Beta Was this translation helpful? Give feedback.
-
Moving this from twitter: https://twitter.com/moon_meister/status/1456709799907893251 How does one return an error from https://www.gatsbyjs.com/docs/how-to/rendering-options/using-server-side-rendering/ Suggests: ...
} catch (error) {
return {
headers: {
status: 500,
},
props: {}
}
}
} but that does nothing in https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/ doesn't even use a try/catch block suggesting that just throwing an exception will trigger the 500. That's reasonable...but what if I want to throw a 401 or anything other than a 200/500 code? |
Beta Was this translation helpful? Give feedback.
-
What's the thought behind using the |
Beta Was this translation helpful? Give feedback.
-
Is it possible to access data queried by the page-query in the |
Beta Was this translation helpful? Give feedback.
-
In Next.js, we have the ability to These are extremely helpful tools, and while Gatsby SSR is missing these options, I figured that I could accomplish the same thing by using the return {
status: 301,
headers: {
Location: '/new-path'
}
} Unfortunately, this didn't work as expected. Gatsby still attempted to render my page and failed because I didn't pass any props. For the export async function getServerData({params}) {
const thing = await fetchThing({id: params.id});
if (!thing) {
return {status: 404};
}
return {
props: {thing}
}
} In both of these cases (redirect and 404), the page is still attempted to be rendered. Is there any workaround for this? How can I signal to Gatsby that I want to perform a redirect on the server side, or indicate the current page as "not found"? |
Beta Was this translation helpful? Give feedback.
-
Does SSR work when using Styled Components in Gatsby v4? I have a React/Styled Components based design system based I used originally on my primary Gatsby website and have since used to spin up a new Gatsby based micro-site. Both websites are setup using SSR per the instructions given at their respective times, but the new microsite is experiencing FOUC (flash of unstyled content). More specifically the new site doesn't seem to add styles for components from the design system to the HTML when statically built. However, SSR works for any components I create directly in the new project. I'd appreciate tips, ideas, or pointers generally in the right direction. Old site (no FOUC): ...
"dependencies": {
"gatsby": "^2.28.0",
"babel-plugin-styled-components": "^1.12.0",
"gatsby-plugin-styled-components": "^3.6.0",
"styled-components": "^4.4.1",
... New site (FOUC for design system components): ...
"dependencies": {
"gatsby": "^4.3.0",
"babel-plugin-styled-components": "^2.0.2",
"gatsby-plugin-styled-components": "^5.3.0",
"styled-components": "^5.3.3",
... |
Beta Was this translation helpful? Give feedback.
-
it's possible to host a Gatsby site with SSR pages on IIS? |
Beta Was this translation helpful? Give feedback.
-
Disable/enable (ignore) SSR for specific environments Hi folks. I hope I didn't overlook a similar discussion. First of all: SSR made my day. Thank you for implementing this very important feature! Now, we want to deploy the entire Gatsby app in two different environments. One with SSR (for preview purposes) and one without SSR (SSG for end customers only). The documentation says "When a page component exports getServerData function, Gatsby treats all pages built with this component as server-rendered." In case of existing getServerData component or not, it would be nice to ignore getServerData via an IGNORE_SSR configuration flag. Currently we use two instances of a page component (with and without getServerData) for each environment. Does anyone have similar requirements or any other ideas how to solve this in a nice way? |
Beta Was this translation helpful? Give feedback.
-
SSG, DSG, and client-side rendering can handle a vast majority of use cases in web development. But there is a small niche when you may still need to generate HTML on-the-fly. That’s when you’ll need Server-Side Rendering.
Server-Side Rendering is a method of content rendering in which each web page is served to a site visitor at runtime, meaning that a portion of the build process happens on each page request. Because the content is rendering during runtime, visitors will always get the latest version of content directly from the server—though they may have to wait a few seconds for it display.
As this is a new feature available in Gatsby 4, we're eager to hear about your experiences and use cases where you apply SSR in your Gatsby projects. Please share your questions and findings below!
Read all about SSR in Gatsby here
Thank you for building with Gatsby! 💜
Beta Was this translation helpful? Give feedback.
All reactions