Skip to content

Fixed viewport meta-tags #2084

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

Merged
merged 3 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## Unreleased

### Fixed
- [#2084](https://github.com/plotly/dash/pull/2084) In dash 2.5.0, a default viewport meta tag was added as recommended for mobile-optimized sites by [mdn](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag)
This feature can be disabled by providing an empty viewport meta tag. e.g. `app = Dash(meta_tags=[{"name": "viewport"}])`

## [2.5.0] - 2022-06-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def _generate_meta_html(self):
x.get("http-equiv", "") == "X-UA-Compatible" for x in meta_tags
)
has_charset = any("charset" in x for x in meta_tags)
has_viewport = any("viewport" in x for x in meta_tags)
has_viewport = any(x.get("name") == "viewport" for x in meta_tags)

tags = []
if not has_ie_compat:
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ def test_inin007_meta_tags(dash_duo):
assert meta_tag.get_attribute("content") == meta_info["content"]


def test_inin007b_change_viewport_meta_tag(dash_duo):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather we not squeeze test numbers in between with b or such - makes it harder to run just one test with eg pytest -k inin007. Just shift some of the other test numbers so this one can have its own. Maybe the ones up front since this file starts at inin004?

"""
As of dash 2.5 the default viewport meta tag is:
[{"name": "viewport", "content": "width=device-width, initial-scale=1"}]
Test verifies that this feature can be disabled by using an empty viewport tag.
"""

app = Dash(meta_tags=[{"name": "viewport"}])

app.layout = html.Div(id="content")

dash_duo.start_server(app)

meta = dash_duo.find_elements("meta")

# -3 for the meta charset, http-equiv and viewport.
assert len(meta) == 3, "Should have 3 meta tags"

viewport_meta = meta[2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better not to depend on the order of the returned meta elements. Also if we add more default meta tags in the future this test would need to change. Instead, find just the viewport tags and ensure there's exactly one:

meta = dash_duo.find_elements('meta[name="viewport"]')

assert viewport_meta.get_attribute("name") == "viewport"
assert viewport_meta.get_attribute("content") == ""


def test_inin008_index_customization(dash_duo):
app = Dash()

Expand Down