|
| 1 | +import { |
| 2 | + Asset, |
| 3 | + Await, |
| 4 | + Block, |
| 5 | + Body, |
| 6 | + CatchBoundary, |
| 7 | + CatchNotFound, |
| 8 | + ClientOnly, |
| 9 | + DefaultGlobalNotFound, |
| 10 | + ErrorComponent, |
| 11 | + HeadContent, |
| 12 | + Html, |
| 13 | + Link, |
| 14 | + Match, |
| 15 | + MatchRoute, |
| 16 | + Matches, |
| 17 | + Navigate, |
| 18 | + Outlet, |
| 19 | + RouterContextProvider, |
| 20 | + ScriptOnce, |
| 21 | + Scripts, |
| 22 | + ScrollRestoration, |
| 23 | + createLink, |
| 24 | + createRootRoute, |
| 25 | + linkOptions, |
| 26 | + useAwaited, |
| 27 | + useBlocker, |
| 28 | + useCanGoBack, |
| 29 | + useChildMatches, |
| 30 | + useElementScrollRestoration, |
| 31 | + useLinkProps, |
| 32 | + useLoaderData, |
| 33 | + useLoaderDeps, |
| 34 | + useLocation, |
| 35 | + useMatch, |
| 36 | + useMatchRoute, |
| 37 | + useMatches, |
| 38 | + useNavigate, |
| 39 | + useParams, |
| 40 | + useParentMatches, |
| 41 | + useRouteContext, |
| 42 | + useRouter, |
| 43 | + useRouterState, |
| 44 | + useSearch, |
| 45 | + useTags, |
| 46 | +} from '@tanstack/vue-router' |
| 47 | +import { |
| 48 | + createMiddleware, |
| 49 | + createServerFn, |
| 50 | + useServerFn, |
| 51 | +} from '@tanstack/vue-start' |
| 52 | + |
| 53 | +const requestMiddleware = createMiddleware().server(async ({ next }) => { |
| 54 | + return next() |
| 55 | +}) |
| 56 | + |
| 57 | +const functionMiddleware = createMiddleware({ type: 'function' }) |
| 58 | + .client(async ({ next }) => { |
| 59 | + return next() |
| 60 | + }) |
| 61 | + .server(async ({ next }) => { |
| 62 | + return next() |
| 63 | + }) |
| 64 | + |
| 65 | +const helloServerFn = createServerFn({ method: 'GET' }) |
| 66 | + .middleware([requestMiddleware, functionMiddleware]) |
| 67 | + .handler(async () => { |
| 68 | + return 'hello from server fn' |
| 69 | + }) |
| 70 | + |
| 71 | +export const Route = createRootRoute({ |
| 72 | + component: RootComponent, |
| 73 | +}) |
| 74 | + |
| 75 | +function RootComponent() { |
| 76 | + const router = useRouter() |
| 77 | + const [awaited] = useAwaited({ promise: Promise.resolve('ready') }) |
| 78 | + const linkProps = useLinkProps({ to: '/' } as any) |
| 79 | + const matchRoute = useMatchRoute() |
| 80 | + const matches = useMatches() |
| 81 | + const parentMatches = useParentMatches() |
| 82 | + const childMatches = useChildMatches() |
| 83 | + const match = useMatch({ strict: false, shouldThrow: false } as any) |
| 84 | + const loaderDeps = useLoaderDeps({ strict: false } as any) |
| 85 | + const loaderData = useLoaderData({ strict: false } as any) |
| 86 | + const params = useParams({ strict: false } as any) |
| 87 | + const search = useSearch({ strict: false } as any) |
| 88 | + const routeContext = useRouteContext({ strict: false } as any) |
| 89 | + const routerState = useRouterState({ select: (state) => state.status } as any) |
| 90 | + const location = useLocation() |
| 91 | + const canGoBack = useCanGoBack() |
| 92 | + const navigate = useNavigate() |
| 93 | + const scrollEntry = useElementScrollRestoration({ id: 'root-scroll' }) |
| 94 | + const tags = useTags() |
| 95 | + const invokeServerFn = useServerFn(helloServerFn) |
| 96 | + |
| 97 | + useBlocker({ |
| 98 | + shouldBlockFn: () => false, |
| 99 | + disabled: true, |
| 100 | + withResolver: false, |
| 101 | + }) |
| 102 | + |
| 103 | + const linkFactoryResult = linkOptions({ to: '/' } as any) |
| 104 | + const routeMatchResult = matchRoute({ to: '/' } as any) |
| 105 | + const SvgLink = createLink('svg') |
| 106 | + |
| 107 | + const startSurface = [createMiddleware, createServerFn, useServerFn] |
| 108 | + const hooksAndComponents = [ |
| 109 | + useAwaited, |
| 110 | + useLinkProps, |
| 111 | + useMatchRoute, |
| 112 | + useMatches, |
| 113 | + useParentMatches, |
| 114 | + useChildMatches, |
| 115 | + useMatch, |
| 116 | + useLoaderDeps, |
| 117 | + useLoaderData, |
| 118 | + useBlocker, |
| 119 | + useNavigate, |
| 120 | + useParams, |
| 121 | + useSearch, |
| 122 | + useRouteContext, |
| 123 | + useRouter, |
| 124 | + useRouterState, |
| 125 | + useLocation, |
| 126 | + useCanGoBack, |
| 127 | + useElementScrollRestoration, |
| 128 | + useTags, |
| 129 | + Await, |
| 130 | + CatchBoundary, |
| 131 | + CatchNotFound, |
| 132 | + ClientOnly, |
| 133 | + DefaultGlobalNotFound, |
| 134 | + ErrorComponent, |
| 135 | + Link, |
| 136 | + Match, |
| 137 | + MatchRoute, |
| 138 | + Matches, |
| 139 | + Navigate, |
| 140 | + Outlet, |
| 141 | + RouterContextProvider, |
| 142 | + ScrollRestoration, |
| 143 | + Block, |
| 144 | + ScriptOnce, |
| 145 | + Asset, |
| 146 | + HeadContent, |
| 147 | + Scripts, |
| 148 | + Body, |
| 149 | + Html, |
| 150 | + ] |
| 151 | + |
| 152 | + ;(globalThis as any).__TANSTACK_BUNDLE_SIZE_KEEP__ = { |
| 153 | + hooksAndComponents, |
| 154 | + startSurface, |
| 155 | + } |
| 156 | + |
| 157 | + void awaited |
| 158 | + void linkFactoryResult |
| 159 | + void matches.value |
| 160 | + void parentMatches.value |
| 161 | + void childMatches.value |
| 162 | + void match.value |
| 163 | + void loaderDeps.value |
| 164 | + void loaderData.value |
| 165 | + void params.value |
| 166 | + void search.value |
| 167 | + void routeContext.value |
| 168 | + void routerState.value |
| 169 | + void location.value |
| 170 | + void canGoBack.value |
| 171 | + void navigate |
| 172 | + void scrollEntry |
| 173 | + void tags() |
| 174 | + void routeMatchResult.value |
| 175 | + void invokeServerFn |
| 176 | + |
| 177 | + return ( |
| 178 | + <Html> |
| 179 | + <head> |
| 180 | + <HeadContent /> |
| 181 | + </head> |
| 182 | + <Body> |
| 183 | + <ScriptOnce>{'window.__tsr_bundle_size = true'}</ScriptOnce> |
| 184 | + <Asset |
| 185 | + tag="meta" |
| 186 | + attrs={{ name: 'bundle-size', content: 'vue-start-full' }} |
| 187 | + /> |
| 188 | + <Link {...(linkProps as any)}>home</Link> |
| 189 | + <SvgLink to="/" aria-label="svg-home"> |
| 190 | + <circle cx="8" cy="8" r="7" /> |
| 191 | + </SvgLink> |
| 192 | + <MatchRoute to="/">{() => <span data-test="match-route" />}</MatchRoute> |
| 193 | + <ClientOnly fallback={<span data-test="client-only-fallback" />}> |
| 194 | + <span data-test="client-only" /> |
| 195 | + </ClientOnly> |
| 196 | + <Await |
| 197 | + promise={Promise.resolve('done')} |
| 198 | + children={() => <span data-test="await" />} |
| 199 | + /> |
| 200 | + <Block shouldBlockFn={() => false} disabled withResolver={false}> |
| 201 | + {() => <span data-test="block" />} |
| 202 | + </Block> |
| 203 | + <CatchNotFound fallback={() => <DefaultGlobalNotFound />}> |
| 204 | + <span data-test="catch-not-found" /> |
| 205 | + </CatchNotFound> |
| 206 | + <RouterContextProvider router={router}> |
| 207 | + <span data-test="nested-router-context" /> |
| 208 | + </RouterContextProvider> |
| 209 | + <ScrollRestoration /> |
| 210 | + <Outlet /> |
| 211 | + <Scripts /> |
| 212 | + <div data-test="full-root"> |
| 213 | + <div>hello world</div> |
| 214 | + </div> |
| 215 | + </Body> |
| 216 | + </Html> |
| 217 | + ) |
| 218 | +} |
0 commit comments