ReviewOS

stacks/stx

Hyphenated custom-element tags are intercepted by the file-based component resolver (blocks Web Component / third-party widget hosting)

#1845
Closed glennmichael123 opened this 22 days ago · 2 comments
22 days ago

Summary

Any hyphenated tag is claimed by the file-based component resolver at parse time (it tries to load <name>.stx from disk), which makes it impossible to render a Web Component / custom element — the resolver wins before the browser ever sees the tag. This blocks hosting third-party imperative widgets the idiomatic way.

Impact (real app)

bench integrates a third-party rich-text editor (ts-medium-editor). It cannot use a <rich-text-editor> custom element because stx intercepts the hyphenated tag and looks for rich-text-editor.stx. The documented workaround (resources/components/Bench/RichTextEditor.stx:1-8) is to drop to a plain <div data-richtext-host> found via document.querySelectorAll('[data-richtext-host]'), plus a body-level MutationObserver (:479-492) to catch instances that appear inside toggled :if blocks — an entire imperative component built by hand.

defineCustomElement / ClientOnly / onClient are all exported, but they can't help here because the parse-time resolver claims the tag first.

Ask

Provide an escape hatch so a registered/known custom element (or an explicitly-marked tag) is passed through to the browser instead of being resolved as an .stx component — e.g. a <ClientOnly> raw-passthrough boundary, or a resolver skip-list for tags registered via defineCustomElement.

22 days ago

Fixed in c77c37f1c2 ("fix(components): preserve native custom elements").

component-processing.ts now short-circuits before the file resolver: a hyphenated tag with no matching .stx component is left alone for the browser. File components still take precedence, which keeps existing kebab-case component names working.

Verified against the case in this report — the tag, its attributes and its children all survive:

<rich-text-editor data-x="1"><p>inner</p></rich-text-editor>
  ->  <rich-text-editor data-x="1"><p>inner</p></rich-text-editor>

Also checked the harder placements, since a passthrough that only works at the top level would not have helped bench (its instances appear inside toggled blocks, which is what forced the body-level MutationObserver):

placementsurvives
inside @ifyes
inside :ifyes
inside :foryes

packages/stx/test/components/custom-element-passthrough.test.ts pins it — 11 tests, all passing.

So the <div data-richtext-host> + MutationObserver workaround at RichTextEditor.stx:1-8 and :479-492 can be replaced with a real <rich-text-editor> custom element.

Sign in to comment on this issue.