@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.
@@ -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 { 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);
package/src/useStore.ts CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strong';
2
+
1
3
  // The keystone adapter. Everything reactive in the router funnels through
2
4
  // `@tanstack/react-store`'s `useStore(atom, selector)`, which is
3
5
  // `useSyncExternalStoreWithSelector(atom.subscribe→unsubscribe, atom.get, …,