Skip to content

Commit

Permalink
Fix back button behavior in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-hadden committed Nov 18, 2023
1 parent fc78862 commit 60fb324
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eighty-cars-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-suspense": patch
---

Set vary header to avoid incorrect back button behavior.
13 changes: 12 additions & 1 deletion packages/astro-suspense/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ export const onRequest = defineMiddleware(async (ctx, next) => {
...response,
headers: {
...response.headers,
vary: [response.headers.get("vary"), "astro-suspense-transition"]
.filter(Boolean)
.join("\n"),
"content-type": "text/astro-suspense-transition-stream",
},
});
}

const stream = transformStream(ctx.locals.suspensePromises, response.body);

return new Response(stream, response);
return new Response(stream, {
...response,
headers: {
...response.headers,
vary: [response.headers.get("vary"), "astro-suspense-transition"]
.filter(Boolean)
.join("\n"),
},
});
});

function transformStream(
Expand Down

0 comments on commit 60fb324

Please sign in to comment.