Skip to content

Commit d3d8533

Browse files
committed
Source data generation fix
1 parent d24f7ee commit d3d8533

File tree

8 files changed

+105
-48
lines changed

8 files changed

+105
-48
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "devtools-monorepo",
33
"type": "module",
44
"scripts": {
5-
"build": "pnpm --parallel build",
5+
"build": "pnpm -r build",
66
"demo": "wdio run ./example/wdio.conf.ts",
77
"demo:nightwatch": "pnpm --filter @wdio/nightwatch-devtools example",
88
"dev": "pnpm --parallel dev",
@@ -18,7 +18,8 @@
1818
"pnpm": {
1919
"overrides": {
2020
"vite": "^7.3.0",
21-
"@types/node": "25.5.2"
21+
"@types/node": "25.5.2",
22+
"@codemirror/state": "6.5.4"
2223
},
2324
"ignoredBuiltDependencies": [
2425
"chromedriver"

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"stylelint-config-recommended": "^17.0.0",
4343
"stylelint-config-tailwindcss": "^1.0.1",
4444
"tailwindcss": "~4.2.2",
45+
"typescript": "6.0.2",
4546
"vite": "7.3.2"
4647
}
4748
}

packages/app/src/components/workbench/source.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Element } from '@core/element'
2-
import { html, css } from 'lit'
3-
import { customElement } from 'lit/decorators.js'
2+
import { html, css, type PropertyValues } from 'lit'
3+
import { customElement, state } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
55

66
import { EditorView, basicSetup } from 'codemirror'
@@ -28,45 +28,75 @@ export class DevtoolsSource extends Element {
2828
width: 100%;
2929
height: 100%;
3030
padding: 10px 0px;
31+
flex: 1;
32+
min-height: 0;
3133
}
3234
.cm-content {
3335
padding: 0 !important;
3436
}
3537
3638
.source-container {
39+
display: flex;
40+
flex-direction: column;
3741
width: 100%;
3842
height: 100%;
43+
overflow: hidden;
3944
}
4045
`
4146
]
4247

4348
@consume({ context: sourceContext, subscribe: true })
49+
@state()
4450
sources: Record<string, string> = {}
4551

4652
#editorView?: EditorView
4753
#activeFile?: string
54+
#tabObserver?: MutationObserver
4855

4956
connectedCallback(): void {
5057
super.connectedCallback()
5158
window.addEventListener(
5259
'app-source-highlight',
5360
this.#highlightCallSource.bind(this)
5461
)
62+
// Observe when the containing tab becomes active so CodeMirror can remeasure
63+
// after having been initialized while the tab was hidden (display:none).
64+
requestAnimationFrame(() => {
65+
const tab = this.closest('wdio-devtools-tab')
66+
if (tab) {
67+
this.#tabObserver = new MutationObserver(() => {
68+
if (tab.hasAttribute('active') && this.#editorView) {
69+
// Force CodeMirror to remeasure and re-render after becoming visible
70+
requestAnimationFrame(() => {
71+
this.#editorView?.requestMeasure()
72+
this.#editorView?.dom.dispatchEvent(new Event('resize'))
73+
})
74+
}
75+
})
76+
this.#tabObserver.observe(tab, { attributes: true, attributeFilter: ['active'] })
77+
}
78+
})
5579
}
5680

5781
disconnectedCallback(): void {
5882
super.disconnectedCallback()
5983
this.#editorView?.destroy()
6084
this.#editorView = undefined
85+
this.#tabObserver?.disconnect()
86+
this.#tabObserver = undefined
6187
}
6288

63-
updated() {
89+
updated(_changedProperties: PropertyValues<this>) {
6490
const sourceFileNames = Object.keys(this.sources || {})
6591
if (sourceFileNames.length === 0) {
6692
return
6793
}
68-
// Mount or refresh the editor for the first source file
69-
this.#mountEditor(sourceFileNames[0])
94+
// Respect an explicitly highlighted file; otherwise show the first available
95+
const targetFile =
96+
this.#activeFile && this.sources?.[this.#activeFile]
97+
? this.#activeFile
98+
: sourceFileNames[0]
99+
this.#mountEditor(targetFile)
70100
}
71101

72102
#mountEditor(filePath: string, highlightLine?: number) {
@@ -101,6 +131,11 @@ export class DevtoolsSource extends Element {
101131
this.#editorView = new EditorView(opts)
102132
this.#activeFile = filePath
103133

134+
// Force a measure on the next frame so CodeMirror can calculate heights
135+
// correctly — needed when the editor was created while the panel was hidden
136+
// or before layout was complete.
137+
requestAnimationFrame(() => this.#editorView?.requestMeasure())
138+
104139
if (highlightLine && highlightLine > 0) {
105140
this.#scrollToLine(this.#editorView, highlightLine)
106141
}

packages/app/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"extends": "../../tsconfig.json"
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"ignoreDeprecations": "6.0",
5+
"noUncheckedSideEffectImports": false
6+
}
37
}

packages/app/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
99
export default defineConfig({
1010
resolve: {
1111
alias: {
12+
// Force all codemirror packages to use the same @codemirror/state instance,
13+
// preventing the "multiple instances" error when mixing codemirror meta-package
14+
// with direct @codemirror/* imports under pnpm.
15+
'@codemirror/state': path.resolve(
16+
__dirname,
17+
'../../node_modules/.pnpm/@codemirror+view@6.41.0/node_modules/@codemirror/state'
18+
),
1219
'@': path.resolve(__dirname, './src'),
1320
'@core': path.resolve(__dirname, './src/core'),
1421
'@components': path.resolve(__dirname, './src/components'),

packages/service/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"lint": "eslint ."
3535
},
3636
"dependencies": {
37+
"@babel/parser": "^7.28.4",
38+
"@babel/traverse": "^7.28.4",
3739
"@babel/types": "^7.28.4",
3840
"@wdio/devtools-backend": "workspace:^",
3941
"@wdio/devtools-script": "workspace:^",
@@ -42,8 +44,6 @@
4244
"@wdio/types": "9.27.0",
4345
"import-meta-resolve": "^4.1.0",
4446
"stack-trace": "1.0.0-pre2",
45-
"@babel/parser": "^7.28.4",
46-
"@babel/traverse": "^7.28.4",
4747
"ws": "^8.18.3"
4848
},
4949
"license": "MIT",
@@ -54,8 +54,9 @@
5454
"@types/ws": "^8.18.1",
5555
"@wdio/globals": "9.27.0",
5656
"@wdio/protocols": "9.27.0",
57+
"typescript": "6.0.2",
58+
"vite": "7.3.2",
5759
"vite-plugin-dts": "^4.5.4"
58-
,"vite": "7.3.2"
5960
},
6061
"peerDependencies": {
6162
"@wdio/protocols": "9.27.0",

packages/service/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"ignoreDeprecations": "6.0",
45
"moduleResolution": "NodeNext",
56
"module": "NodeNext",
67
"types": ["@wdio/globals/types"]

0 commit comments

Comments
 (0)