Skip to content

Commit

Permalink
Ensure favicon is displayed on Preview links
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib committed Jan 3, 2025
1 parent 6095dc4 commit 9125d5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-pets-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Ensure favicon is displayed on Preview links.
1 change: 1 addition & 0 deletions lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['preview'],
filename: 'preview/index.html',
favicon: path.join(__dirname, '../images/favicon.png'),
publicPath: '../',
}),
new VanillaExtractPlugin({
Expand Down
13 changes: 13 additions & 0 deletions src/preview.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { renderElement } from './render';
import Preview from './Playroom/Preview';
import faviconPath from '../images/favicon.png';
import faviconInvertedPath from '../images/favicon-inverted.png';

const outlet = document.createElement('div');
document.body.appendChild(outlet);

const selectedElement = document.head.querySelector('link[rel="icon"]');
const favicon = window.matchMedia('(prefers-color-scheme: dark)').matches
? faviconInvertedPath
: faviconPath;

const formattedFavicon = `../${favicon}`;

if (selectedElement) {
selectedElement.setAttribute('href', formattedFavicon);
}

const renderPreview = ({
themes = require('./themes'),
components = require('./components'),
Expand Down

0 comments on commit 9125d5a

Please sign in to comment.