From bbead33bf530be030d16a1466b52cd99d077382a Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Wed, 10 Jul 2024 08:11:40 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Properly=20bind=20cloudflare=20workers?= =?UTF-8?q?=E2=80=99=20ctx.waitUntil=20and=20ctx.passThroughOnException=20?= =?UTF-8?q?(#9696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contributors.yml | 1 + templates/cloudflare-workers/server.js | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/contributors.yml b/contributors.yml index a1c32df2763..941193224a9 100644 --- a/contributors.yml +++ b/contributors.yml @@ -5,6 +5,7 @@ - abotsi - accidentaldeveloper - achinchen +- acusti - adamwathan - adicuco - AdiRishi diff --git a/templates/cloudflare-workers/server.js b/templates/cloudflare-workers/server.js index dfcfb3f5184..034653d326a 100644 --- a/templates/cloudflare-workers/server.js +++ b/templates/cloudflare-workers/server.js @@ -9,16 +9,15 @@ const handleRemixRequest = createRequestHandler(remixBuild); export default { async fetch(request, env, ctx) { + const waitUntil = ctx.waitUntil.bind(ctx); + const passThroughOnException = ctx.passThroughOnException.bind(ctx); try { const url = new URL(request.url); const ttl = url.pathname.startsWith("/assets/") ? 60 * 60 * 24 * 365 // 1 year : 60 * 5; // 5 minutes return await getAssetFromKV( - { - request, - waitUntil: ctx.waitUntil.bind(ctx), - }, + { request, waitUntil }, { ASSET_NAMESPACE: env.__STATIC_CONTENT, ASSET_MANIFEST: MANIFEST, @@ -40,10 +39,7 @@ export default { // `cloudflareDevProxyVitePlugin`: // https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy cf: request.cf, - ctx: { - waitUntil: ctx.waitUntil, - passThroughOnException: ctx.passThroughOnException, - }, + ctx: { waitUntil, passThroughOnException }, caches, env, }, From 01b868f52cb27acb4a4b7f97dd25a483ea0d7ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Comeau?= <114004123+sebastien-comeau@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:33:16 -0300 Subject: [PATCH 2/2] docs: add info on FormData submitter and SubmitEvent compatibility (#9739) --- contributors.yml | 1 + docs/guides/faq.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/contributors.yml b/contributors.yml index 941193224a9..b699a984905 100644 --- a/contributors.yml +++ b/contributors.yml @@ -575,6 +575,7 @@ - sean-roberts - SeanGroff - SeanRoberts +- sebastien-comeau - sebz - selfish - sergiocarneiro diff --git a/docs/guides/faq.md b/docs/guides/faq.md index 021b411e9b0..333b67217b2 100644 --- a/docs/guides/faq.md +++ b/docs/guides/faq.md @@ -135,6 +135,8 @@ export default function Projects() { } ``` +Older browser versions might break this functionality because they might not support the [SubmitEvent: submitter property][submitevent-submitter] or the [FormData() constructor submitter parameter][formdata-submitter]. Be sure to check the browser compatibility for these features. If you need to polyfill this, please refer to the [Event Submitter Polyfill][polyfill-event-submitter] and the [FormData Submitter Polyfill][polyfill-formdata-submitter]. For more details, see the related issue [remix-run/remix#9704][remix-submitter-issue]. + ## How can I have structured data in a form? If you're used to doing fetches with a content type of `application/json`, you may wonder how forms fit into this. [`FormData`][form_data] is a bit different from JSON. @@ -233,3 +235,8 @@ Again, `formData.getAll()` is often all you need, we encourage you to give it a [query_string]: https://npm.im/query-string [ramda]: https://npm.im/ramda [watch_on_youtube]: https://www.youtube.com/watch?v=w2i-9cYxSdc&ab_channel=Remix +[submitevent-submitter]: https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent/submitter +[formdata-submitter]: https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData#submitter +[polyfill-event-submitter]: https://github.com/idea2app/event-submitter-polyfill +[polyfill-formdata-submitter]: https://github.com/jenseng/formdata-submitter-polyfill +[remix-submitter-issue]: https://github.com/remix-run/remix/issues/9704