diff --git a/CHANGELOG.md b/CHANGELOG.md index 970ddb7f0f..b32d47c791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added - [#4203](https://github.com/plotly/dash/pull/4203) Add a Copy button to each error in the debug toolbar, which copies the error message and its traceback to the clipboard. Closes [#3624](https://github.com/plotly/dash/issues/3624). - [#4204](https://github.com/plotly/dash/pull/4204) Add `DASH_HOST` and `DASH_PORT` environment variables to set the listen address for `Dash.run`, taking precedence over the generic `HOST` and `PORT` variables. Fixes [#3400](https://github.com/plotly/dash/issues/3400). +- Add the `loading` prop to `html.Img` and `html.Iframe`, so `loading="lazy"` turns on the browser's lazy loading. Fixes [#2423](https://github.com/plotly/dash/issues/2423). ### Changed - [#4118](https://github.com/plotly/dash/pull/4118) The JupyterLab extension now ships prebuilt, so JupyterLab 3 and 4 load it without asking for a rebuild. JupyterLab 2 is no longer supported. Fixes [#3828](https://github.com/plotly/dash/issues/3828). diff --git a/components/dash-html-components/scripts/data/attributes.json b/components/dash-html-components/scripts/data/attributes.json index 4621b06f19..983cb5a4c1 100644 --- a/components/dash-html-components/scripts/data/attributes.json +++ b/components/dash-html-components/scripts/data/attributes.json @@ -361,6 +361,13 @@ ], "description": "Defines the language used in the element." }, + "loading": { + "elements": [ + "img", + "iframe" + ], + "description": "Indicates if the element should be loaded lazily (loading=\"lazy\") or loaded immediately (loading=\"eager\")." + }, "list": { "elements": [ "input" @@ -856,6 +863,7 @@ "iframe": [ "allow", "height", + "loading", "name", "referrerPolicy", "sandbox", @@ -878,6 +886,7 @@ "alt", "crossOrigin", "height", + "loading", "referrerPolicy", "sizes", "src", diff --git a/components/dash-html-components/scripts/extract-attributes.js b/components/dash-html-components/scripts/extract-attributes.js index 26759db550..c7ada25d33 100644 --- a/components/dash-html-components/scripts/extract-attributes.js +++ b/components/dash-html-components/scripts/extract-attributes.js @@ -20,7 +20,7 @@ const supportedAttributes = ['accept', 'accessKey', 'action', 'allow', 'encType', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget', 'frameBorder', 'headers', 'height', 'hidden', 'high', 'href', 'hrefLang', 'icon', 'id', 'inputMode', 'integrity', 'is', -'keyParams', 'keyType', 'kind', 'label', 'lang', 'list', 'loop', 'low', +'keyParams', 'keyType', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'manifest', 'marginHeight', 'marginWidth', 'max', 'maxLength', 'media', 'mediaGroup', 'method', 'min', 'minLength', 'multiple', 'muted', 'name', 'noValidate', 'nonce', 'open', 'optimum', 'pattern', 'placeholder', 'playsInline', 'poster', diff --git a/components/dash-html-components/tests/test_dash_html_components.py b/components/dash-html-components/tests/test_dash_html_components.py index 206f4fb3e8..f73e902fe0 100644 --- a/components/dash-html-components/tests/test_dash_html_components.py +++ b/components/dash-html-components/tests/test_dash_html_components.py @@ -47,3 +47,8 @@ def test_customDocs(): assert "CAUTION" in html.Script.__doc__[:100] assert "OBSOLETE" in html.Blink.__doc__[:100] assert "DEPRECATED" in html.Marquee.__doc__[:100] + + +def test_loading_attribute(): + assert repr(html.Img(loading="lazy")) == "Img(loading='lazy')" + assert repr(html.Iframe(loading="lazy")) == "Iframe(loading='lazy')" diff --git a/components/dash-html-components/tests/test_integration.py b/components/dash-html-components/tests/test_integration.py index d0551d6e90..c6b75b990f 100644 --- a/components/dash-html-components/tests/test_integration.py +++ b/components/dash-html-components/tests/test_integration.py @@ -141,3 +141,19 @@ def update(n2, n3, n4): dash_duo.wait_for_text_to_equal("#div-output", "1, 0, 1") assert not dash_duo.get_logs() + + +def test_loading_attribute(dash_duo): + app = Dash(__name__) + app.layout = html.Div( + [ + html.Img(id="img", loading="lazy"), + html.Iframe(id="iframe", loading="eager"), + ] + ) + + dash_duo.start_server(app) + + assert dash_duo.find_element("#img").get_attribute("loading") == "lazy" + assert dash_duo.find_element("#iframe").get_attribute("loading") == "eager" + assert not dash_duo.get_logs()