question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove <Host/> component

See original GitHub issue

Is your feature request related to a problem?

If it’s "possible to remove <Host/>, let’s remove it.

Describe the solution you’d like

Idea from a discussion @mhevery and I just had:

  • Internally, there always needs to be an actual actual <div> (or whatever) host component
  • However, what if the <Host/> component user’s write never existed at all, it’s not something they import and use
  • And the “host” component qwik generates, ALWAYS is display: contents??
  • So “qwik’s” host is kinda never really there to begin with.
  • It’s a host element for qwik to interact with, but it’s not something to the user has to worry about since it’s basically silent.
  • The “user’s” host is whatever the heck they want it to be, or no host at all
  • Exactly like react in how it can return a top level element, or a fragment with an array of children

So user could return

return (
  <footer>my footer</footer>
)

And qwik would generate

<div q:host>
  <footer>myfooter</footer>
</div>

Or the user could return

return (
  <Fragment>
    <span>a</span>
    <span>b</span>
  </Fragment>
)

And qwik would generate

<div q:host>
    <span>a</span>
    <span>b</span>
</div>

And now the component’s css would flow how they’d expect, and their component could continue act like display inline if that’s what the top level components were. Just like how react devs would expect their components to render and flow.

This allows us to completely remove <Host/>, and now users wouldn’t have to worry about adding { tagName: 'footer' }, which are both strange to traditional JSX frameworks.

export default component$(() => { 
    return (
      <Host>
        <ul>
          ...
        </ul>
      </Host>
    );
  },
  {
    tagName: 'footer',
  }
);

becomes

export default component$(() => {
    return (
      <footer>
        <ul>...</ul>
      </footer>
    );
  } 
);

I also think this makes the internal code much easier now, because it doesn’t have to worry about merging attributes.

For example, let’s say that below is a React app.

export default function App() {
  return (
    <div>
      <CmpA style={ { color: 'red' } }/>
    </div>
  );
}

function CmpA() {
  return (
    <>
      <h1>Hello!</h1>
    </>
  );
}

The red color styles wouldn’t actually apply to the h1, cuz what would the “style” be getting assigned to? It’s a component prop, not an actual attribute. The example above wouldn’t work in React (which is expected).

Thoughts

Describe alternatives you’ve considered

Keep <Host/> :

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
adamdbradleycommented, Aug 5, 2022

Ok, I wasn’t aware of the accessibility tree issues. Here’s the latest research: https://adrianroselli.com/2022/07/its-mid-2022-and-browsers-mostly-safari-still-break-accessibility-via-display-properties.html

1reaction
manucorporatcommented, Aug 5, 2022

I am all for removing the host element, but technically extremely challenging. If we cant remove the actual host element, we cant remove apis to control it, aka <Host/> but I guess some better default like display:contents makes it less of a pain.

Also, i also find it arbitrary that we default to <div>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove the host HTML element selectors created by angular ...
In remove-host directive, all the children of the nativeElement are inserted before the host and then the host element is removed.
Read more >
Delete a Component - Hortonworks Data Platform
To delete a component: Steps. Using Ambari Web, browse the Hosts page. Find and click the FQDN of the host on which the...
Read more >
How to Delete a Host Created by a Targetable Component (Sun N1 ...
To create a virtual host with a targetable component, you must have Run Component Procedures and Allow of Host Sets permissions. Step. Uninstall...
Read more >
Disable Host Profile Component or Subprofile - VMware Docs
Note: Sometimes, disabling the check box might remove the component or component element from the host. This action is displayed in the task ......
Read more >
Angular :host, :host-context, ::ng-deep - The Complete Guide
Style isolation would allow us to ship our components knowing that the styles of the component will (most likely) not be overridden by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found