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

[t-config-provider] vue3.4子组件inject globalConfig不具备响应式 #4611

Closed
aolyang opened this issue Sep 26, 2024 · 3 comments
Closed
Labels
to be published to be published

Comments

@aolyang
Copy link
Contributor

aolyang commented Sep 26, 2024

tdesign-vue-next 版本

1.10.1

重现链接

https://stackblitz.com/edit/angular-fvhxrp-77bkvd?file=package.json

重现步骤

任意 vue3.4以上的版本,用的另一个issue的连接。

期望结果

globalconfig具备响应,子组件国际化能通过globalconfig影响

实际结果

globalConfig无响应

框架版本

Vue3.4

补充说明

<script>
const globalConfig = computed(() => {
    return locale.value === "zh-CN" ? zhCN : enUS
})
</script>
<template>
  <TConfigProvider :globalConfig="globalConfig">
      <TAlert :max-line="2">
          <-- ... !-->
      </TAlert>
  </TConfigProvider>
</template>

devtools查看 config-provider 中的globalConfig是具备响应式的
本地组件手动inject也是可以的,但是 TAlert 中的不会变
最终定位是computed返回的对象保持了引用:

const defaultData = cloneDeep(defaultGlobalConfig);
const mergedGlobalConfig = computed(() =>
mergeWith(defaultData as unknown as GlobalConfigProvider, props.globalConfig),
);
provide(configProviderInjectKey, mergedGlobalConfig);

参考useConfig 本地node_modules手动修改测试可行:

-mergeWith(defaultData as unknown as GlobalConfigProvider, props.globalConfig),
+Object.assign({}, mergeWith(defaultData as unknown as GlobalConfigProvider, props.globalConfig)),
Copy link
Contributor

👋 @aolyang,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@aolyang aolyang changed the title [t-config-provider] globalConfig在inject后丢失响应式 [t-config-provider] vue3.4子组件inject globalConfig不具备响应式 Sep 26, 2024
@aolyang
Copy link
Contributor Author

aolyang commented Sep 26, 2024

相关issue #3854

quick fix: 使用patch功能,修改(es/esm/cjs/lib)的useConfig.mjs 文件,⚠ 注意是否使用了AutoImport插件

var provideConfig = function provideConfig(props) {
  var defaultData = cloneDeep_1(defaultGlobalConfig);
  var mergedGlobalConfig = computed(function () {
-    return mergeWith(defaultData, props.globalConfig);
+    return Object.assign({}, mergeWith(defaultData, props.globalConfig));
  });
  provide(configProviderInjectKey, mergedGlobalConfig);
  if (!globalConfigCopy.value) {
    globalConfigCopy.value = mergedGlobalConfig.value;
  }
  return mergedGlobalConfig;
};

@uyarn uyarn added the to be published to be published label Sep 27, 2024
@uyarn uyarn closed this as completed Sep 28, 2024
@uyarn
Copy link
Collaborator

uyarn commented Sep 28, 2024

fixed 1.10.2

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

No branches or pull requests

2 participants