JupiterBroadcasting / jupiterbroadcasting.com

JupiterBroadcasting.com, hugo-based and community-driven!
https://jupiterbroadcasting.com
99 stars 49 forks source link

PeerTube JavaScript included on every page #328

Open reclaimingmytime opened 2 years ago

reclaimingmytime commented 2 years ago

When I look at the browser console on any page other than the live page (e.g. https://new.jupiterbroadcasting.com/sponsors/), I get the following error:

(index):102 Uncaught (in promise) TypeError: Cannot set properties of null (setting 'src')
    at (index):102:73

It seems to be that the code embedded in the jb-tube.html partial is included on every page, not just the live page.

https://github.com/JupiterBroadcasting/jupiterbroadcasting.com/blob/3216265083a3ea39b98950cc1443e49c4a981962/themes/jb/layouts/partials/live/jb-tube.html#L1

gerbrent commented 2 years ago

nice investigative work!

gerbrent commented 1 year ago

@elreydetoda : closed because solved by #425?

elreydetoda commented 1 year ago

Yes, @ChanceM 's #425 solved this by doing a query on each page to see if the liveStream id is present. Explained here: https://github.com/JupiterBroadcasting/jupiterbroadcasting.com/pull/425#pullrequestreview-1121249814

elreydetoda commented 1 year ago

Thinking about this again for a second, technically the #425 didn't "solve" every page loading the JS. It's just preventing the error from happening by checking if the expected embed element exists and only setting the .src attrib (which was causing the error) if it does.

So, I'd say it technically patched the issue not solved 😅

ChanceM commented 1 year ago

Thinking about this again for a second, technically the #425 didn't "solve" every page loading the JS. It's just preventing the error from happening by checking if the expected embed element exists and only setting the .src attrib (which was causing the error) if it does.

So, I'd say it technically patched the issue not solved 😅

Yeah the JB live is tied into this so rather than unravel them I just fixed it from attempting to set the src when the element wasn't on the page.

ozcoder commented 1 year ago

I think a better way is to detect the page it is going to be included in, and not including it in pages it shouldn't be on.

elreydetoda commented 1 year ago

I'll actually re-open this since it's not fully remediated then. Just so we don't lose track of doing a "proper" fix for it.

ChanceM commented 1 year ago

I'll actually re-open this since it's not fully remediated then. Just so we don't lose track of doing a "proper" fix for it.

I mean technically we could remove a few lines and copy the rest to another file, but then we would need to maintain the same code in two places, as the same query for the live show embed is used to mark the live menu item. I think this is a sane half measure to eliminate the error and either not maintain the code twice or add another file request to the pages.