-
Notifications
You must be signed in to change notification settings - Fork 625
fix: artifacts code not streaming #732
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -162,7 +162,7 @@ const appVersion = ref('') | |||||||||||||||||||||||||||||||||||||||||||||||||||
| const codeLanguage = ref( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| artifactStore.currentArtifact?.language || artifactStore.currentArtifact?.type || '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { createEditor, updateCode } = useMonaco() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { createEditor, updateCode } = useMonaco({ MAX_HEIGHT: '500px' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const codeEditor = ref<any>(null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 创建节流版本的语言检测函数,1秒内最多执行一次 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -176,24 +176,29 @@ const throttledDetectLanguage = useThrottleFn( | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| watch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => artifactStore.currentArtifact, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 如果当前 artifact 的语言已经被检测过了,就不再进行检测 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| codeLanguage.value = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| artifactStore.currentArtifact?.language || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFileExtension(artifactStore.currentArtifact?.type || '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (newArtifact) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!newArtifact) return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Update language detection | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| codeLanguage.value = newArtifact.language || getFileExtension(newArtifact.type || '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (codeLanguage.value === 'mermaid') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newCode = artifactStore.currentArtifact?.content || '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newCode = newArtifact.content || '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if we need to detect language | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!codeLanguage.value || codeLanguage.value === '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| throttledDetectLanguage(newCode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateCode(artifactStore.currentArtifact?.content || '', codeLanguage.value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Always update Monaco editor content | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateCode(newCode, codeLanguage.value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| immediate: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| immediate: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| deep: true // Add deep watching to catch property changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+179
to
+201
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid duplicate Monaco updates and remove unnecessary deep watch This watcher sets language and also pushes content to Monaco; combined with the dedicated content watcher and the language watcher, this causes double/triple Apply: - // Always update Monaco editor content
- updateCode(newCode, codeLanguage.value)
+ // Defer editor updates to dedicated content/language watchers to avoid duplicate updates
},
{
- immediate: true,
- deep: true // Add deep watching to catch property changes
+ immediate: true
}Additionally, consider only updating the ref when the computed language actually changes: const nextLang = newArtifact.language || getFileExtension(newArtifact.type || '')
if (nextLang !== codeLanguage.value) codeLanguage.value = nextLang🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -209,6 +214,19 @@ watch( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add a specific watcher for content changes to ensure real-time updates | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| watch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => artifactStore.currentArtifact?.content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (newContent) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (newContent !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateCode(newContent, codeLanguage.value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| immediate: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+217
to
+228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Content watcher updates Monaco for mermaid and before editor init; add guards and skip no-op updates Currently this watcher will:
Apply: -watch(
- () => artifactStore.currentArtifact?.content,
- (newContent) => {
- if (newContent !== undefined) {
- updateCode(newContent, codeLanguage.value)
- }
- },
- {
- immediate: true
- }
-)
+watch(
+ () => artifactStore.currentArtifact?.content,
+ (newContent, oldContent) => {
+ if (newContent === undefined || newContent === oldContent) return
+ if (codeLanguage.value === 'mermaid') return
+ if (!codeEditor.value) return
+ updateCode(newContent, codeLanguage.value)
+ }
+)This keeps streaming updates responsive while preventing invalid mermaid pushes and pre-init updates. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| watch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => codeEditor.value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.