Skip to content

feat: runtime npm registry fetching for lynx-example versions#23

Open
Huxpro wants to merge 8 commits intomainfrom
Huxpro/runtime-fetch-examples
Open

feat: runtime npm registry fetching for lynx-example versions#23
Huxpro wants to merge 8 commits intomainfrom
Huxpro/runtime-fetch-examples

Conversation

@Huxpro
Copy link
Copy Markdown
Member

@Huxpro Huxpro commented Mar 17, 2026

Summary

Implemented runtime npm registry discovery for @lynx-example packages, enabling browsing any version directly from the CDN without build-time preparation.

  • New npm-registry.ts: Runtime helpers for npm search API and jsdelivr CDN queries
  • Version support: ExamplePreview now accepts optional version prop to fetch from CDN
  • Example app UI: Added version selector dropdown and runtime example list discovery
  • Zero build overhead: Examples no longer cached in public/; enables instant version switching

Test Plan

  • Load example app at http://localhost:5969
  • Verify example list populates from npm (loading indicator shows briefly)
  • Select an example and verify version dropdown fills with available versions
  • Switch versions and verify metadata reloads from CDN
  • Switch examples and verify version resets to latest

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 17, 2026

Deploy Preview for lynx-go-web ready!

Name Link
🔨 Latest commit 057f7ca
🔍 Latest deploy log https://app.netlify.com/projects/lynx-go-web/deploys/69bbeb7bdba13600087a0780
😎 Deploy Preview https://deploy-preview-23--lynx-go-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Huxpro added 4 commits March 17, 2026 17:56
- New npm-registry.ts module provides runtime example discovery and version
  selection via jsdelivr CDN, replacing build-time prepare-examples.js
- ExamplePreview accepts optional version prop to fetch from CDN instead of
  local static files
- Example app now displays runtime example list from npm registry and version
  selector dropdown
- Example packages no longer need to be pre-downloaded at build time, enabling
  zero-install and support for any published version

This enables browsing any version of any @lynx-example/* package directly
in the browser without requiring a rebuild.
…ntext

Remove the global Version dropdown from the toolbar to avoid the confusion
of a unified version control across packages that have independent version
histories. Instead, show the version selector in the Entries column header
(clearly scoped to the selected example) and display the current version as
a badge on the active example list item.
The jsdelivr data API (/v1/packages/npm/...) does not support dist-tags
like 'latest' — it requires exact semver versions. Passing 'latest'
caused file listing and metadata fetches to silently fail.

Compute effectiveVersion by resolving 'latest' against the already-fetched
examplePackages (npm search result) or packageVersions[0] (fallback).
Pass effectiveVersion to ExamplePreview and fetchExampleMetadata instead of
the raw version state.
…validate

- Initialize useExamplePackages from build-time EXAMPLES env var so the list
  renders immediately on first paint with zero network latency
- Background-fetch from npm registry replaces the list once resolved
- Replace loading: boolean with source: 'build'|'fetching'|'live'|'error'
  for precise state semantics
- Add SourceBadge component in the Examples panel header showing current
  data source with color-coded states and a pulsing dot during fetch
@Huxpro Huxpro force-pushed the Huxpro/runtime-fetch-examples branch from 5fcb8a2 to 63a146d Compare March 17, 2026 21:56
Huxpro added 4 commits March 17, 2026 20:28
…stead

Root cause of missing loading overlay: effectiveVersion started as undefined
(while examplePackages loaded), causing ExamplePreview to mount twice —
first with useCdn=false (local static files), then remount with a real semver
(CDN). During the CDN remount's metadata fetch window there was no WebIframe
and therefore no loading overlay visible.

Fix: remove the 'latest' virtual version entirely. version state defaults to
undefined; a new useEffect auto-pins it to packageVersions[0].version once
the version list loads. effectiveVersion falls back to currentPkg.version
from the already-loaded examplePackages, so the CDN path is taken immediately
on example switch (single mount, single loading overlay).
The runtime fetch layer only searched @lynx-example/* and hardcoded
that scope everywhere, breaking vue-lynx-example support added in
cecc9a0. Introduce EXAMPLE_SCOPES as a shared source of truth for
scope metadata (prefix, git base URL) and update all consumers:

- searchExamplePackages() now searches all configured scopes in parallel
- fetchExampleMetadata() derives git URL and shortName from scope config
- Build-time init in main.tsx maps vue- prefixed names back to their scope
- Package name derivation uses currentPkg instead of hardcoded scope
… load

Root cause: the LoadingOverlay lives inside WebIframe, which only mounts
after defaultWebPreviewFile is set (i.e. after metadata finishes fetching).
During the CDN metadata fetch window there is no WebIframe in the tree at
all, so no loading indicator is visible. Additionally, once the CDN bundle
is browser-cached the template renders in ~2 rAFs which is imperceptible.

Fix: import LoadingOverlay into ExampleContent and render it directly on
the preview-wrap-content panel with visible={!initState}. This covers the
entire metadata-fetch phase. The WebIframe's own overlay continues to
handle the subsequent template-load phase, giving a seamless indicator
from the moment the CDN version is requested until the frame is painted.
Two distinct loading phases, clearly separated:

1. **App-level (example app):** Don't render Go until effectiveVersion is
   resolved. This avoids the useCdn=false → useCdn=true double-mount when
   effectiveVersion transitions from undefined to a real semver. Show a
   simple "Resolving package version…" placeholder instead.

2. **Go library (ExampleContent):** The LoadingOverlay with
   visible={!initState} covers the CDN metadata fetch phase. This is Go's
   own universal loading state — it works wherever Go is embedded, not just
   in this example app.
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