@octanejs/tanstack-router 0.3.2 → 0.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/tanstack-router",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -11,7 +11,33 @@
11
11
  "manual": [
12
12
  "src"
13
13
  ]
14
- }
14
+ },
15
+ "strong": [
16
+ "src/ClientOnly.tsrx",
17
+ "src/ErrorComponent.tsrx",
18
+ "src/ScriptOnce.tsrx",
19
+ "src/Transitioner.tsrx",
20
+ "src/assetComponent.tsrx",
21
+ "src/compiled/Document.tsrx",
22
+ "src/compiled/HydrationRangeOwner.tsrx",
23
+ "src/compiled/Link.tsrx",
24
+ "src/compiled/Matches.tsrx",
25
+ "src/compiled/bindings.ts",
26
+ "src/compiled/route.tsrx",
27
+ "src/compiled/serverDocument.client.ts",
28
+ "src/compiled/serverDocument.tsrx",
29
+ "src/headContentBinding.ts",
30
+ "src/hookBindings.ts",
31
+ "src/internal.ts",
32
+ "src/linkBinding.ts",
33
+ "src/linkComponent.tsrx",
34
+ "src/routeHookBindings.ts",
35
+ "src/router.ts",
36
+ "src/routerStateBinding.ts",
37
+ "src/scriptComponent.tsrx",
38
+ "src/scriptContentBinding.ts",
39
+ "src/useStore.ts"
40
+ ]
15
41
  },
16
42
  "description": "TanStack Router bindings for the octane renderer — reuses @tanstack/router-core and swaps the React binding for octane's hooks.",
17
43
  "author": {
@@ -60,17 +86,23 @@
60
86
  "isbot": "^5.1.22"
61
87
  },
62
88
  "peerDependencies": {
63
- "octane": "^0.16.0"
89
+ "octane": "^0.17.0"
64
90
  },
65
91
  "devDependencies": {
66
92
  "@tanstack/react-router": "1.170.41",
67
93
  "@tsrx/react": "^0.4.5",
68
94
  "esbuild": "^0.28.1",
69
- "octane": "0.16.0",
95
+ "octane": "0.17.0",
70
96
  "react": "19.2.7",
71
97
  "react-dom": "19.2.7",
72
98
  "vitest": "^4.1.10"
73
99
  },
100
+ "imports": {
101
+ "#server-document": {
102
+ "browser": "./src/compiled/serverDocument.client.ts",
103
+ "default": "./src/compiled/serverDocument.tsrx"
104
+ }
105
+ },
74
106
  "scripts": {
75
107
  "test": "vitest run"
76
108
  }
@@ -70,22 +70,26 @@ function subscribeToHistory(router: AnyRouter, history: AnyRouter['history']) {
70
70
  return unsub;
71
71
  }
72
72
 
73
- const resolvedLocation = router.stores.resolvedLocation.get();
73
+ // A completed load leaves a transaction on the router. Only a pending load
74
+ // for this history entry can own its upcoming render and lifecycle events.
75
+ const pending = router.stores.status.get() === 'pending';
76
+ const loadLocation = pending
77
+ ? router.stores.location.get()
78
+ : router.stores.resolvedLocation.get();
74
79
  if (
75
- resolvedLocation?.href === location.href &&
76
- resolvedLocation.state.__TSR_key === location.state.__TSR_key
80
+ loadLocation?.href !== location.href ||
81
+ loadLocation.state.__TSR_key !== location.state.__TSR_key
77
82
  ) {
78
- // Hydration acknowledges the already-committed tree, which does not trigger
79
- // another render for the navigation acknowledgement effect to observe.
80
- router.emit({
81
- type: 'onRendered',
82
- ...getLocationChangeInfo(resolvedLocation, resolvedLocation),
83
- fromLocation: resolvedLocation,
84
- });
85
- } else if (!router._tx) {
86
83
  router.load({ sync: true }).catch((err: unknown) => {
87
84
  console.error(err);
88
85
  });
86
+ } else if (!pending) {
87
+ // The already-committed tree will not rerender to acknowledge hydration.
88
+ router.emit({
89
+ type: 'onRendered',
90
+ ...getLocationChangeInfo(loadLocation, loadLocation),
91
+ fromLocation: loadLocation,
92
+ });
89
93
  }
90
94
  return unsub;
91
95
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  declare const process: { env: { NODE_ENV?: string } };
4
4
 
5
- import { useEffect, useId, HYDRATION_RANGE_BOUNDARY, createPortal, useState } from 'octane';
5
+ import { useEffect, useId, createPortal, useSyncExternalStore } from 'octane';
6
6
  import { DEV_STYLES_ATTR } from '@tanstack/router-core';
7
7
  import type { AssetCrossOriginConfig } from '@tanstack/router-core';
8
8
  import { createAsset } from '../assetComponent.tsrx';
@@ -12,6 +12,8 @@ import { createScripts } from '../scriptComponent.tsrx';
12
12
  import { getAssetKeys } from '../assetKeys';
13
13
  import { useHydrated } from '../ClientOnly.tsrx';
14
14
  import { useRouter } from './bindings';
15
+ import { HydrationRangeOwner } from './HydrationRangeOwner.tsrx';
16
+ import { ServerBody, ServerHead, ServerHtml } from '#server-document';
15
17
 
16
18
  import { isServer } from '@tanstack/router-core/isServer';
17
19
 
@@ -19,43 +21,32 @@ import type { HtmlProps } from '../Html';
19
21
  import type { HeadProps } from '../Head';
