Last active
July 16, 2024 16:17
-
-
Save KonnorRogers/d9abe11599e23a45ff5aca83817983fe to your computer and use it in GitHub Desktop.
Catching hydration errors in Lit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyElement extends LitElement { | |
protected update(changedProperties: PropertyValues<this>): void { | |
try { | |
super.update(changedProperties) | |
} catch (e) { | |
// We should probably check the contents of the message since this could error on a regular update?? | |
// I really dont know. Its hacky, but it works. | |
const event = new Event("lit-hydration-error", { bubbles: true, composed: true, cancelable: false }) | |
// @ts-expect-error leave me alone TS. | |
event.error = e | |
this.dispatchEvent(event) | |
throw e | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment