Skip to content

Fix #1767: Allow custom favicon.png by renaming defaults and adding o…#2799

Open
arryansh5 wants to merge 5 commits into
Avaiga:developfrom
arryansh5:bug/#1767-favicon-not-displayed
Open

Fix #1767: Allow custom favicon.png by renaming defaults and adding o…#2799
arryansh5 wants to merge 5 commits into
Avaiga:developfrom
arryansh5:bug/#1767-favicon-not-displayed

Conversation

@arryansh5

Copy link
Copy Markdown

Fixes #1767

Summary

Resolves the issue where custom favicons named favicon.png or favicon.ico were not displayed due to naming conflicts with bundled default favicons. Implements a dual-approach solution that renames default favicons and adds override detection for standard favicon filenames.

Changes

  • Renamed frontend/taipy-gui/public/favicon.pngtaipy-favicon.png
  • Renamed frontend/taipy-gui/public/favicon.icotaipy-favicon.ico
  • Updated frontend/taipy-gui/public/index.html to reference taipy-favicon.png
  • Updated taipy/gui/webapp/index.html to reference taipy-favicon.png
  • Modified taipy/gui/gui.py - Changed _DEFAULT_FAVICON_URL constant to use taipy-favicon.png
  • Modified taipy/gui/servers/flask/server.py - Added override detection logic in my_index() route handler to intercept favicon.png and favicon.ico requests

Problem Solved

When users specified run(favicon="favicon.png"), the Flask server always served the bundled default favicon from the webapp folder instead of the user's custom file. This occurred because:

  1. Flask's route handler checked static files in webapp/ first
  2. Both default and custom favicons had the same filename (favicon.png)
  3. The static file route took precedence over custom content routes

This implementation uses two complementary solutions:

  • Solution 2 (Rename Defaults): Eliminates the root naming conflict by renaming bundled favicons to taipy-favicon.png/ico
  • Solution 4 (Override Detection): Adds request interception for standard favicon names, checking if a custom favicon exists and serving it via the content accessor route instead of the static file

Users can now use standard favicon filenames without any issues:

Gui(page).run(favicon="favicon.png")  # ✅ Now works correctly

…ding override detection

Problem: Custom favicon named 'favicon.png' was not displayed due to naming conflict with bundled default favicon.

Solution: Implemented two complementary fixes:

1. Renamed default favicons from favicon.png/ico to taipy-favicon.png/ico

2. Added override detection in Flask server to prioritize custom favicon.png

Changes:

- Renamed frontend/taipy-gui/public/favicon.* to taipy-favicon.*

- Updated HTML templates to reference renamed default favicons

- Updated _DEFAULT_FAVICON_URL constant in gui.py

- Added override logic in server.py to intercept favicon.png/ico requests

- Custom favicons with standard names now take priority over defaults

Result: Users can now use favicon='favicon.png' successfully

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #1767 where custom favicons named favicon.png or favicon.ico were not displayed due to naming conflicts with bundled default favicons. The solution implements a dual approach: renaming the default favicon files and adding override detection logic to intercept standard favicon requests.

Changes:

  • Renamed bundled default favicons from favicon.png/ico to taipy-favicon.png/ico to eliminate naming conflicts
  • Added override detection in the Flask route handler to intercept requests for favicon.png and favicon.ico when custom favicons are configured
  • Updated all references to point to the renamed default favicon files

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
taipy/gui/servers/flask/server.py Added override detection logic in my_index() route handler to intercept favicon requests and serve custom files via content accessor when configured
taipy/gui/gui.py Updated _DEFAULT_FAVICON_URL constant to reference the renamed taipy-favicon.png file in the external assets repository
frontend/taipy-gui/public/index.html Updated favicon link references from favicon.png to taipy-favicon.png
frontend/taipy-gui/public/taipy-favicon.png Renamed default PNG favicon file (from favicon.png)
frontend/taipy-gui/public/taipy-favicon.ico Renamed default ICO favicon file (from favicon.ico)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread taipy/gui/gui.py Outdated
__DOWNLOAD_ACTION = "__Taipy__download_csv"
__DOWNLOAD_DELETE_ACTION = "__Taipy__download_delete_csv"
_DEFAULT_FAVICON_URL = "https://raw.githubusercontent.com/Avaiga/taipy-assets/develop/favicon.png"
_DEFAULT_FAVICON_URL = "https://raw.githubusercontent.com/Avaiga/taipy-assets/develop/taipy-favicon.png"

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The external default favicon URL has been updated to point to "taipy-favicon.png" in the taipy-assets repository. Please verify that this file exists at the specified URL (https://raw.githubusercontent.com/Avaiga/taipy-assets/develop/taipy-favicon.png) to ensure the fallback default favicon works correctly when no custom favicon is specified.

Copilot uses AI. Check for mistakes.
Comment thread taipy/gui/servers/flask/server.py Outdated
if custom_page_resource is not None:
return custom_page_resource

# Solution 4: Override detection for custom favicon

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Solution 4: Override detection for custom favicon" references an implementation approach number that may not be meaningful to future maintainers. Consider updating to a more descriptive comment like "Override default favicon with custom favicon if configured".

Suggested change
# Solution 4: Override detection for custom favicon
# Override default favicon with custom favicon if configured

Copilot uses AI. Check for mistakes.
Comment thread taipy/gui/servers/flask/server.py Outdated
Comment on lines +167 to +168
parts = path.split("/")
file_name = parts[-1]

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable: file_name is assigned but never used. These lines should be removed.

Suggested change
parts = path.split("/")
file_name = parts[-1]

Copilot uses AI. Check for mistakes.
Comment thread taipy/gui/servers/flask/server.py Outdated
Comment on lines +162 to +164
from pathlib import Path
# Check if custom favicon filename matches the requested path
custom_path = Path(custom_favicon)

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary import: The pathlib module is already imported at the top of the file (line 17). Instead of importing Path from pathlib here, use pathlib.Path directly to avoid redundant imports.

Suggested change
from pathlib import Path
# Check if custom favicon filename matches the requested path
custom_path = Path(custom_favicon)
# Check if custom favicon filename matches the requested path
custom_path = pathlib.Path(custom_favicon)

Copilot uses AI. Check for mistakes.
Comment thread taipy/gui/servers/flask/server.py Outdated
Comment on lines +158 to +174
# Solution 4: Override detection for custom favicon
if path in ["favicon.png", "favicon.ico"]:
custom_favicon = self._gui._get_config("favicon") # type: ignore[attr-defined]
if custom_favicon:
from pathlib import Path
# Check if custom favicon filename matches the requested path
custom_path = Path(custom_favicon)
if custom_path.name == path:
# Serve custom favicon via content accessor
parts = path.split("/")
file_name = parts[-1]
# Get the mapped URL from content accessor
url = self._gui._get_content("__taipy_favicon", custom_favicon, True) # type: ignore[attr-defined]
# Extract the path after _CONTENT_ROOT
if isinstance(url, str) and url.startswith(f"/{self._gui._CONTENT_ROOT}/"): # type: ignore[attr-defined]
content_path = url[len(f"/{self._gui._CONTENT_ROOT}/"):] # type: ignore[attr-defined]
return self._gui._serve_content(content_path) # type: ignore[attr-defined]

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage: The new override detection logic for custom favicons in the my_index route handler is not covered by tests. Consider adding tests that verify:

  1. A custom favicon with the name "favicon.png" is correctly served instead of the default
  2. A custom favicon with the name "favicon.ico" is correctly served instead of the default
  3. When no custom favicon is configured, the default favicon files are served correctly

Copilot uses AI. Check for mistakes.
- Updated comment for better clarity

- Removed unused variables (parts, file_name)

- Fixed redundant pathlib.Path import
The taipy-assets repo still uses 'favicon.png' not 'taipy-favicon.png'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if custom favicon is set to taipy-favicon.png ?

@FredLL-Avaiga FredLL-Avaiga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix the linter issues ?
What if custom favicon is set to taipy-favicon.png ?

@arryansh5

Copy link
Copy Markdown
Author

can you fix the linter issues ? What if custom favicon is set to taipy-favicon.png ?

Okay I will fix it

@jrobinAV

jrobinAV commented Mar 9, 2026

Copy link
Copy Markdown
Member

Hello @arryansh5,

We appreciate your help.

You have been automatically unassigned, but if you are still working on that issue, I can re-assign it to you without any trouble.

Just tell me, please.

Thx,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 BUG] Favicon not being displayed using run(favicon="favicon.png")

4 participants