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

嵌套组件会引起无限编译 #691

Closed
eaTong opened this issue Sep 25, 2018 · 7 comments
Closed

嵌套组件会引起无限编译 #691

eaTong opened this issue Sep 25, 2018 · 7 comments

Comments

@eaTong
Copy link

eaTong commented Sep 25, 2018

问题描述
写了两个组件:一个TaskItem.js 一个TaskChildren.js,然后内部代码会相互调用,然后npm run dev:weapp的时候控制台会持续输出如下信息:

tim 20180925161551

TaskItem

import Taro, {Component, navigateTo} from '@tarojs/taro'
import {View, Text, Input, Button, Icon, Progress} from '@tarojs/components';
import {emergentLevel, importantLevel} from '../utils/constants';
import {AtTag} from 'taro-ui';
import './taskItem.less'
import TaskChildren from "./TaskChildren";

export default class TaskItem extends Component {
  static options = {
    addGlobalClass: true
  };

  render() {
    const {task, isRoot} = this.props;
    const emergentItem = emergentLevel[task.emergent_level - 1];
    return (
      <View className={`task-item ${isRoot ? 'root' : ''}`} key="id">
        <View className="title-bar">
          <Text className={`tag tag-level-${task.emergent_level}`}>{emergentItem.label}</Text>
          <View className="title">{task.title}</View>
          <View className='percentage'>{`${task.complete_percent}%`}</View>
        </View>
        {task.children && task.children.length > 0 && (
          <TaskChildren childrenTasks={task.children}/>
        )}
      </View>
    );
  }
}

TaskChildren

import Taro, {Component, navigateTo} from '@tarojs/taro'
import {View, Text, Input, Button, Icon, Progress} from '@tarojs/components';
import TaskItem from "./TaskItem";
import './taskChildren.less'

export default class TaskChildren extends Component {
  static options = {
    addGlobalClass: true
  }
  render() {
    const {childrenTasks} = this.props;
    return (<View className="task-children">
      {childrenTasks.map(childTask => (<TaskItem task={childTask} key={childTask.id}/>))}
    </View>);
  }
}

期望行为
未改动文件的情况下不做更多编译

系统信息

  • 操作系统: Windows 10
  • Taro 版本 v1.0.3
  • Node.js 版本 v8.0.10
@eaTong eaTong changed the title windows下嵌套组件会引起无限编译 嵌套组件会引起无限编译 Sep 25, 2018
@eaTong
Copy link
Author

eaTong commented Sep 25, 2018

经测试,macOS也会存在相同的情况

@eaTong
Copy link
Author

eaTong commented Sep 25, 2018

进一步测试结果为:应用第一次编译的时候会出现,将taskItem中的TaskChildren相关代码禁用之后运行npm run dev:weapp之后再修改代码为继续引用,不会出现重复编译的情况

@luckyadam
Copy link
Member

不能这样循环依赖使用,换一种写法吧,一般尽量避免在代码里出现循环依赖

@eaTong
Copy link
Author

eaTong commented Sep 26, 2018

这样做的目的是为了实现树形结构,会有多个层级的情况出现,故而采用这种方式编码

@luckyadam
Copy link
Member

OJBK,我看下能不能解决~

@ldwonday
Copy link

这个问题的解决会导致小程序端报组件找不到,一个页面引入一个组件a,这个组件也会引用一个组件b,那么小程序端会报a找不到组件b。这个问题在1.1.0.beta2以前都没有问题,升级到3以后就有问题了。

@luckyadam
Copy link
Member

@ldwonday 86df1d9

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

No branches or pull requests

3 participants