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.

Rendering issues when used with ES6 / prototypes

See original GitHub issue

Hey! Using yo-yo in a project with ES6 classes: we have Core and Plugins, and each plugin is inheriting from a Plugin class, which serves a boilerplate. Using super and extend keywords, which is relevant, because the issue goes away without those. Everything gets transpiled down to ES5 with Babel.

Sometimes yo-yo won’t render an element that was created in a constructor with this, like so:

import yo from 'yo-yo'

export class Smth extends Plugin {
  constructor (core, opts) {
    super(core, opts)
    this.strange = yo`<h1>this is strange 1</h1>`
  }

  render (state) {
    const bla = yo`<h2>this is strange 2</h2>`
    return yo`
      <div class="wow-this-works">
        <input type="text" value="hello">
        ${this.strange}
        ${bla}
      </div>
    `
  }

  install () {
    this.getTarget(this.opts.target, this, this.render)
  }
}

<h1>this is strange 1</h1> gets rendered while <h2>this is strange 2</h2> does not. If you move this.strange from the constructor to render function, it works. If you console.log the elements, they always show up in the console. Also, it works if you wrap yo call in a function, like this.strange = function () { return yo'<h1>this is strange 1</h1>' }

And I would think it’s totally this and class issues, except — wait for it — when you replace h2 with h1, it works. Different elements won’t render, but if two of the same are used — it works.

Here is a diff of two transpiled examples: https://www.diffchecker.com/ngpc5whl (the one on the left works, the one on the right does not), and are screenshots:

screen shot 2016-05-31 at 17 01 47 screen shot 2016-05-31 at 17 02 22

I thought maybe someone who wrote bel and knows internals will understand what’s going on here. Where should we even look? Sorry for complicated explanation and thanks in advance.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
arturicommented, Jun 1, 2016

Thanks for willing to help! Sure, we have the repo on GitHub:

  1. git clone -b new-build https://github.com/transloadit/uppy/
  2. npm install
  3. npm run watch
  4. Open example/index.html in the browser, the Modal dialog with the example I mentioned should pop up.
  5. Edit src/plugins/Dummy.js and refresh the browser tab to see changes.
1reaction
yoshuawuytscommented, May 31, 2016

Thanks for opening this issue! Ummmm, off the top of my head I have literally no idea what could be causing this - are you using yo-yoify at all? What about babel?

This probably definitely needs deeper research to figure out; would you mind setting up a quick repro so we can plough through it? Thanks!

edit: @shama jinx!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ES6 prototype method map rendered nothing in React
Anything wrong with my map method? ... Couldn't see anything rendered, checked the console, no error found. ... .map() is array`s prototype method....
Read more >
Prototype. The big bro behind ES6 class. - wanago.io
Objects do not have a class or type that they get their properties from: they use prototypes for it. In other languages, a...
Read more >
Object prototypes - Learn web development | MDN
This article has covered JavaScript object prototypes, including how prototype object chains allow objects to inherit features from one ...
Read more >
You Don't Know JS: this & Object Prototypes - GitHub Pages
There are still some deep and profoundly troubling issues with using “classes” as a design pattern in JS. Firstly, the class syntax may...
Read more >
As a JS Developer, This Is What Keeps Me Up at Night - Toptal
Did ES6 classes help or just muddy the waters? ... The Trouble with ES6 Classes ... it's only a question of whether ES6...
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