@bakery-framework/plugin-vue 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/handler.ts +25 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/plugin-vue",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Bakery vue plugin.",
5
5
  "keywords": [
6
6
  "bakery",
@@ -43,7 +43,7 @@
43
43
  "vue": "^3.5.38"
44
44
  },
45
45
  "dependencies": {
46
- "@bakery-framework/core": "^2.0.3"
46
+ "@bakery-framework/core": "^2.0.4"
47
47
  },
48
48
  "engines": {
49
49
  "bun": ">=1.4.0"
package/src/handler.ts CHANGED
@@ -568,8 +568,27 @@ export class VueHandler extends DynamicHandler {
568
568
  claimed?: string[]
569
569
  claimedSingle?: boolean
570
570
  },
571
+ /**
572
+ * The URL the page's own stylesheet and root script are requested
573
+ * through. The request route passes the page's URL; it defaults to the
574
+ * component's file path.
575
+ *
576
+ * **For a dynamic page the file path does not resolve.** It is
577
+ * `/admin/[...slug].vue`, a browser sends the brackets unencoded, and
578
+ * route lookup reads a requested name as a glob, where `[...slug]` is a
579
+ * character class: the literal file never matches, the catch-all then
580
+ * yields to the real file of that name, and nothing serves it. A real
581
+ * app's admin area answered 404 for both requests and lost its styles
582
+ * and its script. The page's own URL is the one address guaranteed to
583
+ * reach the component that rendered it; a fixed placeholder would not
584
+ * be, since a single-param sibling such as `admin/[id].vue` wins a
585
+ * one-segment URL before the catch-all does. Neither request runs the
586
+ * server block (see `needsServerData`), so the URL only picks the file.
587
+ */
588
+ assetPath: string = routePath,
571
589
  ) {
572
590
  const { hasCss, serverScript } = parsed
591
+ const assets = escapeHtml(assetPath)
573
592
  const hasServerData =
574
593
  Boolean(serverScript) || params?.errorCode !== undefined
575
594
 
@@ -619,9 +638,9 @@ export class VueHandler extends DynamicHandler {
619
638
  const prio =
620
639
  (await VueHandler.layoutCssLink(parsed)) +
621
640
  (hasCss
622
- ? `<link rel="stylesheet" id="__vu_css_${id}" href="${routePath}?__vue_css=true">\n`
641
+ ? `<link rel="stylesheet" id="__vu_css_${id}" href="${assets}?__vue_css=true">\n`
623
642
  : '') +
624
- `<script type="module" src="${routePath}?__vue_script=root"></script>`
643
+ `<script type="module" src="${assets}?__vue_script=root"></script>`
625
644
 
626
645
  const htmlRes = await injectIfHtml(hydrated, params, { prio })
627
646
  return htmlRes || response.error('Failed to build HTML', 500)
@@ -847,5 +866,9 @@ async function sharedHandler(
847
866
  // no reader. Skipping the stamp also skips the directory scan.
848
867
  ...(catchAll ? claimedBeside(diskFile.name ?? '') : null),
849
868
  },
869
+ // The page's own URL routes back to this component; see `assetPath`. An
870
+ // error render is the exception: its URL is the one that failed, and it
871
+ // would route to the error, not to the error page's component.
872
+ errorData ? routePath : url.pathname,
850
873
  )
851
874
  }