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.

Component extends another component lost its extended methods after hot reload

See original GitHub issue

Description

Component A is defined in a .vue file, and component B is defined in a .js file that extends A. After changing the <script> section of A, B is reloaded but it lost what is extended (for the example below, test() will be gone).

import Vue from 'vue'
import component from './component'

export default Vue.extend({
  extends: component,
  methods: {
    test () {           // test will be lost!
      alert('test!')
    }
  }
})

What is expected

Component B is correctly reloaded.

Reproduction repo

https://github.com/hjkcai/vue-hot-reload-api-issue

Reproduction steps

Edit changeThis() method or any part of the <script> section in component.vue. The console will show the error after hot reload.

What I have found

I tried to step into vue-hot-reload-api to find out this question. It seems that component A and B share the same entry in the map object, which means they have the same data ID (data-v-xxxxxx). After hot reload, the constructor of B is recreated with the options of A. Maybe that is why component B is reloaded without its own methods?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
mikerockettcommented, May 13, 2020

I tried the suggestion(s) above a little while ago, to no avail. Not sure how else to fix the issue with the limited knowledge I have in regards to how the cogs work internally.

Pinging @yyx990803 – I know your focus is currently on a bunch of other things, and I also know that not many others are bringing this issue up, but is there any chance you could take a look at it? Thanks!

1reaction
silverprizecommented, Oct 1, 2019

@scq Thank you!! I’ve fixed some problem in your code. record.Ctor is not Array that is Object. Works fine below code. Thanks again.

        var ctor
        if (options._Ctor) {
          var key = Object.keys(options._Ctor)[0]
          if (key) {
            ctor = options._Ctor[key]
          }
        }
        if (!ctor) {
          ctor = this.constructor
        }
        record.Ctor = ctor
Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot Reload not working in react-native android - Stack Overflow
class B extends React.Component ... Live Reload on the other hand, rebuilds your application and discards your application state. It includes ...
Read more >
Evan You on Twitter: "I still say to myself "jeez this is so fast" when ...
Component extends another component lost its extended methods after hot reload · Issue #68 ·... Description Component A is defined in a .vue...
Read more >
Hot Reload | Vue Loader
With hot reload enabled, when you edit a *.vue file, all instances of that component will be swapped in without reloading the page....
Read more >
Angular: Reload/Refresh a Component or Entire Application ...
Use inheritance to add this functionality inside a single component so that any other component can extend and reuse it. Let's first check...
Read more >
ASP.NET Core Razor components - Microsoft Learn
After the component is initially rendered, the component's render tree ... Create a different property or method to supply the transformed ...
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