flurry
@flurry asked:

Have you written any posts on how you handle injecting code in your Cohost userscripts? I'm mainly curious about how you choose your IDs for injecting into loadable-components, and if you've had any issues with SSR hydration. I feel like I constantly run into the latter when trying to use a MutationObserver.

Great question! No, I haven't. I lowkey forgot I had cohost userscripts, and I assume you're talking about my contributions to @mintexists's Markdown Plus userscript since my other one is dead.
The IDs are just big random numbers basically, they should just not collide with any cohost chunk or other userscript chunk. The injection isn't super loadable-components specific, it's mostly just webpack stuff.
I don't think any userscript I've written has touched SSRed components? but yeah hydration is a fuck, my advice is probably to just... wait for react to hydrate before you run your stuff? maybe check by doing something like Object.keys(document.getElementById("app")).find(k => k.startsWith("__react"))


You must log in to comment.

in reply to @easrng's post:

I don't think any userscript I've written has touched SSRed components?

Oh, interesting! I assumed the entire DOM tree below #app was from SSRed components.

For some reason when I try to add/remove elements, it occasionally causes a rehydrate to occur, and my script would have a back-and-forth with React until it gave up. I'll have to see if I'm running before hydration completes though.

Thank you!