ReviewOS

also looking at this

stacks/stx

fix(bun-plugin): forward analytics config on the serve path (so plugin/native analytics inject)

#1760
Merged glennmichael123 wants to merge fix/forward-analytics-on-serve-path into main
1 file +15 -0
packages/bun-plugin/src/serve.tsmodified+15-0
Changes to packages/bun-plugin/src/serve.ts
@@ -384,6 +384,13 @@ export async function serve(options: ServeOptions): Promise<void> {
384384 stxConfig._pluginComponentDirs = pluginLoaded._pluginComponentDirs
385385 if (pluginLoaded?._pluginPageDirs)
386386 stxConfig._pluginPageDirs = pluginLoaded._pluginPageDirs
387 // A plugin's setup() can mutate the loaded config — e.g. an analytics
388 // plugin sets `analytics.{enabled,driver,custom}` so injectAnalytics
389 // runs. bunfig's loadConfig above returns the RAW object (pre-setup), so
390 // carry the plugin-mutated analytics across, else the tracker is silently
391 // dropped on this serve path.
392 if (pluginLoaded?.analytics)
393 stxConfig.analytics = pluginLoaded.analytics
387394 }
388395 // Preload the default icon collection so <Icon name="..." /> resolves on
389396 // the FIRST page render. Without this preload, the IconBuiltin returns
@@ -1180,6 +1187,10 @@ export async function serve(options: ServeOptions): Promise<void> {
11801187 ...('defaultDescription' in stxConfig && { defaultDescription: stxConfig.defaultDescription }),
11811188 ...('defaultImage' in stxConfig && { defaultImage: stxConfig.defaultImage }),
11821189 ...('seo' in stxConfig && { seo: stxConfig.seo }),
1190 // Forward analytics so injectAnalytics runs on this serve path too —
1191 // both native providers (fathom/GA/…) and plugin-injected trackers (the
1192 // plugin-mutated analytics is merged onto stxConfig above).
1193 ...('analytics' in stxConfig && { analytics: stxConfig.analytics }),
11831194 // Forward plugin-registered component dirs so renderComponentWithSlot
11841195 // can resolve tags exposed by stx plugins (e.g. `<Notification>` from
11851196 // `@stacksjs/components` via a stx plugin shim). Populated by
@@ -1463,6 +1474,10 @@ export async function serve(options: ServeOptions): Promise<void> {
14631474 ...('defaultDescription' in stxConfig && { defaultDescription: stxConfig.defaultDescription }),
14641475 ...('defaultImage' in stxConfig && { defaultImage: stxConfig.defaultImage }),
14651476 ...('seo' in stxConfig && { seo: stxConfig.seo }),
1477 // Forward analytics so injectAnalytics runs on this serve path too —
1478 // both native providers (fathom/GA/…) and plugin-injected trackers (the
1479 // plugin-mutated analytics is merged onto stxConfig above).
1480 ...('analytics' in stxConfig && { analytics: stxConfig.analytics }),
14661481 // Mirror the static-route config: forward plugin-registered component
14671482 // dirs so dynamic routes also resolve `<Notification>` etc.
14681483 ...('_pluginComponentDirs' in stxConfig && { _pluginComponentDirs: stxConfig._pluginComponentDirs }),