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

top level attributes returning as undefined #165

Open
thescientist13 opened this issue Oct 1, 2024 · 0 comments · May be fixed by #166
Open

top level attributes returning as undefined #165

thescientist13 opened this issue Oct 1, 2024 · 0 comments · May be fixed by #166
Assignees
Labels
0.15.0 bug Something isn't working
Milestone

Comments

@thescientist13
Copy link
Member

Summary

Noticed in ProjectEvergreen/www.greenwoodjs.dev#94 that something simple when pre-rendering

<app-side-nav
  route="/guides/"
  heading="Guides"
></app-side-nav>
import { getContentByRoute } from "@greenwood/cli/src/data/queries.js";
import styles from "./side-nav.module.css";

export default class SideNav extends HTMLElement {
  async connectedCallback() {
    const heading = this.getAttribute("heading");
    const route = this.getAttribute("route");
    const currentRoute = this.getAttribute("current-route");
    
    // route gets used somewhere down here...
  }
}

customElements.define("app-side-nav", SideNav);

Will result in an error because route is undefined

{ route: undefined, heading: undefined }
TypeError [Error]: Cannot read properties of undefined (reading 'data')
    at file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/src/components/side-nav/side-nav.js:20:28
    at Array.forEach (<anonymous>)
    at SideNav.connectedCallback (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/src/components/side-nav/side-nav.js:13:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async initializeCustomElement (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/wc-compiler/src/wcc.js:218:5)
    at async renderFromHTML (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/wc-compiler/src/wcc.js:259:5)
    at async executeRouteModule (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/@greenwood/cli/src/lib/execute-route-module.js:13:22)
    at async executeModule (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/@greenwood/cli/src/lib/ssr-route-worker.js:6:16)
    at async MessagePort.<anonymous> (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/@greenwood/cli/src/lib/ssr-route-worker.js:12:3)

Details

It actually looks like for renderFromHTML that we are double instantiating dependencies through initializeCustomElement which calls connectedCallback, when all we really need is to just trigger calling customElements.define, as the real rendering happens in renderComponentRoots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.15.0 bug Something isn't working
Projects
1 participant