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.

Uncaught TypeError: n.setAttribute is not a function when ssr client-side hydration

See original GitHub issue

Version

2.6.10

Reproduction link

https://github.com/yinxin630/vue-issue-example

Steps to reproduce

  1. clone and npm i
  2. run npm run build and npm run build:ssr
  3. run node src/ssr.js
  4. render app.js with ssr get result
<div id="app" data-server-rendered="true"><!----><h2>2222222222</h2></div>
  1. open in browser. client-side hydration will throw error Uncaught TypeError: n.setAttribute is not a function

What is expected?

client-side hydration success

What is actually happening?

throw error Uncaught TypeError: n.setAttribute is not a function


I found this when debug. vue call n.setAttribute('class', 'm-image-padding') but n is a comment node.

In app.js I use v-if. It will be true when ssr but be false when csr.

I don’t know if there is something wrong with my usage or the logic of vue client-side hydration.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
jigs1996commented, Jul 23, 2021

@kirkins I have this same issue on production mode but not on dev mode

Yes i have same issue any suggestion

2reactions
johndoudoucommented, Oct 22, 2021

I have the exact same problem, a value is false on ssr, true on csr, I have a v-if to display or not a NuxtLink. Upon hydration, console displays TypeError: el.setAttribute is not a function.

Note :

  • I’m running the project through yarn dev
  • I can simply fix the problem using v-show instead of v-if
  • I have to refresh the page to see the error : if I navigate through my app using the router, all is fine
  • And MOST IMPORTANTLY, i do not have the problem if the v-if has a corresponding v-else
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: setAttribute is not a function in JavaScript
To solve the "setAttribute is not a function" error, make sure to only call the setAttribute method on valid DOM elements and place...
Read more >
VueJS2 - SSR - Select element - setAttribute is not a function
n.setAttribute is not a function​​ But everything appears to be standard vue code when it comes to my component code above using the...
Read more >
Starsgeometry[0].Setattribute Is Not A Function - ADocLib
Uncaught TypeError : Cannot read property 'setAttribute' of null. By: LazarusRisingin that case the element doesn't exist yet in the. We can use...
Read more >
error - typeerror: render is not a function contextapi - You.com
Faced TypeError: render is not a function when using Context API ... open in browser. client-side hydration will throw error Uncaught TypeError: n....
Read more >
javascript - this.setAttribute is not a function - Stack Overflow
To fix the context issue you can replace Update checkForMatch() with checkForMatch.bind(this)(); but you also seem to have another issue in ...
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