emberjs / emberjs/ember.js

[Bug] in-element cannot render into a document-fragment

Open
#20,643 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

This is basically the same as: https://github.com/emberjs/ember.js/issues/20641

but with this code:
(notice the `.content`)

```gts
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { setComponentTemplate } from '@ember/component';
import templateOnly from '@ember/component/template-only';
import { precompileTemplate } from '@ember/template-compilation';

import { modifier } from 'ember-modifier';

import type { ComponentLike } from '@glint/template';

// index.html has the production-fingerprinted references to these links
// Ideally, we'd have some pre-processor scan everything for references to
// assets in public, but idk how to set that up
const getStyles = () => [...document.head.querySelectorAll('link')].map((link) => link.href);

const Shadow = setComponentTemplate(precompileTemplate(`

{{yield}}

`, { strictMode: true }), templateOnly('shadow', 'Shadow')) as ComponentLike<{
Element: HTMLTemplateElement;
Args: {};
Blocks: { default: [] }
}>;

export class Shadowed extends Component<{
Element: HTMLDivElement;
Args: {
omitStyles?: boolean;
};
Blocks: { default: [] };
}> {
@tracked shadow: ShadowRoot | undefined | null;

getShadowRef = modifier((element: HTMLTemplateElement) => {
this.shadow = element.content;
});


{{#if this.shadow}}
{{#in-element this.shadow}}
{{#unless @omitStyles}}
{{#each (getStyles) as |styleHref|}}

{{/each}}
{{/unless}}

{{yield}}
{{/in-element}}
{{/if}}


;
}

export default Shadowed;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.