Skip to content

Commit

Permalink
Update SubmitEvent Polyfill to Workaround Safari 15 bug (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
terracatta committed Sep 24, 2021
1 parent 157d423 commit a4a3033
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ interface Node {

interface Window {
Turbo: typeof import("./core/index")
SubmitEvent: typeof Event
}
15 changes: 13 additions & 2 deletions src/polyfills/submit-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ function clickCaptured(event: Event) {
}

(function() {
if ("SubmitEvent" in window) return
if ("submitter" in Event.prototype) return

let prototype;
// Certain versions of Safari 15 have a bug where they won't
// populate the submitter. This hurts TurboDrive's enable/disable detection.
// See https://bugs.webkit.org/show_bug.cgi?id=229660
if ("SubmitEvent" in window && /Apple Computer/.test(navigator.vendor)) {
prototype = window.SubmitEvent.prototype;
} else if ("SubmitEvent" in window) {
return; // polyfill not needed
} else {
prototype = window.Event.prototype;
}

addEventListener("click", clickCaptured, true)

Object.defineProperty(Event.prototype, "submitter", {
Object.defineProperty(prototype, "submitter", {
get(): HTMLElement | undefined {
if (this.type == "submit" && this.target instanceof HTMLFormElement) {
return submittersByForm.get(this.target)
Expand Down

0 comments on commit a4a3033

Please sign in to comment.