-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
88 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@quilted/preact-browser': patch | ||
'@quilted/quilt': patch | ||
--- | ||
|
||
Add more server rendering hooks |
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,5 +1,10 @@ | ||
import {createOptionalContext} from '@quilted/preact-context'; | ||
import type {BrowserDetails} from '@quilted/browser'; | ||
import type {BrowserAssets} from '@quilted/assets'; | ||
|
||
export const BrowserDetailsContext = createOptionalContext<BrowserDetails>(); | ||
export const useBrowserDetails = BrowserDetailsContext.use; | ||
|
||
export const BrowserAssetsManifestContext = | ||
createOptionalContext<BrowserAssets>(); | ||
export const useBrowserAssetsManifest = BrowserAssetsManifestContext.use; |
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
29 changes: 29 additions & 0 deletions
29
packages/preact-browser/source/server/hooks/browser-response.ts
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,29 @@ | ||
import {BrowserResponse} from '@quilted/browser/server'; | ||
|
||
import {useBrowserDetails} from '../../context.ts'; | ||
|
||
/** | ||
* Returns the mutable browser response object. This hook can only be called on the | ||
* server, and only when a `BrowserResponse` is found in the context. This object gives | ||
* you access to details about the original request, and the ability to read and write | ||
* headers and head tags to the eventual response. | ||
* | ||
* When using the `renderToHTMLResponse()` or `renderToHTMLString()` functions, this context | ||
* is automatically provided for you. If you are using Preact’s server rendering functions | ||
* directly, you will need to provide a `BrowserResponse` object yourself. | ||
*/ | ||
export function useBrowserResponse() { | ||
const response = useBrowserDetails(); | ||
|
||
if (typeof document === 'object') { | ||
throw new Error( | ||
`You can only call the useBrowserResponse() hook in server-side code.`, | ||
); | ||
} | ||
|
||
if (!(response instanceof BrowserResponse)) { | ||
throw new Error(`No BrowserResponse found in context.`); | ||
} | ||
|
||
return response; | ||
} |
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