@krate/runtime 0.5.0-rc.3 → 0.5.0-rc.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.
@@ -731,7 +731,7 @@ export function createKrateHandler(options) {
731
731
  }
732
732
  }
733
733
  }
734
- const wantsHTML = isHTMLDocRequest(p) || (rs.headers.get("accept") || "").includes("text/html");
734
+ const wantsHTML = isHTMLDocRequest(p) || extName(p) === "" || (rs.headers.get("accept") || "").includes("text/html");
735
735
  // Conditional headers dropped by an outer layer (flash notices) must not reach the file server.
736
736
  const sreq = rs.headers === rs.request.headers ? rs.request : new Request(rs.request.url, { method: rs.request.method, headers: rs.headers });
737
737
  let served = staticLayer ? await staticLayer.serve(sreq, p) : null;
@@ -743,6 +743,12 @@ export function createKrateHandler(options) {
743
743
  }
744
744
  if (served && served.status !== 404)
745
745
  return mergeStaticResponse(rs, served);
746
+ // An unknown URL follows the same slash rule as a page, then answers 404 at its canonical form.
747
+ if (p !== "/api" && !p.startsWith("/api/") && !p.startsWith("/__krate") && !p.split("/").some((seg) => seg.startsWith("."))) {
748
+ const slash = redirectToCanonicalSlash(rs);
749
+ if (slash)
750
+ return slash;
751
+ }
746
752
  const page404 = wantsHTML ? errorPage(p, 404, { closed: closedPattern }) : null;
747
753
  if (page404)
748
754
  return custom404(rs, page404);
package/dist/slot.d.ts CHANGED
@@ -5,4 +5,16 @@ export declare const Root: typeof KrateSlot;
5
5
  export declare function Slottable(props: {
6
6
  children?: unknown;
7
7
  }): unknown;
8
+ type SlotProps = Record<string, unknown> & {
9
+ children?: unknown;
10
+ };
11
+ /**
12
+ * Radix's `createSlot(ownerName)` (react-slot >= 1.2): a Slot that merges its
13
+ * props and `ref` onto its single child. `ownerName` only labels the component.
14
+ */
15
+ export declare function createSlot(ownerName: string): (props: SlotProps) => Node | null;
16
+ /** Radix's `createSlottable(ownerName)`: a `Slottable` marker for one owner. */
17
+ export declare function createSlottable(ownerName: string): (props: {
18
+ children?: unknown;
19
+ }) => unknown;
8
20
  export default Slot;
package/dist/slot.js CHANGED
@@ -8,4 +8,27 @@ export const Root = KrateSlot;
8
8
  export function Slottable(props) {
9
9
  return props?.children;
10
10
  }
11
+ /**
12
+ * Radix's `createSlot(ownerName)` (react-slot >= 1.2): a Slot that merges its
13
+ * props and `ref` onto its single child. `ownerName` only labels the component.
14
+ */
15
+ export function createSlot(ownerName) {
16
+ const OwnerSlot = (props) => {
17
+ const node = KrateSlot(props);
18
+ const ref = props?.ref;
19
+ if (node && typeof ref === 'function')
20
+ ref(node);
21
+ else if (node && ref && typeof ref === 'object')
22
+ ref.current = node;
23
+ return node;
24
+ };
25
+ OwnerSlot.displayName = ownerName + '.Slot';
26
+ return OwnerSlot;
27
+ }
28
+ /** Radix's `createSlottable(ownerName)`: a `Slottable` marker for one owner. */
29
+ export function createSlottable(ownerName) {
30
+ const OwnerSlottable = (props) => props?.children;
31
+ OwnerSlottable.displayName = ownerName + '.Slottable';
32
+ return OwnerSlottable;
33
+ }
11
34
  export default Slot;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createSlot, createSlottable, Slot, Slottable } from './slot.js';
3
+ describe('react-slot shim', () => {
4
+ it('createSlot merges props and ref onto the single child', () => {
5
+ const SlotImpl = createSlot('Dialog');
6
+ const child = document.createElement('a');
7
+ child.setAttribute('class', 'base');
8
+ let refd = null;
9
+ const node = SlotImpl({ className: 'extra', 'data-x': '1', ref: (n) => (refd = n), children: child });
10
+ expect(node).toBe(child);
11
+ expect(child.getAttribute('class')).toBe('base extra');
12
+ expect(child.getAttribute('data-x')).toBe('1');
13
+ expect(refd).toBe(child);
14
+ const objRef = { current: null };
15
+ SlotImpl({ ref: objRef, children: [child] });
16
+ expect(objRef.current).toBe(child);
17
+ expect(SlotImpl.displayName).toBe('Dialog.Slot');
18
+ });
19
+ it('createSlottable returns a marker that renders its children', () => {
20
+ const Marker = createSlottable('Dialog');
21
+ expect(Marker({ children: 'x' })).toBe('x');
22
+ expect(typeof Slot).toBe('function');
23
+ expect(typeof Slottable).toBe('function');
24
+ });
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krate/runtime",
3
- "version": "0.5.0-rc.3",
3
+ "version": "0.5.0-rc.4",
4
4
  "description": "Client-side runtime for Krate - signals, hydration, SPA router, resources, and context.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",