Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side navigation interruptibility #580

Open
1 task
hi-ogawa opened this issue Jul 18, 2024 · 0 comments
Open
1 task

Client side navigation interruptibility #580

hi-ogawa opened this issue Jul 18, 2024 · 0 comments

Comments

@hi-ogawa
Copy link
Owner

hi-ogawa commented Jul 18, 2024

There was something magical possible (thought probably it wasn't really fool proof when navigation multiple layout quickly) when using sync transition and async setState.

Now, we moved to async transition (in #564) and it's not possible to interrupt and start new client side navigation while the last one is pending.

Probably having async transition is actually mandatory to have robust error handling (e.g. const res = await fetch(), then check res.status, res.headers cf. #386). But having interruptible client side navigation in case of slow flight server stream seems quite an important feature, so we'll probably need to rework something huge to get this right (but hopefully we don't have to introduce entire reducer...?)

startTransition(async () => {
const response = await fetch(request);
if (handleFlightRedirectResponse(history, response)) {
return;
}
$__setFlight(
ReactClient.createFromFetch<FlightData>(Promise.resolve(response), {
callServer,
}),
);
});

// very shaky trick to merge with current layout
$__setFlight = (nextPromise) => {
setFlight(
memoize(async (currentPromise: Promise<FlightData>) => {
const current = await currentPromise;
const next = await nextPromise;
return {
action: next.action,
metadata: next.metadata,
segments: next.segments,
url: next.url,
nodeMap: {
...current.nodeMap,
...next.nodeMap,
},
layoutContentMap: next.layoutContentMap,
} satisfies FlightData;
}),
);
};

todo

  • research Next.js and others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant