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

Iframe reloads every time update is called #3

Open
rl-king opened this issue Feb 24, 2019 · 1 comment
Open

Iframe reloads every time update is called #3

rl-king opened this issue Feb 24, 2019 · 1 comment

Comments

@rl-king
Copy link

rl-king commented Feb 24, 2019

This surprised me

If you render html containing an iframe it reloads the content every time you call update. This results in the iframe data being reloaded.

Currently working solution

Use lazy

Might be nice

A note in the docs on how why you might need to use lazy in combination with the toHtml functions

SSCCE

Problematic, keyed but not lazy

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Html.Keyed as Keyed
import Markdown exposing (defaultOptions)


main : Program () () Msg
main =
    Browser.sandbox
        { init = ()
        , view = view
        , update = \_ _ -> ()
        }


type Msg
    = Foo


view : () -> Html Msg
view _ =
    div []
        [ button [ onClick Foo ] [ text "click" ]
        , Keyed.node "div"
            []
            [ ( "foo"
              , Markdown.toHtmlWith { defaultOptions | sanitize = False }
                    []
                    iframeString
              )
            ]
        ]


iframeString : String
iframeString =
    """<iframe width="560" height="315" 
    src="https://www.youtube-nocookie.com/embed/o_4EX4dPppA" 
    frameborder="0" allow="accelerometer; autoplay; encrypted-media; 
    gyroscope; picture-in-picture" allowfullscreen></iframe>"""

https://ellie-app.com/4Pj7WpKzTHKa1

Possible solution, lazy

provided by @zwilias

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Html.Lazy as Lazy
import Markdown exposing (defaultOptions)


main : Program () () Msg
main =
    Browser.sandbox
        { init = ()
        , view = view
        , update = \_ _ -> ()
        }


type Msg
    = Foo


view : () -> Html Msg
view _ =
    div []
        [ button [ onClick Foo ] [ text "click" ]
        , Lazy.lazy markdown iframeString
        ]

markdown : String -> Html msg
markdown content =
    Markdown.toHtmlWith
            { defaultOptions | sanitize = False }
            []
            content


iframeString : String
iframeString =
    """<iframe width="560" height="315" 
    src="https://www.youtube-nocookie.com/embed/o_4EX4dPppA" 
    frameborder="0" allow="accelerometer; autoplay; encrypted-media; 
    gyroscope; picture-in-picture" allowfullscreen></iframe>"""

https://ellie-app.com/4PkBNVJsKnka1

@NPCRUS
Copy link

NPCRUS commented Mar 3, 2021

both links you provided are to the same app

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

No branches or pull requests

2 participants