Skip to content
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

fix(types): genChildren function with error normalizationType #9182

Closed
wants to merge 1 commit into from

Conversation

skyline0705
Copy link

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@skyline0705
Copy link
Author

bug fix for #9181

first I try to change function genChildren, and change normalizationType to ALWAYS_NORMALIZE, it works in my case

but when I try this code:

var vm = new Vue({
  el: '#demo',
  template: `
      <div>
        <foo v-for="item in list">
          {{ item }}
        </foo>
      </div>
  `,
  data: {
    list: undefined
  },
  components: {
    foo: {
      template: '<div><slot></slot></div>'
    },
  }
})

setTimeout(() => {
  vm.list = [1,2,3,4,5];
}, 1000);

I found it now works because the root element div has no attrs, and found the function createElement has an error params order;

so second I try to change file src/compiler/codegen/index
and change the function call _c, change the code

code = `_c('${el.tag}'${
    data ? `,${data}` : '' // data
  }${
    children ? `,${children}` : '' // children
  })`

to

code = `_c('${el.tag}'${
    data ? `,${data}` : ',undefined' // data
  }${
    children ? `,${children}` : '' // children
  })`

I think it will works, but…… the unit test shows that I'm wrong, there are many error 😭

finally I fix the renderList function, let it always return an array, and everything goes well……

I know use an undefined value in v-for is invalid, but before v2.5.16, it works well, I think it should be warn in the next version like v2.6.x, and should keep work in v2.5.x

@yyx990803
Copy link
Member

I think it's better to handle it directly in simpleNormalizeChildren - it avoids allocating empty array on each render and allows the diff algorithm to take a faster path.

See 4748760

@yyx990803 yyx990803 closed this Dec 11, 2018
@yyx990803
Copy link
Member

Ended up using your fix in 847e493 when trying to apply additional optimization for the case... sorry!

@skyline0705
Copy link
Author

Ok~ No problem~~And another thing, the fundamental cause of this is because the params order at function createElement, that is why I finally decided to change function renderList: the createElement calls are too flexible😂.

maybe there need a little more test case of compile template, like the test case components with v-for and empty list, root element has no attrs I added before. the steps is on the last comment #9182 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants