ReviewOS

stacks/stx

process: imports in `@include`'d partials don't register components — `<Dialog>` in a partial errors with `ENOENT: open 'dialog'` even when the parent page imports it

#1705
Closed glennmichael123 opened this 23 days ago · 0 comments
23 days ago

TL;DR

stx's component import-extraction pass only runs against the top-level page's <script> block. When a partial that's pulled in via @include contains its own import { Foo } from '@stacksjs/components', the import never registers Foo as a known component — the component resolver then falls back to the local-component file search and emits ENOENT: open 'foo'. The page-level import (when the parent page also imports Foo) doesn't propagate into the included partial either.

Net effect: any partial that wants to use a component from @stacksjs/components either (a) has to fall back to hand-rolled markup or (b) requires the consuming app to inline the markup directly in every page instead of @including a partial.

Empirical repro

In a training app I migrated 18 hand-rolled modals to <Dialog> from @stacksjs/components. 11 of them landed in page files (views/coaches/atp.stx, views/coaches/athletes.stx, views/coaches/calendar.stx) and work correctly. The other 7 — in partials — all failed identically:

resources/components/confirmation.stx (the reverted commit explains it in-file):

<!--
  Partials cannot use <Dialog> from @stacksjs/components — the import-extraction
  pass in stx's renderer only runs against the top-level page's <script>, so an
  `import { Dialog } from '@stacksjs/components'` declared in a partial that's
  pulled in via @include never registers as a known component. The component
  resolver then falls back to the local-component search and emits an
  "ENOENT: open 'dialog'" error.
-->

Three reverted files (had to roll back from <Dialog> to plain <div :show=…>):

  • resources/components/athlete-home.stx (2 modals)
  • resources/components/coach-sidebar.stx (4 modals)
  • resources/components/confirmation.stx (1 modal)

The parent pages do import Dialog (views/coaches/calendar.stx includes confirmation.stx and itself has import { Dialog } from '@stacksjs/components'), but the import doesn't propagate.

The oddity that needs investigating

Spinner works in partials. athlete-home.stx is a partial included from views/index.stx. It has:

<script client>
  import { Spinner } from '@stacksjs/components'
  ...
</script>
...
<Spinner size="lg" color="success" />

And it works. But import { Dialog } in the same kind of file fails. Two hypotheses for why:

  1. Component already in registry from another file's extraction. Spinner is imported in views/dashboard.stx, views/profile.stx, views/metrics.stx, views/workouts.stx, views/settings.stx, views/performance.stx, views/coaches/dashboard.stx, views/settings/zones.stx. So by the time athlete-home.stx is rendered, Spinner is already cached in the registry from one of those pages' extractions. Dialog was only imported in three pages, and the partial render might happen before any of those.
  2. File-search fallback differs. Maybe the resolver checks Spinner.stx (uppercase) in the components dir as a fallback and that happens to find something, but Dialog.stx doesn't match. Unlikely but possible.

The fix shape depends on which it is.

What's needed

Component resolution from a partial should honor:

  1. The partial's own <script> imports (extracted per-file, scoped to the partial's content)
  2. AND/OR the including page's imports (propagated down through the include)

Either model works for the user. The current behavior (neither works reliably) doesn't.

Files touched in the repro

  • resources/views/coaches/atp.stx:7 — import { Dialog, Spinner } from '@stacksjs/components' works (page)
  • resources/views/coaches/calendar.stx:7 — import { Dialog } works (page)
  • resources/views/coaches/athletes.stx:7 — import { Dialog, Spinner } works (page)
  • resources/components/confirmation.stx — Dialog import fails (partial)
  • resources/components/coach-sidebar.stx — Dialog import fails (partial)
  • resources/components/athlete-home.stx — Dialog import fails, but Spinner import in the same script block works (partial)

This is the gap that prevents shipping the slot-based Dialog/Drawer migration patterns from #1704 into reusable partials. Apps end up either inlining the markup at every site or sticking with hand-rolled <div :show=…> modals in partials — both regress from the goal of consistent component usage.

🤖 Filed via Claude Code

Sign in to comment on this issue.