Skip to content

Consecutive v-if stop reactive properties #127

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

Closed
Tronix117 opened this issue Mar 6, 2018 · 3 comments
Closed

Consecutive v-if stop reactive properties #127

Tronix117 opened this issue Mar 6, 2018 · 3 comments
Labels

Comments

@Tronix117
Copy link
Contributor

Tronix117 commented Mar 6, 2018

Whenever in the same hierarchy, there are multiple v-if, and a v-if become true, all reactive properties stop working altogether. This means all Vue reactive properties does not work anymore in the entire app, even if the page is destroyed. The only way is to reload the app.

As a workaround:v-if along v-else-if or v-else are not affected, v-show is also not affected.

The bug has been reproduced by @rigor789 .


This causes the issue:

Page
  StackLayout
    Label(
      v-if="foo"
      text="Enable"
      @tap="foo = false"
    )

    Label(
      v-if="!foo"
      text="Disable"
      @tap="foo = true"
    )

However this is working:

Page
  StackLayout
    Label(
      v-if="foo"
      text="Enable"
      @tap="foo = false"
    )

    Label(
      v-else
      text="Disable"
      @tap="foo = true"
    )

And this is also working:

Page
  StackLayout
    Label(
      v-show="foo"
      text="Enable"
      @tap="foo = false"
    )

    Label(
      v-show="!foo"
      text="Disable"
      @tap="foo = true"
    )
@rigor789
Copy link
Member

Update: Looks like the difference between the working/non-working example (in terms of the render function) is that the working v-if/v-else code generates a render function like so:

[
 (foo) ? _c(Enable) : _c(Disable)
]

(shortened here), while the consecutive v-if version generates

[
  (foo) ? _c(Enable) : _e(),
  (!foo) ? _c(Disable) : _e(),
]

_e() creates an empty VNode, which is represented as a CommentNode (or TextNode - can't remember).

The issue lies in the logic of insertBefore which tries to insert before the empty VNode.

I need to re-visit the whole renderer - which will take some time, but at least the cause is now known!

@msaelices
Copy link

@rigor789 I'm not sure if the fix is completely working. Sometimes if you remove and add a vnode from the tree the order change!

msaelices added a commit to msaelices/nativescript-vue that referenced this issue Jun 22, 2018
…does weird change the components order and I think is because nativescript-vue#127 is not completely fixed.
msaelices added a commit to msaelices/nativescript-vue that referenced this issue Jun 22, 2018
…does weird change the components order and I think is because nativescript-vue#127 is not completely fixed.
rigor789 added a commit that referenced this issue Jul 4, 2018
* feat (wrap ns components): Wrap the Label NS component into a Vue's one.

* feat (wrap ns components): Refactor the way that the Vue components are registered.

* feat (wrap ns components): New registerComponent function which would be the way to wrap and register new NS and Vue components.

* feat (wrap ns components): Wrap a Vue component if no component is passed to the registerComponent function. Refactored Label component as it's the simpler case to refactor.

* feat (wrap ns components): Begin an sample app with all the components. For now only the Label one.

* feat (wrap ns components): Make v-model work also in the automatically wrapped Vue components. Register DatePicker.

* feat (wrap ns components): Add DatePicker component to the app-with-all-components app

* feat (wrap ns components): Better not using v-bind and v-on shorthands here.

* feat (wrap ns components): Another way for wrapping components which is not working yet.

* feat (wrap ns components): Some fixes following the @rigor789 guidelines

* feat (wrap ns components): Fix a typo.

* feat (wrap ns components): Debug the label component internals.

* feat (wrap ns components): Fix some typos.

* feat (wrap ns components): no need for return the entry.

* feat (wrap ns components): Change a second v-if to v-else because it does weird change the components order and I think is because #127 is not completely fixed.

* feat (wrap ns components): Some fixes.

* feat (wrap ns components): Fix the render function for wrapped components.

* feat (wrap ns components): In order to keep the $refs, we pass the context.data object entirely to the component.

* feat (wrap ns components): Wrap DatePicker and Button elements. Add them to the test app.

* feat (wrap ns components): Destructured render function.

* feat: wrap all elements in a functional vue component

BREAKING CHANGE: All elements are now Vue components, in some cases where a ref is used to get the
nativeView will have to be updated to use `this.$refs.element.$el.nativeView` instead of
`this.$refs.element.nativeView`. There may be other breaking changes this introduces that are not
known at this point.

re #266 re #241

* test: update expectations for normalized element names
@nativescript-vue-bot
Copy link
Collaborator

We are locking this issue because it has been closed for more than 14 days.

If the issue comes up again please open a new issue with additional details.

@nativescript-vue nativescript-vue locked as resolved and limited conversation to collaborators Jul 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants