Skip to content

Commit

Permalink
Disable prerender when streamingSsr is enabled (#8775)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 1, 2023
1 parent f9912af commit e7d5361
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/cli/src/commands/prerenderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Listr } from 'listr2'
import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
import { runPrerender, writePrerenderedHtmlFile } from '@redwoodjs/prerender'
import { detectPrerenderRoutes } from '@redwoodjs/prerender/detection'
import { getPaths } from '@redwoodjs/project-config'
import { getConfig, getPaths } from '@redwoodjs/project-config'
import { errorTelemetry } from '@redwoodjs/telemetry'

import c from '../lib/colors'
Expand Down Expand Up @@ -275,6 +275,16 @@ const diagnosticCheck = () => {
}

export const handler = async ({ path: routerPath, dryRun, verbose }) => {
if (getConfig().experimental?.streamingSsr?.enabled) {
console.log(
c.warning(
'Prerendering is not yet supported with Streaming SSR. Skipping prerender...'
)
)

return
}

recordTelemetryAttributes({
command: 'prerender',
dryRun,
Expand Down
5 changes: 5 additions & 0 deletions packages/router/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ declare global {
**/
var RWJS_API_URL: string

/**
* Is the experimental Streaming/SSR feature enabled?
*/
var RWJS_EXP_STREAMING_SSR: boolean

namespace NodeJS {
interface Global {
/**
Expand Down
7 changes: 6 additions & 1 deletion packages/router/src/active-route-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface Props {

let isPrerendered = false

// TODO (STREAMING)
// SSR and streaming changes how we mount the React app (we render the whole page, including head and body)
// This logic is no longer valid and needs to be rethought
if (typeof window !== 'undefined') {
const redwoodAppElement = document.getElementById('redwood-app')

Expand Down Expand Up @@ -48,7 +51,9 @@ export const ActiveRouteLoader = ({
const announcementRef = useRef<HTMLDivElement>(null)

const usePrerenderLoader =
globalThis.__REDWOOD__PRERENDERING || (isPrerendered && firstLoad)
// Prerendering doesn't work with Streaming/SSR yet. So we disable it.
!globalThis.RWJS_EXP_STREAMING_SSR &&
(globalThis.__REDWOOD__PRERENDERING || (isPrerendered && firstLoad))

const LazyRouteComponent = usePrerenderLoader
? spec.prerenderLoader(spec.name).default
Expand Down

0 comments on commit e7d5361

Please sign in to comment.