question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NextJs integration support

See original GitHub issue

When 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:

  1. Place a video on a page using a Plyr player.
  2. Navigate from one route (without a player) to another (with a player)

Expected Behavior

No popup error.

Screenshots

image

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:open
  • Created a year ago
  • Reactions:9
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
altechzillacommented, Dec 20, 2022

Whoever wrote that blog post using GPT to sell their book at the end… amateur 🤣

https://bobbyhadz.com/blog/javascript-cannot-read-property-getattribute-of-null

1reaction
realamirhecommented, Sep 23, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found