Skip to content

Regression in Anchor component #11349

Closed

Description

@roastedcpu

When upgrading from 14.4.10 to 14.6.1 the anchor component no longer sets the href attribute after the initial render.

This applies to both PolymerTemplate and LitTemplate.

See issue #3839 for attached code.

Activity

  1. knoobie commented on Jun 16, 2021

    @knoobie
    Contributor

    See the following discussion #10947

  2. DiegoCardoso commented on Jun 28, 2021

    @DiegoCardoso
    Contributor

    Hi @roastedcpu

    See issue #3839 for attached code.

    Which issue you are referring to? Can you provide the steps to reproduce this issue?

  3. roastedcpu commented on Jun 28, 2021

    @roastedcpu
    Author

    Hi @DiegoCardoso

    Which issue you are referring to? Can you provide the steps to reproduce this issue?

    VS-3839 on Jira :)

  4. roastedcpu commented on Jun 28, 2021

    @roastedcpu
    Author

    Reported:

    When upgrading from 14.4.10 to 14.6.1 the anchor component no longer sets the href attribute after the initial render.
    This applies to both PolymerTemplate and LitTemplate.

    AnchorTest.java

    package com.synesis7.sandbox;
    
    import java.io.ByteArrayInputStream;
    import java.nio.charset.StandardCharsets;
    
    import com.vaadin.flow.component.Tag;
    import com.vaadin.flow.component.dependency.JsModule;
    import com.vaadin.flow.component.html.Anchor;
    import com.vaadin.flow.component.littemplate.LitTemplate;
    import com.vaadin.flow.component.template.Id;
    import com.vaadin.flow.server.StreamResource;
      
    @Tag("anchor-test")
    @JsModule("./anchor-test.ts")
    public class AnchorTest extends LitTemplate {
    
      @Id("anchor")
      private Anchor anchor;
      
      public AnchorTest() {
        StreamResource streamResource = new StreamResource("test.txt",
    		    () -> new ByteArrayInputStream("this is a test".getBytes(StandardCharsets.UTF_8)));
        anchor.setHref(streamResource);
      }
    }
    

    anchor-test.ts

    import { LitElement, html, css, customElement, property } from "lit-element";
    import "@vaadin/vaadin-ordered-layout/src/vaadin-vertical-layout.js";
    import "@vaadin/vaadin-button/src/vaadin-button.js";
    
    @customElement("anchor-test")
    export class AnchorTest extends LitElement {
      @property({ reflect: true })
      static get styles() {
        return css`
          :host {
            display: block;
            height: 100%;
          }
        `;
      }
      
      render() {
        return html`
          <vaadin-vertical-layout style="width: 100%; height: 100%;">
            <a href="" download id="anchor"> <vaadin-button> Button </vaadin-button></a>
          </vaadin-vertical-layout>
      `;
      }
    }
    

    AnchorTestPolymer.java

    package com.synesis7.sandbox;
    
    import java.io.ByteArrayInputStream;
    import java.nio.charset.StandardCharsets;
    
    import com.vaadin.flow.component.Tag;
    import com.vaadin.flow.component.dependency.JsModule;
    import com.vaadin.flow.component.html.Anchor;
    import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
    import com.vaadin.flow.component.template.Id;
    import com.vaadin.flow.server.StreamResource;
    import com.vaadin.flow.templatemodel.TemplateModel;
    
    @Tag("anchor-test-polymer")
    @JsModule("./anchor-test-polymer.js")
    public class AnchorTestPolymer extends PolymerTemplate<TemplateModel> {
    
    	@Id("anchor")
    	private Anchor anchor;
    
    	public AnchorTestPolymer() {
    		StreamResource streamResource = new StreamResource("test.txt",
    				() -> new ByteArrayInputStream("this is a test".getBytes(StandardCharsets.UTF_8)));
    		anchor.setHref(streamResource);
    	}
    }
    

    anchor-test-polymer.js

    import { html, PolymerElement } from "@polymer/polymer/polymer-element.js";
    import "@vaadin/vaadin-ordered-layout/src/vaadin-vertical-layout.js";
    import "@vaadin/vaadin-button/src/vaadin-button.js";
    
    class AnchorTestPolymer extends PolymerElement {
      static get template() {
        return html`
          <style include="shared-styles">
            :host {
              display: block;
              height: 100%;
            }
          </style>
          <vaadin-vertical-layout style="width: 100%; height: 100%;">
            <a href="" download id="anchor"> <vaadin-button> Button </vaadin-button></a>
          </vaadin-vertical-layout>
        `;
      }
    
      static get is() {
        return "anchor-test-polymer";
      }
    
      static get properties() {
        return {
          // Declare your properties here.
        };
      }
    }
    
    customElements.define(AnchorTestPolymer.is, AnchorTestPolymer);
    
  5. vlukashov commented on Jun 28, 2021

    @vlukashov

    I was able to reproduce with this project (cloned from https://github.com/vaadin/skeleton-starter-flow/tree/v14).

    With 14.6.4 the <a> tag inside the <anchor-test-polymer> element has an empty href. That is, it does not point to the stream resource content. With 14.4.10 the same <a> tag has a valid href pointing to a stream resource.

  6. caalador commented on Jun 28, 2021

    @caalador
    Contributor

    This is probably due to #8974 that reads the attributes so the href will be set as "" and the second setHref might be dropped from the response.
    As a workaround for the problem drop the href definition from the template so that it reads <a download id="anchor"> <vaadin-button> Button </vaadin-button></a> and it should work as expected.

  7. vlukashov commented on Jun 28, 2021

    @vlukashov

    This is probably due to vaadin/flow#8974 that reads the attributes so the href will be set as "" and the second setHref might be dropped from the response.
    As a workaround for the problem drop the href definition from the template so that it reads <a download id="anchor"> <vaadin-button> Button </vaadin-button></a> and it should work as expected.

    Thanks for providing a work-around, @caalador! I can confirm it works in my demo porject.

    I'll transfer this issue to the https://github.com/vaadin/flow repo since the Anchor component is a part of the standard HTML component set provided by Flow.

  8. added
    BFPBugfix priority, also known as Warranty
    on Jun 28, 2021
  9. 8 remaining items

  10. added 5 commits that reference this issue on Jun 30, 2021
    24fc5c3
    6630aa9
    8b02a3e
    bf662a8
    a1a8c95
  11. vaadin-bot commented on Jul 15, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.6.6. For prerelease versions, it will be included in its final version.

  12. vaadin-bot commented on Jul 26, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 20.0.5. For prerelease versions, it will be included in its final version.

  13. vaadin-bot commented on Aug 6, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 21.0.0.beta1 and is also targeting the upcoming stable 21.0.0 version.

  14. vaadin-bot commented on Aug 9, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.

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

Metadata

Metadata