Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure favicon is displayed on Preview links #385

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading