Skip to content

Commit f10a657

Browse files
committed
fix: resolve NoStoryMatchError in Storybook and address TypeError in RootProvider.vue
- Updated Storybook configuration to correctly handle path aliases for components. - Diagnosed and fixed TypeError related to `Collapsible.RootProvider` by ensuring proper unwrapping of computed values. - Implemented checks to prevent accessing properties of undefined in the RootProvider component. - Enhanced error handling and added guards in the template to ensure components render only when API values are available.
1 parent 0c6cecf commit f10a657

File tree

2 files changed

+579
-9
lines changed

2 files changed

+579
-9
lines changed

.specstory/history/2025-11-11_00-47Z-解决-storybook-中的-nostorymatcherror-错误.md

Lines changed: 130 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ PreviewWithSelection @ storybook_internal_preview_runtime.js?v=9aef49a6:44719
2626
PreviewWeb @ storybook_internal_preview_runtime.js?v=9aef49a6:45384
2727
(anonymous) @ vite-app.js:27
2828

29+
2930
---
3031

3132
_**Agent (model copilot/claude-sonnet-4.5)**_
3233

33-
我来帮你解决这个 Storybook 错误。错误提示找不到 story `'components-collapse--basic'`。让我先检查一下当前的 story 文件结构。 问题在于你的 story 文件只定义了 default export,但没有导出任何具名的 story。Storybook 需要具名导出来创建实际的 story。我来修复这个文件:
34+
我来帮你解决这个 Storybook 错误。错误提示找不到 story `'components-collapse--basic'`。让我先检查一下当前的 story 文件结构。 问题在于你的 story 文件只定义了 default export,但没有导出任何具名的 story。Storybook 需要具名导出来创建实际的 story。我来修复这个文件:
3435
```
3536
3637
```
@@ -43,28 +44,38 @@ _**Agent (model copilot/claude-sonnet-4.5)**_
4344

4445
---
4546

46-
_**User (2025-11-11 01:19Z)**_
47+
_**User (2025-11-11 01:22Z)**_
4748

4849
这是为什么
4950

5051
```
51-
[Vue warn]: Property "asChild" was accessed during render but is not defined on instance.
52-
at <Root defaultValue= ['Vue'] >
53-
at <Basic>
54-
at <Anonymous>
55-
at <Anonymous>
52+
[Vue warn]: Property "asChild" was accessed during render but is not defined on instance.
53+
at <Root defaultValue= ['Vue'] >
54+
at <Basic>
55+
at <Anonymous>
56+
at <Anonymous>
5657
at <App>
5758
```
5859

5960
---
6061

6162
_**Agent (model copilot/claude-sonnet-4.5)**_
6263

63-
这个警告是因为 `Root` 组件使用了 `asChild` 属性但没有正确定义。让我检查一下相关的组件代码: 我看到问题了。在 `Root.vue` 的模板中使用了 `asChild`,但这个属性来自 `PolymorphicProps`,需要在 props 中访问。让我检查一下 `PolymorphicProps` 的定义: 现在我明白了。问题是在模板中直接使用 `asChild` 变量,但应该使用 `props.asChild`。让我修复这个问题:
64+
这个警告是因为 `Root` 组件使用了 `asChild` 属性但没有正确定义。让我检查一下相关的组件代码: 我看到问题了。在 `Root.vue` 的模板中使用了 `asChild`,但这个属性来自 `PolymorphicProps`,需要在 props 中访问。让我检查一下 `PolymorphicProps` 的定义: 现在我明白了。问题是在模板中直接使用 `asChild` 变量,但应该使用 `props.asChild`。让我修复这个问题:
65+
```
66+
67+
```
68+
让我检查其他组件是否也有同样的问题: 还有其他组件也有同样的问题。让我逐个修复它们: 现在我需要修复所有这些组件,将 `asChild` 改为 `props.asChild`
69+
```
70+
71+
```
72+
73+
```
74+
6475
```
6576

6677
```
67-
让我检查其他组件是否也有同样的问题: 还有其他组件也有同样的问题。让我逐个修复它们: 现在我需要修复所有这些组件,将 `asChild` 改为 `props.asChild`
78+
6879
```
6980

