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

multiple usages of new URL + import.meta.url in same file only bundles the last occurrence #1410

Open
thescientist13 opened this issue Feb 8, 2025 · 0 comments · May be fixed by #1412
Open
Assignees
Labels
bug Something isn't working CLI v0.31.1
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Feb 8, 2025

What happened?

When I have a component with multiple usages of new URL + import.meta.url in the same file, it looks like only the last instance is getting bundled.

const template = document.createElement('template');

export default class HeaderComponent extends HTMLElement {
  #logo = new URL("../../assets/greenwood-logo.png", import.meta.url);
  #otherLogo = new URL("../../assets/nodejs.svg", import.meta.url);

  connectedCallback() {
    if (!this.shadowRoot) {
      template.innerHTML = `
        <header class="header">
          <a href="/">
            <img src="${this.#logo.pathname.replace(window.location.pathname, "/")}" alt="Greenwood Logo"/>
            <h4>My Blog</h4>
          </a>
          <img src="${this.#node.pathname.replace(window.location.pathname, "/")}" alt="NodeJS Logo"/>
        </header>
      `;
      
      this.attachShadow({ mode: 'open' });
      this.shadowRoot.appendChild(template.content.cloneNode(true));
    }
  }
}

customElements.define('app-header', HeaderComponent);

In the browser, we can see the src attribute of the first <img> tag has an unbundled path, but the second one is
Image

Steps to reproduce

  1. Have a component with two usages of new URL + import.meta.url in the same file
  2. Run Greenwood's build command

Repro repo - https://github.com/ProjectEvergreen/greenwood-getting-started/compare/1408-debug-new-url-import-meta?expand=1

Environment

  • Greenwood v0.31.0
  • Node v22

Additional Context

N / A

@thescientist13 thescientist13 added bug Something isn't working CLI v0.31.1 labels Feb 8, 2025
@thescientist13 thescientist13 added this to the 1.0 milestone Feb 8, 2025
@thescientist13 thescientist13 self-assigned this Feb 8, 2025
@thescientist13 thescientist13 changed the title multiple consecutive new URL + import.meta.url usages in same file only bundles the last occurence multiple usages of new URL + import.meta.url in same file only bundles the last occurrence Feb 8, 2025
@thescientist13 thescientist13 moved this from 🔖 Ready to 🏗 In progress in [Greenwood] Phase 10 - Ecosystem Compat Feb 8, 2025
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 10 - Ecosystem Compat Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLI v0.31.1
Projects
Status: 👀 In review
1 participant