In SSR projects like NextJS, the Porsche Design System components are getting rendered on the server using native web
platform API called Declarative Shadow DOM (DSR). The
browser support is already good but still limited.
Therefore, we provide a partial in @porsche-design-system/components-react package based on
@webcomponents/template-shadowroot which needs to be
injected before the closing </body> of your index.html.
OptionDescriptionTypeDefaultformatDefines the output format of the partial. By default, it returns a html string. For jsx it returns a jsx element. For sha256 it returns a SHA-256 hash of the innerHTML to use in a Content Security Policy (CSP).'html' | 'jsx' | 'sha256''html'
When using jsx in the format option, it is necessary to have react/jsx-runtime as a dependency in the project
included.
Project integration differs based on the project setup.
The following showcases the most common ways.
prev
next
<!-- index.html -->
<body><!--PLACEHOLDER_DSR_PONYFILL--></body>
<!-- package.json (tested on macOS, the script may need to be adjusted depending on the operating system used) -->
<!-- make sure to adjust the path to the index.html file -->
"scripts": {
"prestart": "yarn replace",
"replace": "placeholder='<!--PLACEHOLDER_DSR_PONYFILL-->' && partial=$placeholder$(node -e 'console.log(require(\"@porsche-design-system/components-js/partials\").getDSRPonyfill())') && regex=$placeholder'.*' && sed -i '' -E -e \"s^$regex^$partial^\" index.html"}