[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EKXN3WMYCDPREAM9HABC6Z":3,"skill-same:01M7EKXN3WMYCDPREAM9HABC6Z":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":32,"commitSha":33,"skillDirectory":34,"forksCount":14,"repositoryHtmlUrl":35,"repositoryHomepageUrl":35,"ownerHtmlUrl":36,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":37,"install":38,"resources":51},"01M7EKXN3WMYCDPREAM9HABC6Z","use-js-interop",null,"> Add, review, or fix JavaScript interop in Blazor components. USE FOR: calling JavaScript from Blazor, calling .NET from JavaScript, collocated .razor.js modules, IJSRuntime, IJSObjectReference lifecycle, DotNetObjectReference, ElementReference, timing rules","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fcloud\u002Fuse-js-interop\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: use-js-interop\ndescription: \"> Add, review, or fix JavaScript interop in Blazor components. USE FOR: calling JavaScript from Blazor, calling .NET from JavaScript, collocated .razor.js modules, IJSRuntime, IJSObjectReference lifecycle, DotNetObjectReference, ElementReference, timing rules\"\ncategory: cloud\nversion: 1.0.0\ndisable-model-invocation: false\nrisk: low\nsource:\n  repository: \"microsoft\u002Fskills\"\n  commit: \"8f3b1a2c\"\n  path: \"plugins\u002Fdotnet-blazor\u002Fskills\u002Fuse-js-interop\u002FSKILL.md\"\n  license: \"MIT\"\n  imported_at: \"2026-09-20\"\n---\n# JS Interop in Blazor\n\n## 1. Collocated JS Modules\n\nAlways use collocated `.razor.js` files with `export` — never global `window.*` functions or `\u003Cscript>` tags.\n\n```javascript\n\u002F\u002F ChartPanel.razor.js — placed next to ChartPanel.razor\nexport function initialize(canvas, dotNetRef) { \u002F* ... *\u002F }\nexport function updateData(points) { \u002F* ... *\u002F }\nexport function dispose() { \u002F* ... *\u002F }\n```\n\nImport paths: same project = `\".\u002FComponents\u002FChartPanel.razor.js\"`, RCL = `\".\u002F_content\u002F{AssemblyName}\u002F...\"`.\n\n## 2. Lifecycle Timing\n\n**All JS interop must happen in `OnAfterRenderAsync` or event handlers** — never in `OnInitialized`, `OnParametersSet`, or constructors. JS is not available during server prerendering.\n\nUse a typed interop wrapper (see Section 4) — never call `InvokeAsync`\u002F`InvokeVoidAsync` with raw string literals:\n\n```csharp\nprivate ChartInterop? _chart;\n\nprotected override async Task OnAfterRenderAsync(bool firstRender)\n{\n    if (firstRender)\n    {\n        _chart = new ChartInterop(JS);\n        await _chart.InitializeAsync(_canvasRef);\n    }\n}\n```\n\n**Parameter changes**: set a flag in `OnParametersSet`, apply in `OnAfterRenderAsync`:\n\n```csharp\nprivate bool _dataChanged;\n\nprotected override void OnParametersSet() => _dataChanged = true;\n\nprotected override async Task OnAfterRenderAsync(bool firstRender)\n{\n    if (firstRender) { \u002F* init *\u002F }\n    else if (_dataChanged && _chart is not null)\n    {\n        _dataChanged = false;\n        await _chart.UpdateDataAsync(DataPoints);\n    }\n}\n```\n\n## 3. Batch Related Operations\n\nEach JS interop call crosses the .NET-to-JS boundary (and in Blazor Server, the SignalR circuit). Batching applies in **both directions** — .NET→JS and JS→.NET.\n\n### .NET → JS: merge consecutive calls\n\nIf the C# side makes two or more JS calls in a row, combine them into one JS function:\n\n```csharp\n\u002F\u002F ❌ Two round-trips — theme and locale are always applied together\nawait _module.InvokeVoidAsync(\"applyTheme\", theme);\nawait _module.InvokeVoidAsync(\"applyLocale\", locale);\n\n\u002F\u002F ❌ Result of one call feeds into another — both can stay in JS\nvar token = await _module.InvokeAsync\u003Cstring>(\"createAccessToken\");\nawait _module.InvokeVoidAsync(\"storeToken\", token);\n```\n\n```javascript\n\u002F\u002F ✅ One call applies both — no data dependency, no reason for two trips\nexport function applyPreferences(theme, locale) {\n    document.documentElement.dataset.theme = theme;\n    document.documentElement.lang = locale;\n}\n\n\u002F\u002F ✅ Chain stays in JS — the token never needs to cross the boundary\nexport function createAndStoreToken() {\n    const token = crypto.randomUUID();\n    sessionStorage.setItem('access-token', token);\n    return token;\n}\n```\n\n### JS → .NET: batch callbacks\n\nWhen JS needs to send multiple pieces of data back to .NET, send them in a single `invokeMethodAsync` call rather than making separate callbacks:\n\n```javascript\n\u002F\u002F ❌ Two .NET round-trips from JS\nawait dotNetRef.invokeMethodAsync(ON_VOLUME_CHANGED, volume);\nawait dotNetRef.invokeMethodAsync(ON_PLAYBACK_CHANGED, isPlaying);\n\n\u002F\u002F ✅ One callback with all data\nawait dotNetRef.invokeMethodAsync(ON_PLAYER_STATE_CHANGED, { volume, isPlaying });\n```\n\n**Rule**: if two interop calls always happen together from either side, merge them into one function.\n\n## 4. Typed Interop Wrapper\n\nEncapsulate interop for a feature in a plain class that owns the module lifecycle:\n\n```csharp\npublic sealed class ChartInterop : IAsyncDisposable\n{\n    internal const string ModulePath = \".\u002FComponents\u002FChartPanel.razor.js\";\n    internal const string InitMethod = \"initialize\";\n    internal const string UpdateMethod = \"updateData\";\n    internal const string DisposeMethod = \"dispose\";\n\n    private readonly IJSRuntime _js;\n    private IJSObjectReference? _module;\n\n    public ChartInterop(IJSRuntime js) => _js = js;\n\n    private async ValueTask\u003CIJSObjectReference> GetModuleAsync()\n        => _module ??= await _js.InvokeAsync\u003CIJSObjectReference>(\"import\", ModulePath);\n\n    public async ValueTask InitializeAsync(ElementReference canvas)\n    {\n        var module = await GetModuleAsync();\n        await module.InvokeVoidAsync(InitMethod, canvas);\n    }\n\n    public async ValueTask UpdateDataAsync(IReadOnlyList\u003CDataPoint> points)\n    {\n        var module = await GetModuleAsync();\n        await module.InvokeVoidAsync(UpdateMethod, points);\n    }\n\n    public async ValueTask DisposeAsync()\n    {\n        try\n        {\n            if (_module is not null)\n            {\n                await _module.InvokeVoidAsync(DisposeMethod);\n                await _module.DisposeAsync();\n            }\n        }\n        catch (JSDisconnectedException) { }\n    }\n}\n```\n\nThe component creates and uses the wrapper with no magic strings:\n\n```razor\n@inject IJSRuntime JS\n@implements IAsyncDisposable\n\n\u003Ccanvas @ref=\"_canvasRef\" width=\"600\" height=\"400\">\u003C\u002Fcanvas>\n\n@code {\n    private ElementReference _canvasRef;\n    private ChartInterop? _chart;\n\n    protected override async Task OnAfterRenderAsync(bool firstRender)\n    {\n        if (firstRender)\n        {\n            _chart = new ChartInterop(JS);\n            await _chart.InitializeAsync(_canvasRef);\n        }\n    }\n\n    async ValueTask IAsyncDisposable.DisposeAsync()\n    {\n        if (_chart is not null)\n            await _chart.DisposeAsync();\n    }\n}\n```\n\nPrefer a concrete class over interface + implementation for interop wrappers. For unit testing, substitute `IJSRuntime` directly (it is already an interface).\n\n## 5. DotNetObjectReference for JS-to-.NET Callbacks\n\n```csharp\n_dotNetRef = DotNetObjectReference.Create(this);\nawait _module.InvokeVoidAsync(\"initialize\", _dotNetRef);\n```\n\nOn the JS side, wrap the `dotNetRef` in a class. Use `async`\u002F`await` with `try\u002Fcatch` (not `.catch()`) to guard against circuit loss. Define .NET method name constants at the top:\n\n```javascript\nconst ON_CLIPBOARD_CHANGED = 'OnClipboardChanged';\n\nclass ClipboardMonitor {\n    #dotNetRef;\n    #abortController;\n\n    constructor(dotNetRef) {\n        this.#dotNetRef = dotNetRef;\n        this.#abortController = new AbortController();\n    }\n\n    start() {\n        document.addEventListener('copy', async () => {\n            try {\n                const text = await navigator.clipboard.readText();\n                await this.#dotNetRef.invokeMethodAsync(ON_CLIPBOARD_CHANGED, text);\n            } catch { \u002F* circuit disconnected or clipboard denied *\u002F }\n        }, { signal: this.#abortController.signal });\n    }\n\n    dispose() {\n        this.#abortController.abort();\n    }\n}\n\nlet monitor;\nexport function initialize(dotNetRef) {\n    monitor = new ClipboardMonitor(dotNetRef);\n    monitor.start();\n}\n\nexport function dispose() {\n    monitor?.dispose();\n}\n```\n\nRules:\n- `[JSInvokable]` methods **must be `public`** — private\u002Finternal silently fails at runtime\n- Wrap `StateHasChanged` in `InvokeAsync` inside `[JSInvokable]` callbacks:\n  ```csharp\n  [JSInvokable]\n  public async Task OnClipboardChanged(string text)\n  {\n      await InvokeAsync(() => { _lastClipboard = text; StateHasChanged(); });\n  }\n  ```\n- Always `try\u002Fcatch` around `invokeMethodAsync` in JS — circuit loss throws\n- Use `const` for .NET method name strings in JS — prevents typo bugs that silently fail\n- Dispose `DotNetObjectReference` in `DisposeAsync`\n\n## 6. Disposal and Server Safety\n\nAlways implement `IAsyncDisposable`. Call JS cleanup first, then dispose references. Catch `JSDisconnectedException` for Blazor Server circuit loss:\n\n```csharp\npublic async ValueTask DisposeAsync()\n{\n    try\n    {\n        if (_module is not null)\n        {\n            await _module.InvokeVoidAsync(\"dispose\");\n            await _module.DisposeAsync();\n        }\n    }\n    catch (JSDisconnectedException) { }\n\n    _dotNetRef?.Dispose();\n}\n```\n\nNever use sync `IDisposable` for JS interop cleanup — `InvokeVoidAsync` returns `ValueTask` and must be awaited.\n\n## 7. ElementReference\n\nPass DOM elements via `@ref`, not string IDs:\n\n```razor\n\u003Ccanvas @ref=\"_canvasRef\" width=\"600\" height=\"400\">\u003C\u002Fcanvas>\n```\n\n```csharp\nawait _chart.InitializeAsync(_canvasRef);\n```\n\n## Checklist\n\n- [ ] JS is in collocated `.razor.js` with `export` — no `window.*` globals\n- [ ] All interop in `OnAfterRenderAsync` or event handlers — never during prerender\n- [ ] `IAsyncDisposable` catches `JSDisconnectedException`\n- [ ] `DotNetObjectReference` disposed in `DisposeAsync`; JS side has `try\u002Fcatch` around `invokeMethodAsync`\n- [ ] `[JSInvokable]` methods are `public` and use `await InvokeAsync(StateHasChanged)`\n- [ ] `InvokeVoidAsync` used when no return value is needed\n- [ ] `ElementReference` instead of string IDs\n- [ ] Related operations batched into single interop calls (both .NET→JS and JS→.NET)\n\n## Common Mistakes Checklist\n\n| Mistake | Fix |\n|---------|-----|\n| Using JS for something achievable with CSS | Use CSS custom properties, `data-` attributes, pseudo-classes |\n| Many fine-grained interop calls | Batch into coarse functions — both .NET→JS and JS→.NET |\n| Component imports JS module directly | Encapsulate in a strongly typed interop class |\n| Magic strings for method names \u002F module paths | Define `internal const` fields in the interop class |\n| Interface + implementation for interop wrapper | Use a plain class; mock `IJSRuntime` for tests instead |\n| JS calls in `OnInitializedAsync` | Move to `OnAfterRenderAsync(firstRender)` |\n| `InvokeAsync\u003Cobject>` for void calls | Use `InvokeVoidAsync` |\n| `IDisposable` with fire-and-forget JS | Use `IAsyncDisposable` with `await` |\n| Global `window.*` JS functions | Use collocated `.razor.js` with `export` |\n| String element IDs passed to JS | Use `ElementReference` with `@ref` |\n| `[JSInvokable]` on private method | Must be `public` — silently fails otherwise |\n| `DotNetObjectReference` not disposed | Dispose in `DisposeAsync` — causes memory leak |\n| `StateHasChanged()` without `InvokeAsync` | Wrap in `await InvokeAsync(() => { StateHasChanged(); })` |\n| JS `invokeMethodAsync` without error handling | Wrap in `try\u002Fcatch` — circuit loss throws |\n| Bare `dotNetRef` in JS event handlers | Wrap in a class with `#dotNetRef` private field |\n| Magic strings in JS `invokeMethodAsync` calls | Use `const` at module top — typos silently fail at runtime |\n| JS calls in `OnParametersSetAsync` | Track changes, apply in `OnAfterRenderAsync` with guard |\n| No null check before calling module | Check `module is not null` before use |\n","# JS Interop in Blazor\n\n## 1. Collocated JS Modules\n\nAlways use collocated `.razor.js` files with `export` — never global `window.*` functions or `\u003Cscript>` tags.\n\n```javascript\n\u002F\u002F ChartPanel.razor.js — placed next to ChartPanel.razor\nexport function initialize(canvas, dotNetRef) { \u002F* ... *\u002F }\nexport function updateData(points) { \u002F* ... *\u002F }\nexport function dispose() { \u002F* ... *\u002F }\n```\n\nImport paths: same project = `\".\u002FComponents\u002FChartPanel.razor.js\"`, RCL = `\".\u002F_content\u002F{AssemblyName}\u002F...\"`.\n\n## 2. Lifecycle Timing\n\n**All JS interop must happen in `OnAfterRenderAsync` or event handlers** — never in `OnInitialized`, `OnParametersSet`, or constructors. JS is not available during server prerendering.\n\nUse a typed interop wrapper (see Section 4) — never call `InvokeAsync`\u002F`InvokeVoidAsync` with raw string literals:\n\n```csharp\nprivate ChartInterop? _chart;\n\nprotected override async Task OnAfterRenderAsync(bool firstRender)\n{\n    if (firstRender)\n    {\n        _chart = new ChartInterop(JS);\n        await _chart.InitializeAsync(_canvasRef);\n    }\n}\n```\n\n**Parameter changes**: set a flag in `OnParametersSet`, apply in `OnAfterRenderAsync`:\n\n```csharp\nprivate bool _dataChanged;\n\nprotected override void OnParametersSet() => _dataChanged = true;\n\nprotected override async Task OnAfterRenderAsync(bool firstRender)\n{\n    if (firstRender) { \u002F* init *\u002F }\n    else if (_dataChanged && _chart is not null)\n    {\n        _dataChanged = false;\n        await _chart.UpdateDataAsync(DataPoints);\n    }\n}\n```\n\n## 3. Batch Related Operations\n\nEach JS interop call crosses the .NET-to-JS boundary (and in Blazor Server, the SignalR circuit). Batching applies in **both directions** — .NET→JS and JS→.NET.\n\n### .NET → JS: merge consecutive calls\n\nIf the C# side makes two or more JS calls in a row, combine them into one JS function:\n\n```csharp\n\u002F\u002F ❌ Two round-trips — theme and locale are always applied together\nawait _module.InvokeVoidAsync(\"applyTheme\", theme);\nawait _module.InvokeVoidAsync(\"applyLocale\", locale);\n\n\u002F\u002F ❌ Result of one call feeds into another — both can stay in JS\nvar token = await _module.InvokeAsync\u003Cstring>(\"createAccessToken\");\nawait _module.InvokeVoidAsync(\"storeToken\", token);\n```\n\n```javascript\n\u002F\u002F ✅ One call applies both — no data dependency, no reason for two trips\nexport function applyPreferences(theme, locale) {\n    document.documentElement.dataset.theme = theme;\n    document.documentElement.lang = locale;\n}\n\n\u002F\u002F ✅ Chain stays in JS — the token never needs to cross the boundary\nexport function createAndStoreToken() {\n    const token = crypto.randomUUID();\n    sessionStorage.setItem('access-token', token);\n    return token;\n}\n```\n\n### JS → .NET: batch callbacks\n\nWhen JS needs to send multiple pieces of data back to .NET, send them in a single `invokeMethodAsync` call rather than making separate callbacks:\n\n```javascript\n\u002F\u002F ❌ Two .NET round-trips from JS\nawait dotNetRef.invokeMethodAsync(ON_VOLUME_CHANGED, volume);\nawait dotNetRef.invokeMethodAsync(ON_PLAYBACK_CHANGED, isPlaying);\n\n\u002F\u002F ✅ One callback with all data\nawait dotNetRef.invokeMethodAsync(ON_PLAYER_STATE_CHANGED, { volume, isPlaying });\n```\n\n**Rule**: if two interop calls always happen together from either side, merge them into one function.\n\n## 4. Typed Interop Wrapper\n\nEncapsulate interop for a feature in a plain class that owns the module lifecycle:\n\n```csharp\npublic sealed class ChartInterop : IAsyncDisposable\n{\n    internal const string ModulePath = \".\u002FComponents\u002FChartPanel.razor.js\";\n    internal const string InitMethod = \"initialize\";\n    internal const string UpdateMethod = \"updateData\";\n    internal const string DisposeMethod = \"dispose\";\n\n    private readonly IJSRuntime _js;\n    private IJSObjectReference? _module;\n\n    public ChartInterop(IJSRuntime js) => _js = js;\n\n    private async ValueTask\u003CIJSObjectReference> GetModuleAsync()\n        => _module ??= await _js.InvokeAsync\u003CIJSObjectReference>(\"import\", ModulePath);\n\n    public async ValueTask InitializeAsync(ElementReference canvas)\n    {\n        var module = await GetModuleAsync();\n        await module.InvokeVoidAsync(InitMethod, canvas);\n    }\n\n    public async ValueTask UpdateDataAsync(IReadOnlyList\u003CDataPoint> points)\n    {\n        var module = await GetModuleAsync();\n        await module.InvokeVoidAsync(UpdateMethod, points);\n    }\n\n    public async ValueTask DisposeAsync()\n    {\n        try\n        {\n            if (_module is not null)\n            {\n                await _module.InvokeVoidAsync(DisposeMethod);\n                await _module.DisposeAsync();\n            }\n        }\n        catch (JSDisconnectedException) { }\n    }\n}\n```\n\nThe component creates and uses the wrapper with no magic strings:\n\n```razor\n@inject IJSRuntime JS\n@implements IAsyncDisposable\n\n\u003Ccanvas @ref=\"_canvasRef\" width=\"600\" height=\"400\">\u003C\u002Fcanvas>\n\n@code {\n    private ElementReference _canvasRef;\n    private ChartInterop? _chart;\n\n    protected override async Task OnAfterRenderAsync(bool firstRender)\n    {\n        if (firstRender)\n        {\n            _chart = new ChartInterop(JS);\n            await _chart.InitializeAsync(_canvasRef);\n        }\n    }\n\n    async ValueTask IAsyncDisposable.DisposeAsync()\n    {\n        if (_chart is not null)\n            await _chart.DisposeAsync();\n    }\n}\n```\n\nPrefer a concrete class over interface + implementation for interop wrappers. For unit testing, substitute `IJSRuntime` directly (it is already an interface).\n\n## 5. DotNetObjectReference for JS-to-.NET Callbacks\n\n```csharp\n_dotNetRef = DotNetObjectReference.Create(this);\nawait _module.InvokeVoidAsync(\"initialize\", _dotNetRef);\n```\n\nOn the JS side, wrap the `dotNetRef` in a class. Use `async`\u002F`await` with `try\u002Fcatch` (not `.catch()`) to guard against circuit loss. Define .NET method name constants at the top:\n\n```javascript\nconst ON_CLIPBOARD_CHANGED = 'OnClipboardChanged';\n\nclass ClipboardMonitor {\n    #dotNetRef;\n    #abortController;\n\n    constructor(dotNetRef) {\n        this.#dotNetRef = dotNetRef;\n        this.#abortController = new AbortController();\n    }\n\n    start() {\n        document.addEventListener('copy', async () => {\n            try {\n                const text = await navigator.clipboard.readText();\n                await this.#dotNetRef.invokeMethodAsync(ON_CLIPBOARD_CHANGED, text);\n            } catch { \u002F* circuit disconnected or clipboard denied *\u002F }\n        }, { signal: this.#abortController.signal });\n    }\n\n    dispose() {\n        this.#abortController.abort();\n    }\n}\n\nlet monitor;\nexport function initialize(dotNetRef) {\n    monitor = new ClipboardMonitor(dotNetRef);\n    monitor.start();\n}\n\nexport function dispose() {\n    monitor?.dispose();\n}\n```\n\nRules:\n- `[JSInvokable]` methods **must be `public`** — private\u002Finternal silently fails at runtime\n- Wrap `StateHasChanged` in `InvokeAsync` inside `[JSInvokable]` callbacks:\n  ```csharp\n  [JSInvokable]\n  public async Task OnClipboardChanged(string text)\n  {\n      await InvokeAsync(() => { _lastClipboard = text; StateHasChanged(); });\n  }\n  ```\n- Always `try\u002Fcatch` around `invokeMethodAsync` in JS — circuit loss throws\n- Use `const` for .NET method name strings in JS — prevents typo bugs that silently fail\n- Dispose `DotNetObjectReference` in `DisposeAsync`\n\n## 6. Disposal and Server Safety\n\nAlways implement `IAsyncDisposable`. Call JS cleanup first, then dispose references. Catch `JSDisconnectedException` for Blazor Server circuit loss:\n\n```csharp\npublic async ValueTask DisposeAsync()\n{\n    try\n    {\n        if (_module is not null)\n        {\n            await _module.InvokeVoidAsync(\"dispose\");\n            await _module.DisposeAsync();\n        }\n    }\n    catch (JSDisconnectedException) { }\n\n    _dotNetRef?.Dispose();\n}\n```\n\nNever use sync `IDisposable` for JS interop cleanup — `InvokeVoidAsync` returns `ValueTask` and must be awaited.\n\n## 7. ElementReference\n\nPass DOM elements via `@ref`, not string IDs:\n\n```razor\n\u003Ccanvas @ref=\"_canvasRef\" width=\"600\" height=\"400\">\u003C\u002Fcanvas>\n```\n\n```csharp\nawait _chart.InitializeAsync(_canvasRef);\n```\n\n## Checklist\n\n- [ ] JS is in collocated `.razor.js` with `export` — no `window.*` globals\n- [ ] All interop in `OnAfterRenderAsync` or event handlers — never during prerender\n- [ ] `IAsyncDisposable` catches `JSDisconnectedException`\n- [ ] `DotNetObjectReference` disposed in `DisposeAsync`; JS side has `try\u002Fcatch` around `invokeMethodAsync`\n- [ ] `[JSInvokable]` methods are `public` and use `await InvokeAsync(StateHasChanged)`\n- [ ] `InvokeVoidAsync` used when no return value is needed\n- [ ] `ElementReference` instead of string IDs\n- [ ] Related operations batched into single interop calls (both .NET→JS and JS→.NET)\n\n## Common Mistakes Checklist\n\n| Mistake | Fix |\n|---------|-----|\n| Using JS for something achievable with CSS | Use CSS custom properties, `data-` attributes, pseudo-classes |\n| Many fine-grained interop calls | Batch into coarse functions — both .NET→JS and JS→.NET |\n| Component imports JS module directly | Encapsulate in a strongly typed interop class |\n| Magic strings for method names \u002F module paths | Define `internal const` fields in the interop class |\n| Interface + implementation for interop wrapper | Use a plain class; mock `IJSRuntime` for tests instead |\n| JS calls in `OnInitializedAsync` | Move to `OnAfterRenderAsync(firstRender)` |\n| `InvokeAsync\u003Cobject>` for void calls | Use `InvokeVoidAsync` |\n| `IDisposable` with fire-and-forget JS | Use `IAsyncDisposable` with `await` |\n| Global `window.*` JS functions | Use collocated `.razor.js` with `export` |\n| String element IDs passed to JS | Use `ElementReference` with `@ref` |\n| `[JSInvokable]` on private method | Must be `public` — silently fails otherwise |\n| `DotNetObjectReference` not disposed | Dispose in `DisposeAsync` — causes memory leak |\n| `StateHasChanged()` without `InvokeAsync` | Wrap in `await InvokeAsync(() => { StateHasChanged(); })` |\n| JS `invokeMethodAsync` without error handling | Wrap in `try\u002Fcatch` — circuit loss throws |\n| Bare `dotNetRef` in JS event handlers | Wrap in a class with `#dotNetRef` private field |\n| Magic strings in JS `invokeMethodAsync` calls | Use `const` at module top — typos silently fail at runtime |\n| JS calls in `OnParametersSetAsync` | Track changes, apply in `OnAfterRenderAsync` with guard |\n| No null check before calling module | Check `module is not null` before use |\n",{"name":5,"risk":24,"source":25,"version":30,"category":31,"description":7,"disable-model-invocation":20},"low",{"path":26,"commit":27,"license":15,"repository":28,"imported_at":29},"plugins\u002Fdotnet-blazor\u002Fskills\u002Fuse-js-interop\u002FSKILL.md","8f3b1a2c","microsoft\u002Fskills","2026-09-20","1.0.0","cloud","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fcloud\u002Fuse-js-interop","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":39,"prompt":49,"zipAvailable":50},[40,43,46],{"tool":41,"command":42},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill use-js-interop",{"tool":44,"command":45},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill use-js-interop",{"tool":47,"command":48},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill use-js-interop","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fcloud\u002Fuse-js-interop\u002FSKILL.md",true,[],[53,61,68,75,82,89],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":60},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":60},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":60},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":60},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":60},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":60},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]