Discussion:
[elm-discuss] Attributes not getting removed
Kasey Speakman
2017-05-09 20:00:29 UTC
Permalink
Hi, maybe someone has run into this.

I'm noticing that download and target attributes are not getting removed
from links even though subsequent renders are omitting them.

Using this test code on http://elm-lang.org/try:

import Html exposing (a, text, beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (target, download)

main =
beginnerProgram { model = False, view = view, update = update }

view model =
a
[ onClick Toggle
, if model then
target "_blank"
else
download True
]
[ text "click" ]

type Msg =
Toggle

update msg model =
case msg of
Toggle ->
not model


The initial view renders download="true".

First click renders download="null" target="_blank". In Chrome at least,
blank target is ignored and file is downloaded anyway simply for the
presence of download attribute.

Second click renders download="true" target.

I thought omitting the attribute would result in it being absent in the
rendered HTML, but not so.

*Well, after I typed this out...*

I found two work-around.

1) Wrap in a different parent element for each. For example, use div for
one and span for the other.
2) Using Html.Keyed.node to put an identity on each.

Kasey
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Witold Szczerba
2017-05-09 20:27:58 UTC
Permalink
This is surprising
 Looks like DOM↔VDOM diff does not remove missing (but
attached once) attributes? Or it ignores them because it does not want to
be too invasive?

As a other workaround, you can have always two amchor tags: one with
"target", one without, and just switch the visibility of them (the
"onClick" could be attached to the wrapping span, or both can have same
one).

Regards,
Witold Szczerba
Post by Kasey Speakman
Hi, maybe someone has run into this.
I'm noticing that download and target attributes are not getting removed
from links even though subsequent renders are omitting them.
import Html exposing (a, text, beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (target, download)
main =
beginnerProgram { model = False, view = view, update = update }
view model =
a
[ onClick Toggle
, if model then
target "_blank"
else
download True
]
[ text "click" ]
type Msg =
Toggle
update msg model =
case msg of
Toggle ->
not model
The initial view renders download="true".
First click renders download="null" target="_blank". In Chrome at least,
blank target is ignored and file is downloaded anyway simply for the
presence of download attribute.
Second click renders download="true" target.
I thought omitting the attribute would result in it being absent in the
rendered HTML, but not so.
*Well, after I typed this out...*
I found two work-around.
1) Wrap in a different parent element for each. For example, use div for
one and span for the other.
2) Using Html.Keyed.node to put an identity on each.
Kasey
--
You received this message because you are subscribed to the Google Groups
"Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kasey Speakman
2017-05-09 22:16:18 UTC
Permalink
Ah yes, that's another good workaround.

It's definitely not rendering as I would expect. Probably a performance
optimization that's gone awry.

I also tried download False, but that renders download="false". Which also
triggers a download (!) instead of opening normally, so the Elm's download
API must be askew.
Post by Witold Szczerba
This is surprising
 Looks like DOM↔VDOM diff does not remove missing (but
attached once) attributes? Or it ignores them because it does not want to
be too invasive?
As a other workaround, you can have always two amchor tags: one with
"target", one without, and just switch the visibility of them (the
"onClick" could be attached to the wrapping span, or both can have same
one).
Regards,
Witold Szczerba
Post by Kasey Speakman
Hi, maybe someone has run into this.
I'm noticing that download and target attributes are not getting removed
from links even though subsequent renders are omitting them.
import Html exposing (a, text, beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (target, download)
main =
beginnerProgram { model = False, view = view, update = update }
view model =
a
[ onClick Toggle
, if model then
target "_blank"
else
download True
]
[ text "click" ]
type Msg =
Toggle
update msg model =
case msg of
Toggle ->
not model
The initial view renders download="true".
First click renders download="null" target="_blank". In Chrome at least,
blank target is ignored and file is downloaded anyway simply for the
presence of download attribute.
Second click renders download="true" target.
I thought omitting the attribute would result in it being absent in the
rendered HTML, but not so.
*Well, after I typed this out...*
I found two work-around.
1) Wrap in a different parent element for each. For example, use div for
one and span for the other.
2) Using Html.Keyed.node to put an identity on each.
Kasey
--
You received this message because you are subscribed to the Google Groups
"Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gusztáv Szikszai
2017-05-10 07:40:07 UTC
Permalink
Already reported https://github.com/elm-lang/html/issues/124. My advice
would be to use `attribute "download" "value"` and it will be removed if
omitted.
Post by Kasey Speakman
Hi, maybe someone has run into this.
I'm noticing that download and target attributes are not getting removed
from links even though subsequent renders are omitting them.
import Html exposing (a, text, beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (target, download)
main =
beginnerProgram { model = False, view = view, update = update }
view model =
a
[ onClick Toggle
, if model then
target "_blank"
else
download True
]
[ text "click" ]
type Msg =
Toggle
update msg model =
case msg of
Toggle ->
not model
The initial view renders download="true".
First click renders download="null" target="_blank". In Chrome at least,
blank target is ignored and file is downloaded anyway simply for the
presence of download attribute.
Second click renders download="true" target.
I thought omitting the attribute would result in it being absent in the
rendered HTML, but not so.
*Well, after I typed this out...*
I found two work-around.
1) Wrap in a different parent element for each. For example, use div for
one and span for the other.
2) Using Html.Keyed.node to put an identity on each.
Kasey
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kasey Speakman
2017-05-10 14:32:43 UTC
Permalink
Saw that issue, almost commented. Using attribute is best work-around so
far.
Post by Gusztáv Szikszai
Already reported https://github.com/elm-lang/html/issues/124. My advice
would be to use `attribute "download" "value"` and it will be removed if
omitted.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...