@octanejs/tanstack-router 0.2.8 → 0.2.9

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.
@@ -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 { splitSlot, subSlot } from './internal';
5
- import { useStore } from './useStore';
6
- import type { AnyRouteMatch, RouterManagedTag } from '@tanstack/router-core';
2
+ import { createUseScripts } from './scriptContentBinding';
7
3
 
8
- // router-core 1.171.34 composes body scripts through `getSsrBodyScriptParts` +
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);