@rsc-kit/core 0.30.36 → 0.30.38

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.
package/dist/host.js CHANGED
@@ -128,6 +128,19 @@ function isNavigation(request) {
128
128
  return mode === "navigate";
129
129
  return (request.headers.get("accept") ?? "").includes("text/html");
130
130
  }
131
+ /**
132
+ * A redirect out of a form a browser posted to a page, as See Other.
133
+ *
134
+ * Whatever status redirect() was given. A 307 or 308 tells the browser to
135
+ * repeat the request - the same POST, the same body - at the destination, and
136
+ * that body still names the action, which runs at any page's url. So a
137
+ * save that redirected to its list ran again there, redirected again, and
138
+ * looped until the browser gave up, writing a record on every pass. 303 is
139
+ * the answer a form post is meant to get: go there, with a GET.
140
+ */
141
+ function afterFormPost(to) {
142
+ return { ...to, status: 303 };
143
+ }
131
144
  function redirectResponse(to, isPayloadRequest) {
132
145
  if (isPayloadRequest) {
133
146
  return new Response(null, {
@@ -955,7 +968,7 @@ export function createRscHandler(options) {
955
968
  // destination sitting in a scope nobody read.
956
969
  const refused = taken();
957
970
  if (refused)
958
- return redirectResponse(refused, false);
971
+ return redirectResponse(formPost ? afterFormPost(refused) : refused, false);
959
972
  // The page said this url names nothing. Null rather than a rendered
960
973
  // 404: null is already how this host says "not mine", and the caller
961
974
  // in front answers it with not-found.tsx and the right status. One
@@ -977,7 +990,7 @@ export function createRscHandler(options) {
977
990
  const early = taken();
978
991
  if (early) {
979
992
  letGo();
980
- return redirectResponse(early, false);
993
+ return redirectResponse(formPost ? afterFormPost(early) : early, false);
981
994
  }
982
995
  // Above every boundary, so the shell resolving means the page did not
983
996
  // refuse itself. Deeper than that and the shell is already on the wire