forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(streaming-ssr): Fix build and server html injection (redwoodjs#8978
) - Fixes cases where route hooks not firing correctly when root Route hook missing - Fixes build erroring out when pages are explicitly imported - Ensures webdir for build too - Adds new way to inject html to `<head>` for Apollo client - Makes the `<MetaTags>` component partially work with the new streaming setup. Helmet doesn't work with streaming (their docs are for the old way of streaming). - Right now it doesn't support "templates" like Helmet does (neither do route hooks) Note: I haven't applied HTML injection to prod just yet. --------- Co-authored-by: Dominic Saadi, Kris Coulson
- Loading branch information
Showing
19 changed files
with
447 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
/* eslint-disable no-var */ | ||
/// <reference types="react/canary" /> | ||
import type { HelmetServerState } from 'react-helmet-async' | ||
|
||
declare global { | ||
// Provided by Vite.config, or Webpack in the user's project | ||
// but "regsitered" in packages/vite/src/streaming/registerGlobals.ts | ||
// for it to be available to framework code | ||
var RWJS_ENV: { | ||
RWJS_API_GRAPHQL_URL?: string | ||
RWJS_API_GRAPHQL_URL: string | ||
/** URL or absolute path to serverless functions */ | ||
RWJS_API_URL?: string | ||
RWJS_API_URL: string | ||
RWJS_EXP_STREAMING_SSR: boolean | ||
RWJS_EXP_RSC: boolean | ||
|
||
__REDWOOD__APP_TITLE?: string | ||
__REDWOOD__APP_TITLE: string | ||
} | ||
|
||
var RWJS_DEBUG_ENV: { | ||
RWJS_SRC_ROOT: string | ||
REDWOOD_ENV_EDITOR: string | ||
} | ||
|
||
var __REDWOOD__PRERENDER_PAGES: any | ||
|
||
var __REDWOOD__HELMET_CONTEXT: { helmet?: HelmetServerState } | ||
} | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import path from 'node:path' | ||
|
||
import { getConfig, getPaths } from '@redwoodjs/project-config' | ||
|
||
/** | ||
* Use this function on the web server | ||
* | ||
* Because although this is defined in Vite/index.ts | ||
* They are only available in the user's code (and not in FW code) | ||
* because define STATICALLY replaces it in user's code, not in node_modules | ||
* | ||
* It's still available on the client side though, probably because its processed by Vite | ||
*/ | ||
export const registerFwGlobals = () => { | ||
const rwConfig = getConfig() | ||
const rwPaths = getPaths() | ||
|
||
globalThis.RWJS_ENV = { | ||
// @NOTE we're avoiding process.env here, unlike webpack | ||
RWJS_API_GRAPHQL_URL: | ||
rwConfig.web.apiGraphQLUrl ?? rwConfig.web.apiUrl + '/graphql', | ||
RWJS_API_URL: rwConfig.web.apiUrl, | ||
__REDWOOD__APP_TITLE: rwConfig.web.title || path.basename(rwPaths.base), | ||
RWJS_EXP_STREAMING_SSR: | ||
rwConfig.experimental.streamingSsr && | ||
rwConfig.experimental.streamingSsr.enabled, | ||
RWJS_EXP_RSC: rwConfig.experimental?.rsc?.enabled, | ||
} | ||
|
||
globalThis.RWJS_DEBUG_ENV = { | ||
RWJS_SRC_ROOT: rwPaths.web.src, | ||
REDWOOD_ENV_EDITOR: JSON.stringify(process.env.REDWOOD_ENV_EDITOR), | ||
} | ||
} |
Oops, something went wrong.