-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable HDS server side rendering support
In practice this fixes the issue where a huge HKI logo flashes briefly when a user navigates to the site. The implementation is pretty much directly copy-pasted from https://github.com/City-of-Helsinki/linkedregistrations-ui/blob/ 7542320c8e2df6349799a1404fecca4a809519ae/src/pages/_document.tsx
- Loading branch information
Showing
5 changed files
with
43 additions
and
0 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 @@ | ||
export { Document as default } from 'events-helsinki-components'; |
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 @@ | ||
export { Document as default } from 'events-helsinki-components'; |
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 @@ | ||
export { Document as default } from 'events-helsinki-components'; |
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,39 @@ | ||
import * as hds from 'hds-react'; | ||
import { getCriticalHdsRules } from 'hds-react'; | ||
import NextJsDocument, { Html, Head, Main, NextScript } from 'next/document'; | ||
import type { DocumentContext, DocumentProps } from 'next/document'; | ||
|
||
type Props = { | ||
hdsCriticalRules: string; | ||
} & DocumentProps; | ||
|
||
class Document extends NextJsDocument<Props> { | ||
static async getInitialProps(ctx: DocumentContext) { | ||
const initialProps = await NextJsDocument.getInitialProps(ctx); | ||
const hdsCriticalRules = await getCriticalHdsRules( | ||
initialProps.html, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(hds as any).hdsStyles | ||
); | ||
|
||
return { ...initialProps, hdsCriticalRules }; | ||
} | ||
|
||
render() { | ||
return ( | ||
<Html> | ||
<Head> | ||
<style | ||
data-used-styles | ||
dangerouslySetInnerHTML={{ __html: this.props.hdsCriticalRules }} | ||
/> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
} | ||
} | ||
export default Document; |
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