Skip to content

Commit

Permalink
fix: swr navigation works again
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Dec 6, 2022
1 parent b6ee85d commit 19c9f97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
15 changes: 9 additions & 6 deletions examples/react/basic-ssr/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export async function createServer(
app.use(vite.middlewares)
} else {
app.use((await import('compression')).default())
app.use(
(await import('serve-static')).default(resolve('dist/client'), {
index: false,
}),
)
// app.use(
// (await import('serve-static')).default(resolve('dist/client'), {
// index: false,
// }),
// )
}

app.use('*', async (req, res) => {
Expand All @@ -59,7 +59,9 @@ export async function createServer(

if (url.includes('.')) {
console.warn(`${url} is not valid router path`)
return res.status(404)
res.status(404)
res.end(`${url} is not valid router path`)
return
}

// Extract the head from vite's index transformation hook
Expand Down Expand Up @@ -96,6 +98,7 @@ export async function createServer(
// Modify head
// Request/Response control at the route level

console.log('Rendering: ', url, '...')
entry.render({ req, res, url, head: viteHead })
} catch (e) {
!isProd && vite.ssrFixStacktrace(e)
Expand Down
4 changes: 0 additions & 4 deletions examples/react/basic-ssr/src/entry-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ const state = (window as any).__TANSTACK_ROUTER_STATE__
router.hydrate(state)

ReactDOM.hydrateRoot(document, <RouterProvider router={router} />)

// ReactDOM.createRoot(document.getElementById('root')!).render(
// <RouterProvider router={router} />,
// )
7 changes: 4 additions & 3 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,15 +924,16 @@ export function createRouter<
const matchPromises = resolvedMatches.map(async (match) => {
// Validate the match (loads search params etc)
match.__.validate()
match.load(loaderOpts)

const search = match.search as { __data?: any }

if (search.__data && search.__data.matchId !== match.matchId) {
if (search.__data?.matchId && search.__data.matchId !== match.matchId) {
return
}

if (match.__.loadPromise) {
match.load(loaderOpts)

if (match.status !== 'success' && match.__.loadPromise) {
// Wait for the first sign of activity from the match
await match.__.loadPromise
}
Expand Down

0 comments on commit 19c9f97

Please sign in to comment.