7081
```
@@ -77,16 +88,126 @@ _**Agent (model copilot/claude-sonnet-4.5)**_
7788

7889
```
7990
91+
```
92+
让我重新检查并修复 ItemIndicator.vue: 我需要将 `defineProps` 改为带 `const props =` 的形式:
93+
```
94+
95+
```
96+
现在让我检查是否还有其他 collapsible 组件也有同样的问题: collapsible 组件也有同样的问题。让我一并修复:
97+
```
98+
99+
```
100+
80101
```
81102
82103
```
83104

84105
```
85106
107+
```
108+
还需要检查是否还有 Trigger 组件: Trigger 组件没有使用 `asChild`,所以不需要修改。让我检查一下错误是否还有其他地方: 还有 Presence 组件。让我修复它:
86109
```
87110
88111
```
112+
完成!我已经修复了所有组件中的 `asChild` 属性访问问题。
113+
114+
**问题根源:**
115+
在 Vue 3 的 `<script setup>` 中,模板无法直接访问 `defineProps` 返回的属性名(如 `asChild`),必须通过 `props` 对象来访问(如 `props.asChild`)。
116+
117+
**修复的文件:**
118+
1.`Root.vue`
119+
2.`RootProvider.vue`
120+
3.`ItemIndicator.vue`
121+
4.`ItemContent.vue`
122+
5.`ItemTrigger.vue`
123+
6.`Root.vue`
124+
7.`RootProvider.vue`
125+
8.`Content.vue`
126+
9.`Presence.vue`
127+
128+
现在刷新浏览器,警告应该消失了。
129+
130+
---
131+
132+
_**User (2025-11-12 04:17Z)**_
133+
134+
好像会出现这个问题
89135

136+
```
137+
Neither '~/factory.vue' nor '~/factory.js(x)' or '~/factory/index.js(x)' or '~/factory/index.ts(x)' could be found in '/Users/elonehoo/Developer/destyler-dev/ui/packages/vue/src/components/collapse/components'
138+
Neither '~/composables.vue' nor '~/composables.js(x)' or '~/composables/index.js(x)' or '~/composables/index.ts(x)' could be found in '/Users/elonehoo/Developer/destyler-dev/ui/packages/vue/src/components/collapse/components'
90139
```
91140

92141
---
142+
143+
_**Agent (model copilot/claude-sonnet-4.5)**_
144+
145+
这个问题是路径别名 `~` 解析失败。让我检查一下项目的配置和当前文件: 配置看起来是正确的。让我检查 Storybook 的配置: 问题在于 Storybook 没有配置路径别名。我需要在 Storybook 的配置中添加 Vite 的别名配置:
146+
```
147+
148+
```
149+
完成!我已经在 Storybook 的配置文件中添加了路径别名配置。
150+
151+
**修复说明:**
152+
-`main.ts` 中添加了 `viteFinal` 钩子
153+
- 配置了与项目主配置相同的路径别名 `~/` 指向 `src/` 目录
154+
- 这样 Storybook 就能正确解析 `~/factory``~/composables` 等导入路径
155+
156+
现在需要重启 Storybook 服务器,路径解析问题就会解决。如果 Storybook 正在运行,请重新启动它。
157+
158+
---
159+
160+
_**User (2025-11-12 04:18Z)**_
161+
162+
还是有这个问题
163+
164+
```
165+
Neither '~/composables.vue' nor '~/composables.js(x)' or '~/composables/index.js(x)' or '~/composables/index.ts(x)' could be found in '/Users/elonehoo/Developer/destyler-dev/ui/packages/vue/src/components/collapse/components'
166+
Neither '~/factory.vue' nor '~/factory.js(x)' or '~/factory/index.js(x)' or '~/factory/index.ts(x)' could be found in '/Users/elonehoo/Developer/destyler-dev/ui/packages/vue/src/components/collapse/components'
167+
```
168+
169+
---
170+
171+
_**Agent (model copilot/claude-sonnet-4.5)**_
172+
173+
让我检查一下实际的文件结构,确认 `~/composables``~/factory` 是否存在: 文件都存在。问题可能是 Storybook 没有重启。但让我先检查一下在组件中是如何导入的,以及 `.storybook` 目录中是否还有其他配置文件: 路径使用正确。让我查看当前的 `main.ts` 文件内容,确保修改已正确保存: 配置看起来正确。让我检查一下是否还需要导入类型。另外,让我看看 Storybook 的 preview 配置: 问题可能是别名配置的方式。让我尝试另一种配置方法,使用完整的 Vite 配置导入:
174+
```
175+
176+
```
177+
让我修复导入顺序:
178+
```
179+
180+
```
181+
现在配置已更新。关键更改:
182+
1. 使用 `mergeConfig` 来合并配置,这是更标准的做法
183+
2. 别名改为 `'~': path.resolve(...)` 而不是 `'~/': ...`(去掉了尾部斜杠)
184+
185+
**请重启 Storybook 服务器**以使配置生效。如果仍有问题,可能需要清除缓存:
186+
187+
```bash
188+
rm -rf node_modules/.vite
189+
rm -rf node_modules/.cache
190+
```
191+
192+
然后重新启动 Storybook。
193+
194+
---
195+
196+
_**User (2025-11-13 01:49Z)**_
197+
198+
#createFile the plan as is into an untitled file (`untitled:plan-${camelCaseName}.prompt.md` without frontmatter) for further refinement.
199+
200+
---
201+
202+
_**Agent (model copilot/gpt-5-codex)**_
203+
204+
I need more context about what plan you're referring to. Could you please clarify:
205+
206+
1. What plan should I create into an untitled file?
207+
2. Is there a specific plan or content from our previous conversation that you'd like me to document?
208+
3. What should the camelCaseName be for the file?
209+
210+
If you're referring to the fixes we made for the Storybook and Vue component issues, I can create a summary of those changes. Please let me know what specific content you'd like in the plan file.
211+
212+
---
213+

0 commit comments

Comments
 (0)