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.

Cannot read property 'parentNode' of null error in Polymer 2

See original GitHub issue

Hi Nathan, thank you for the great tool which works pretty good in HTML files. However when I tried it in a Polymer 2 element I mocked-up, I couldn’t get it work and keep encountering the error of Cannot read property 'parentNode' of null.

I tried to put code

Split(['#column-tag-list', '#column-repo-list', '#column-repo-page'], {
	sizes: [25,25,50],
	minSize: [300, 300, 960],
	gutterSize: 5
});

anywhere but the parentNode of null keeps showing up.

I guess it’s due to Split() could not find the nodes neither their parent before the shadow DOM are ready, therefore, I put the Split([]) code in the ready(){} method of the definition class as the following, it didn’t work neither.

Please help on how to use it in Polymer 2 properly. Thanks!

<dom-module id="pol-app">
	<template>
		<style>
			...
		</style>
		<div class="app-container">
			<div id="column-tag-list" class="column">
				...
			</div>
			<div id="column-repo-list" class="column">
				...
			</div>
			<div id="column-repo-page" class="column">
				...
			</div>
		</div>
	</template>
	<script src="../../bower_components/Split.js/split.min.js"></script>
	<script>
		class PolApp extends Polymer.Element {
			static get is() { return 'pol-app'; }
			static get properties() {
				return {
					...
				};
			}
			...
			constructor() {
				super();
				this.rootPattern = (new URL(this.rootPath)).pathname;
			}

			ready() {
				console.log('Hi Split.');
				Split(['#column-tag-list', '#column-repo-list', '#column-repo-page'], {
					sizes: [25,25,50],
					minSize: [300, 300, 960],
					gutterSize: 5
				});
			}
			...
		}

		window.customElements.define(PolApp.is, PolApp);
	</script>
</dom-module>

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
skyjiacommented, Jun 7, 2017

This could work.

ready() {
  super.ready();
  const that = this;
  
  ...

  setTimeout(function () {
    Split(
      [
        that.shadowRoot.querySelector('#column1'),
        that.shadowRoot.querySelector('#column2'),
        that.shadowRoot.querySelector('#column3')
      ],
      options);
  }.bind(this), 0);
}

The ready callback, for one-time initialization, signals the creation of the element’s shadow DOM. In the case of class-based elements, you need to call super.ready() before accessing the shadow tree.

To check the initial distribution, use setTimeout or requestAnimationFrame from ready. The callback should fire after initial distribution is complete.

https://www.polymer-project.org/2.0/docs/upgrade#callback-contracts-have-changed https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/

0reactions
wanghaileicommented, Jun 7, 2017

@nathancahill I tried window.document.querySelector('#column-tag-list'), and it didn’t work.

@skyjia that.shadowRoot.querySelector('#column1') works. And the setTimeout() is necessary when used Split() in Polymer 2.

Thanks, guys!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'parentNode' of null error in Polymer 2 #86
Hi, which version of Split.js are you using? The error sounds like those elements are not being found in the document.
Read more >
Javascript error: Cannot read property 'parentNode' of null
There are two possibilities: editInput is a typo, and the actual id of that element is different (ids are case-sensitive).
Read more >
Sidenav has error : Cannot read property &#38;#039;parentNod
Hi,. You have added option data-mdb-scroll-container="#scrollContainer" which points to the #scrollContainer element that is not present in your HTML.
Read more >
Cannot read property 'length' of undefined in grid.$connector.
Hey there :) We're setting up a grid where the user is able to filter items which are related to brands. One filter...
Read more >
"Cannot read property parentNode" error - Vue Forum
Given the mention of parentNode in the error message, my only guess would be that it is somehow related to the use of...
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