NextJs integration support
See original GitHub issueWhen loading a page with a player on localhost, a TypeError: Cannot read properties of null (reading 'getAttribute')
error pops up.
To Reproduce
Steps to reproduce the behavior:
- Place a video on a page using a Plyr player.
- Navigate from one route (without a player) to another (with a player)
Expected Behavior
No popup error.
Screenshots
Desktop (please complete the following information):
- Stack: Next.js, React, Localhost
- OS: macOS
- Browser: Chrome
- Version: 102.0.5005.115 (Official Build) (x86_64)
Additional Context
- Using
plyr-react
as a dependency in a transpiled Next.js module. - The local environment is using a custom hosts domain: “example.local:3000” instead of “localhost:3000”.
- Does not occur on staging (hosted on Vercel).
- Doesn’t occur every single time.
- It’s possible it only occurs the first time a page is built in the .next folder. Try removing the .next folder and running the dev environment again to see it happening when navigating from one route to another as explained above.
Component Source Code
import Plyr from 'plyr-react';
import { Box } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import 'plyr-react/dist/plyr.css';
const Player = ({
src,
type = 'video',
provider = 'youtube',
sources,
sx,
...props
}) => {
const theme = useTheme();
return (
<Box
sx={{
'--plyr-color-main': theme.palette.primary.main,
borderRadius: `${theme.shape.borderRadius}px`,
overflow: 'hidden',
...sx,
}}
>
<Plyr
source={{
type,
sources: sources || [
{
src: src,
provider: 'youtube',
},
],
}}
{...props}
/>
</Box>
);
};
export default Player;
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Testing | Next.js
Learn how to set up Next.js with three commonly used testing tools — Cypress, Playwright, Jest, and React Testing Library.
Read more >Advanced Features: Custom Server - Next.js
A custom Next.js server allows you to start a server 100% programmatically in order to use custom server patterns. Most of the time,...
Read more >Next.js by Vercel - The React Framework
Next.js gives you the best developer experience with all the features you need for production: hybrid static & server rendering, TypeScript support, ...
Read more >Getting Started | Next.js
System Requirements. Node.js 14.6.0 or newer; MacOS, Windows (including WSL), and Linux are supported. Automatic Setup. We recommend creating a new Next.js ......
Read more >API Routes: Introduction - Next.js
Next.js supports API Routes, which allow you to build your API without leaving your Next.js app. Learn how it works here.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Whoever wrote that blog post using GPT to sell their book at the end… amateur 🤣
Hey @haluvibe , the only non-serverside action I’m suspicious of it is about this line: https://github.com/chintan9/plyr-react/blob/f5d6ab7b26fc4335b8eca499001369c77495cdfd/src/index.tsx#L38
But the error and our last investigation show that the problem was related to the plyr itself. Even when I used the next dynamic import with
ssr: false
on the custom Plyr wrapper component it didn’t work well.Any try-out or suggestions for fixing this issue is pleased