20
22
  import type { BodyProps } from '../Body';
21
23
 
22
- // This boundary returns the authored children directly, as the ordinary Body
23
- // owner does. Adding a template frame here changes the SSR range it claims.
24
- function HydrationRangeOwner(props: Pick<BodyProps, 'children'>) {
25
- return props.children;
26
- }
27
-
28
- (
29
- HydrationRangeOwner as typeof HydrationRangeOwner & {
30
- [HYDRATION_RANGE_BOUNDARY]: 'owner';
31
- }
32
- )[HYDRATION_RANGE_BOUNDARY] = 'owner';
24
+ const subscribeToHead = () => () => {};
25
+ const getHead = () => (typeof document === 'undefined' ? null : document.head);
33
26
 
34
27
  // Preserve the ordinary document and hydration-range ownership. Start owns
35
28
  // the outer passthrough boundary; this entry reads the compiled router context.
36
29
  export function Html(props: HtmlProps) @{
37
30
  const router = useRouter();
38
- const { children, ...attrs } = props;
39
31
  @if (isServer ?? router.isServer) {
40
- <html {...attrs}>{children}</html>
32
+ <ServerHtml {...props} />
41
33
  } @else {
42
- <>{children}</>
34
+ <>{props.children}</>
43
35
  }
44
36
  }
45
37
 
46
38
  export function Head(props: HeadProps) @{
47
39
  const router = useRouter();
48
- const { children, ...attrs } = props;
49
40
  @if (isServer ?? router.isServer) {
50
- <head {...attrs}>{children}</head>
41
+ <ServerHead {...props} />
51
42
  } @else {
52
- // Capture the portal target once, before client adoption. This is a
53
- // browser handle, not state copied from a post-hydration effect.
54
- const [target] = useState(() => (typeof document === 'undefined' ? null : document.head));
43
+ // The head portal participates in the first client hydration render, so its
44
+ // children and the body keep the server's shared useId sequence.
45
+ const target = useSyncExternalStore(subscribeToHead, getHead, getHead);
55
46
  @if (target) {
56
47
  <>
57
48
  {createPortal(() => @{
58
- <>{children}</>
49
+ <>{props.children}</>
59
50
  }, target)}
60
51
  </>
61
52
  }
@@ -64,15 +55,10 @@ export function Head(props: HeadProps) @{
64
55
 
65
56
  export function Body(props: BodyProps) @{
66
57
  const router = useRouter();
67
- const { children, ...attrs } = props;
68
58
  @if (isServer ?? router.isServer) {
69
- <body {...attrs}>
70
- <div id="__app">
71
- <HydrationRangeOwner children={children} />
72
- </div>
73
- </body>
59
+ <ServerBody {...props} />
74
60
  } @else {
75
- <HydrationRangeOwner children={children} />
61
+ <HydrationRangeOwner children={props.children} />
76
62
  }
77
63
  }
78
64
  export const Asset = createAsset(useRouter);
@@ -0,0 +1,16 @@
1
+ 'use strong';
2
+
3
+ import { HYDRATION_RANGE_BOUNDARY } from 'octane';
4
+ import type { BodyProps } from '../Body';
5
+
6
+ // This boundary returns the authored children directly, as the ordinary Body
7
+ // owner does. Adding a template frame here changes the SSR range it claims.
8
+ export function HydrationRangeOwner(props: Pick<BodyProps, 'children'>) {
9
+ return props.children;
10
+ }
11
+
12
+ (
13
+ HydrationRangeOwner as typeof HydrationRangeOwner & {
14
+ [HYDRATION_RANGE_BOUNDARY]: 'owner';
15
+ }
16
+ )[HYDRATION_RANGE_BOUNDARY] = 'owner';
@@ -0,0 +1,8 @@
1
+ // The browser build of `#server-document`. A client never renders the document
2
+ // elements: Html, Head, and Body take their server arm only when the router
3
+ // renders on the server.
4
+ import type * as ServerDocument from './serverDocument.tsrx';
5
+
6
+ export const ServerHtml = null as unknown as typeof ServerDocument.ServerHtml;
7
+ export const ServerHead = null as unknown as typeof ServerDocument.ServerHead;
8
+ export const ServerBody = null as unknown as typeof ServerDocument.ServerBody;
@@ -0,0 +1,29 @@
1
+ 'use strong';
2
+
3
+ // The document elements only the server renders. The compiler builds <html>,
4
+ // <head>, and <body> imperatively, through element descriptors, so client
5
+ // builds resolve `#server-document` to serverDocument.client.ts instead and never
6
+ // import those factories.
7
+ import type { HtmlProps } from '../Html';
8
+ import type { HeadProps } from '../Head';
9
+ import type { BodyProps } from '../Body';
10
+ import { HydrationRangeOwner } from './HydrationRangeOwner.tsrx';
11
+
12
+ export function ServerHtml(props: HtmlProps) @{
13
+ const { children, ...attrs } = props;
14
+ <html {...attrs}>{children}</html>
15
+ }
16
+
17
+ export function ServerHead(props: HeadProps) @{
18
+ const { children, ...attrs } = props;
19
+ <head {...attrs}>{children}</head>
20
+ }
21
+
22
+ export function ServerBody(props: BodyProps) @{
23
+ const { children, ...attrs } = props;
24
+ <body {...attrs}>
25
+ <div id="__app">
26
+ <HydrationRangeOwner children={children} />
27
+ </div>
28
+ </body>
29
+ }