Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of null if CSS is linked #751

Closed
tzwel opened this issue Dec 20, 2023 · 2 comments
Closed

Cannot read properties of null if CSS is linked #751

tzwel opened this issue Dec 20, 2023 · 2 comments

Comments

@tzwel
Copy link

tzwel commented Dec 20, 2023

I'm debugging this for over two hours already

const user = await prisma.User.findFirst({
	where: {
		publicId: req.params.userId
	}
})

console.log(user)

res.render('profile.ejs', {user})

This is the returned user object

  {
    id: 1,
    publicId: 'some id',
    username: '123',
    password: 'passwordhash'
  }

The user gets logged correctly (if the template is mostly empty), ejs renders the template correctly, but logs this error in the console:
Cannot read properties of null (reading 'id')

Once I add CSS into the template
<link rel="stylesheet" href="/card.css">
I get this error

 authorId: user.id
                                       ^

TypeError: Cannot read properties of null (reading 'id')

user.id becomes completely unusable everywhere and will just crash node

This is the weirdest bug i have ever encountered, I am not even sure if this is linked to ejs in any way. The bug seems to change its behavior in some random circumstances I can not pinpoint

@tzwel tzwel changed the title Cannot read properties of null but template renders correctly if CSS is linked Cannot read properties of null if CSS is linked Dec 20, 2023
@tzwel
Copy link
Author

tzwel commented Dec 20, 2023

Looks like this is unrelated to ejs and happens with jade and mustache as well
https://stackoverflow.com/questions/31329578/why-does-adding-a-css-link-to-my-jade-template-make-my-node-app-crash
https://stackoverflow.com/questions/57242584/page-crashes-whenever-i-link-a-css-stylesheet-on-one-file-but-doesnt-on-anothe

I'll keep this issue open for a while because there's no clear solution for this afaik

@tzwel
Copy link
Author

tzwel commented Dec 20, 2023

	<link rel="stylesheet" href="/card.css">

A single slash like this fixed the problem. Why, I have no idea

@tzwel tzwel closed this as completed Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant