@octanejs/tanstack-router 0.2.8 → 0.2.10
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/README.md +42 -22
- package/package.json +2 -2
- package/src/Asset.tsrx +3 -135
- package/src/ClientOnly.tsrx +2 -0
- package/src/Link.tsrx +2 -53
- package/src/Matches.tsrx +6 -4
- package/src/Scripts.tsrx +2 -19
- package/src/Transitioner.tsrx +5 -4
- package/src/assetComponent.tsrx +146 -0
- package/src/compiled/Document.tsrx +101 -0
- package/src/compiled/Link.tsrx +18 -0
- package/src/compiled/Matches.tsrx +28 -19
- package/src/compiled/bindings.ts +2 -0
- package/src/compiled/route.tsrx +71 -0
- package/src/compiled.ts +36 -1
- package/src/fileRoute.ts +7 -58
- package/src/headContentBinding.ts +178 -0
- package/src/headContentUtils.ts +2 -170
- package/src/hookBindings.ts +2 -0
- package/src/internal.ts +2 -0
- package/src/link.ts +5 -379
- package/src/linkBinding.ts +391 -0
- package/src/linkComponent.tsrx +61 -0
- package/src/route.ts +6 -51
- package/src/routeHookBindings.ts +146 -0
- package/src/routerStateBinding.ts +2 -0
- package/src/scriptComponent.tsrx +27 -0
- package/src/scriptContentBinding.ts +43 -0
- package/src/scriptContentUtils.ts +2 -35
- package/src/useStore.ts +2 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement, useId } from 'octane';
|
|
2
|
+
import type { RouterManagedTag } from '@tanstack/router-core';
|
|
3
|
+
import { getAssetKeys } from './assetKeys.ts';
|
|
4
|
+
|
|
5
|
+
// router-core's initial hydration scripts remove themselves before adoption.
|
|
6
|
+
// Host descriptors leave no per-item template frames behind when they do, and
|
|
7
|
+
// create live script elements that execute on later client navigation. This
|
|
8
|
+
// shared owner intentionally remains outside Strong mode for both entries.
|
|
9
|
+
export function createScripts(useScripts: () => Array<RouterManagedTag>) {
|
|
10
|
+
function Scripts() @{
|
|
11
|
+
const owner = useId();
|
|
12
|
+
const scripts = useScripts();
|
|
13
|
+
const keys = getAssetKeys('body', owner, scripts);
|
|
14
|
+
<>
|
|
15
|
+
{scripts.map((script, index) => {
|
|
16
|
+
const { assetKey, managedKey } = keys[index]!;
|
|
17
|
+
return createElement('script', {
|
|
18
|
+
...script.attrs,
|
|
19
|
+
key: assetKey,
|
|
20
|
+
'data-tsr-managed-key': managedKey,
|
|
21
|
+
dangerouslySetInnerHTML: { __html: script.children ?? '' },
|
|
22
|
+
});
|
|
23
|
+
})}
|
|
24
|
+
</>
|
|
25
|
+
}
|
|
26
|
+
return Scripts;
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strong';
|
|
2
|
+
|
|
3
|
+
import { composeSsrBodyScripts, deepEqual, getSsrBodyScriptParts } from '@tanstack/router-core';
|
|
4
|
+
import { isServer } from '@tanstack/router-core/isServer';
|
|
5
|
+
import type { useRouter as UseRouter } from './context';
|
|
6
|
+
import { splitSlot, subSlot } from './internal';
|
|
7
|
+
import { useStore } from './useStore';
|
|
8
|
+
import type { AnyRouteMatch, RouterManagedTag } from '@tanstack/router-core';
|
|
9
|
+
|
|
10
|
+
// router-core 1.171.34 composes body scripts through `getSsrBodyScriptParts` +
|
|
11
|
+
// `composeSsrBodyScripts`, and the initial hydration `<Scripts>` take moved from
|
|
12
|
+
// the removed `serverSsr.takeBufferedScripts()` (a single buffered tag) to
|
|
13
|
+
// `serverSsr.takeInitialHydrationScriptTags()` (hydration tags plus the streaming
|
|
14
|
+
// boundary), which `composeSsrBodyScripts` interleaves.
|
|
15
|
+
const routeScriptAttrs = { suppressHydrationWarning: true };
|
|
16
|
+
|
|
17
|
+
export function createUseScripts(useRouter: typeof UseRouter) {
|
|
18
|
+
function useScripts(...args: Array<unknown>): Array<RouterManagedTag> {
|
|
19
|
+
const [, slot] = splitSlot(args);
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
const nonce = router.options.ssr?.nonce;
|
|
22
|
+
const getScripts = (matches: Array<AnyRouteMatch>) =>
|
|
23
|
+
composeSsrBodyScripts(
|
|
24
|
+
getSsrBodyScriptParts(matches, router.ssr?.manifest, nonce, routeScriptAttrs),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (isServer ?? router.isServer) {
|
|
28
|
+
return composeSsrBodyScripts(
|
|
29
|
+
getSsrBodyScriptParts(
|
|
30
|
+
router.stores.matches.get(),
|
|
31
|
+
router.ssr?.manifest,
|
|
32
|
+
nonce,
|
|
33
|
+
routeScriptAttrs,
|
|
34
|
+
),
|
|
35
|
+
router.serverSsr?.takeInitialHydrationScriptTags(),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return useStore(router.stores.matches, getScripts, deepEqual, subSlot(slot, 'body:scripts'));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return useScripts;
|
|
43
|
+
}
|
|
@@ -1,37 +1,4 @@
|
|
|
1
|
-
import { composeSsrBodyScripts, deepEqual, getSsrBodyScriptParts } from '@tanstack/router-core';
|
|
2
|
-
import { isServer } from '@tanstack/router-core/isServer';
|
|
3
1
|
import { useRouter } from './context';
|
|
4
|
-
import {
|
|
5
|
-
import { useStore } from './useStore';
|
|
6
|
-
import type { AnyRouteMatch, RouterManagedTag } from '@tanstack/router-core';
|
|
2
|
+
import { createUseScripts } from './scriptContentBinding';
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
// `composeSsrBodyScripts`, and the initial hydration `<Scripts>` take moved from
|
|
10
|
-
// the removed `serverSsr.takeBufferedScripts()` (a single buffered tag) to
|
|
11
|
-
// `serverSsr.takeInitialHydrationScriptTags()` (hydration tags plus the streaming
|
|
12
|
-
// boundary), which `composeSsrBodyScripts` interleaves.
|
|
13
|
-
const routeScriptAttrs = { suppressHydrationWarning: true };
|
|
14
|
-
|
|
15
|
-
export function useScripts(...args: Array<unknown>): Array<RouterManagedTag> {
|
|
16
|
-
const [, slot] = splitSlot(args);
|
|
17
|
-
const router = useRouter();
|
|
18
|
-
const nonce = router.options.ssr?.nonce;
|
|
19
|
-
const getScripts = (matches: Array<AnyRouteMatch>) =>
|
|
20
|
-
composeSsrBodyScripts(
|
|
21
|
-
getSsrBodyScriptParts(matches, router.ssr?.manifest, nonce, routeScriptAttrs),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (isServer ?? router.isServer) {
|
|
25
|
-
return composeSsrBodyScripts(
|
|
26
|
-
getSsrBodyScriptParts(
|
|
27
|
-
router.stores.matches.get(),
|
|
28
|
-
router.ssr?.manifest,
|
|
29
|
-
nonce,
|
|
30
|
-
routeScriptAttrs,
|
|
31
|
-
),
|
|
32
|
-
router.serverSsr?.takeInitialHydrationScriptTags(),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return useStore(router.stores.matches, getScripts, deepEqual, subSlot(slot, 'body:scripts'));
|
|
37
|
-
}
|
|
4
|
+
export const useScripts = createUseScripts(useRouter);
|
package/src/useStore.ts
CHANGED