Skip to content

feat: run the UI directives on the NoJS-Server host backend - #126

Merged
ErickXavier merged 9 commits into
mainfrom
feat/host-ui-directives
Nov 20, 2026
Merged

ErickXavier merged 9 commits into
mainfrom
feat/host-ui-directives

Conversation

@ErickXavier

@ErickXavier ErickXavier commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On a NoJS-Server compiled site (NoJS.hostApi >= 1) Elements 1.23 installed only dnd and validate. This runs every UI element on the host backend: accordion, breadcrumb, dropdown, modal, popover, scroll-spy, skeleton, split, stepper, table (sortable / sort / fixed-header / fixed-col / table-reorder), tabs, toast, tooltip, tree (with drag) and virtual-list. Found by the reference-site acceptance run (DIVERGENCES D-ELEMENTS-UI).

  • One implementation per module: src/_backend.js defineDirective(NoJS, name, { priority, subtree, init(el, expr, be) }). Core pages run exactly the code they ran before (same expr, disposers on el.__disposers); the existing core-mode unit and e2e suites are unchanged and pass.
  • Host backend: expression attributes are server-delivered values read with host.value (tooltip-disabled, tab-disabled, skeleton, step-validate, toast outside buttons/links/on:click); cleanup through host.onDispose; directives that build their own subtree declare subtree: true (tabs, accordion, stepper, split, skeleton, breadcrumb, toast-container, sortable, table-reorder, tree, tree-drag-mode, virtual, spy).
  • Re-init after a server re-render keeps user state on the element: selected tab, current step, table sort, generated tab/stepper ids.
  • src/ui-contract.js: the contract declares the expression attributes, sort (literal; keeps the attribute on table headers) and toast with literalOn.
  • Breadcrumb auto mode follows location.pathname and the integrator's nojs:navigate event. NoJS.modal/dropdown/popover/toast are also set on the page-level window.NoJS.
  • dnd: drag-disabled is applied at init on the host backend (D-DRAG-DISABLED-INIT).

Needs the NoJS-Server host API extensions (subtree, client-owned attributes, core-order init, literalOn, nojs:navigate) from no-js-dev/nojs-server feat/host-ui-api. With an older integrator the directives still run; subtree is ignored.

Known differences on compiled sites (documented in CHANGELOG)

  • Table sort / reorder move the rendered rows (core's static-table path); a loop-bound table's array is not reordered.
  • Virtual-list windows the rows the server rendered in full.
  • $stepper and $toast are not available to expressions (expressions run on the server).
  • drag-list / drag-multiple remain host stubs.

Tests

  • __tests__/ui-host.test.js (27): host install, subtree flags, contract, page APIs, and each directive on a stand-in host (values, watch, dispose, re-init state and ids).
  • e2e/tests/ui-host.spec.ts (16 x 3 browsers) on e2e/examples/ui-host.html with a stand-in plugin host.
  • npm test: 834 passed, 5 skipped. E2E: 702 passed (chromium, firefox, webkit).
  • NoJS-Server compiled parity with this build: elements-disclosure, elements-overlays, elements-navigation, elements-data, dnd-reorder, validate-form pass; reference site j1b-docs passes compiled.

Fixes in core mode too (lead decisions)

  • table sort marks only a <th> inside a table. sort is also core's loop companion; loop rows rendered after Elements installed got data-sortable, aria-sort="none", tabindex="0". Visible change: those rows leave the tab order and lose the sort attributes. Tests in both modes. (Reference site D-DND-SORT-CHILDREN.)
  • virtual-list row bindings render (each row gets a core context; rows were empty). Test added.
  • Docs: virtual-list examples add the required virtual attribute; a "Server-Rendered Hosts" section on every element page and in llms-full.txt; llms.txt updated.

For the release sync (not in this PR)

  • LSP (directives.json, nojs-custom-data.json, hover docs): add virtual as the required virtual-list attribute; note that sort is valid on <th> only for the table directive; optionally a "server-rendered hosts" line in hovers for table, virtual-list, stepper ($stepper), toast ($toast).
  • Skill (references/elements/*.md, SKILL.md): virtual-list examples need virtual; server-rendered host notes (table sort/reorder move rendered rows, virtual-list windows server-rendered rows, $stepper/$toast unavailable in expressions, toast literal vs expression); references/core/plugins.md: host directive option subtree, contract literalOn, nojs:navigate.

Every UI module registers one implementation through defineDirective,
which hands init (el, expr, be) on both backends. Core keeps its exact
behavior; on a compiled site the body reads server-delivered values with
host.value, disposes through host.onDispose and marks directives that
restructure their subtree (tabs, accordion, stepper, split, ...) with
subtree: true. The contract declares the expression attributes
(tooltip-disabled, tab-disabled, skeleton, step-validate, toast).
A server re-render re-initializes subtree-owning tabs and steppers on a
compiled site; the ids they generated go back to the same positions, as
core initializes them once. Declaring sort keeps the attribute on table
headers, where the compiler otherwise strips it as a loop companion.
Core's watcher applies it on the first state change after init; the
host watcher fires only when the delivered value changes, so a locked
row stayed draggable on compiled sites.
sort is also core's loop companion; loop rows rendered after Elements
installed got data-sortable, aria-sort and tabindex=0. Visible change:
those rows leave the tab order and lose the sort attributes.
@ErickXavier
ErickXavier marked this pull request as ready for review November 20, 2026 20:05
@ErickXavier
ErickXavier merged commit ce68241 into main Nov 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant