@rsc-kit/core 0.22.4 → 0.22.6

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.
package/dist/host.js CHANGED
@@ -268,6 +268,22 @@ function refererPath(referer, origin, hosts = []) {
268
268
  return null;
269
269
  }
270
270
  }
271
+ /**
272
+ * The url of the page an action was invoked from, query string included -
273
+ * or undefined. On this origin whatever the header names: it only ever
274
+ * decides what a render reads from searchParams(), never where anything goes.
275
+ */
276
+ function pageHref(referer, origin) {
277
+ if (!referer)
278
+ return undefined;
279
+ try {
280
+ const parsed = new URL(referer, origin);
281
+ return new URL(parsed.pathname + parsed.search, origin).href;
282
+ }
283
+ catch {
284
+ return undefined;
285
+ }
286
+ }
271
287
  /**
272
288
  * How large a query url may be before it is refused.
273
289
  *
@@ -392,11 +408,15 @@ export function createRscHandler(options) {
392
408
  return false;
393
409
  return (await source(`${patternKey(match.route)}.ppr.html`)) !== null;
394
410
  }
395
- function pageContext(match, props, url) {
411
+ function pageContext(match, props, url, href) {
396
412
  return {
397
413
  component: match.route.component,
398
414
  props,
399
415
  url,
416
+ // The page's whole url, query string included, for what an action
417
+ // re-renders of it - see withUrl in request.ts. `url` is the path the
418
+ // route matched and the key a navigation to it renders under.
419
+ href,
400
420
  layouts: match.route.layouts.map((component) => ({
401
421
  component,
402
422
  props: {},
@@ -1564,7 +1584,7 @@ export function createRscHandler(options) {
1564
1584
  const from = refererPath(request.headers.get(HEADER.referer), url.origin, siteHosts);
1565
1585
  const match = from ? matchRoute(routes, from) : null;
1566
1586
  const page = match
1567
- ? pageContext(match, await propsFor(match, request), from ?? undefined)
1587
+ ? pageContext(match, await propsFor(match, request), from ?? undefined, pageHref(request.headers.get(HEADER.referer), url.origin))
1568
1588
  : undefined;
1569
1589
  // Scoped to this action: revalidate() called anywhere inside it, at any
1570
1590
  // depth, marks here and nowhere else — two requests can be in flight and