mcpField
L
lightning-2025-features

lightning-2025-features

github.com/josiahsiegel开发59150 次安装19 周前更新
代码仓库

关于 lightning-2025-features

lightning-2025-features 汇总 Salesforce Lightning Web Components 的新功能与迁移示例,面向 LWC 开发者。内容涵盖本地开发、Agentforce 目标、测试、安全和设计系统更新。

主要功能

  1. 01切换至 lightning/graphql
  2. 02本地运行并热重载 LWC
  3. 03支持 Agentforce 组件目标
  4. 04使用 Lightning Out 2.0 嵌入组件
  5. 05SLDS 2.0 深色模式与统一测试 API

适用场景

  1. 01在本地预览和调试 LWC
  2. 02为 Agentforce 构建输入或输出组件
  3. 03将组件嵌入外部页面
  4. 04更新 GraphQL 模块并整合测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/josiahsiegel/claude-plugin-marketplace --skill lightning-2025-features

安装后在 Claude Code 中输入/lightning-2025-features确认已加载。

详细介绍

🚨 关键指南

Windows 文件路径要求

强制要求:在 Windows 上始终使用反斜杠表示文件路径

在 Windows 上使用 Edit 或 Write 工具时,必须在文件路径中使用反斜杠(\),而不是正斜杠(/)。

示例:

  • ❌ 错误:D:/repos/project/file.tsx
  • ✅ 正确:D:\repos\project\file.tsx

适用于:

  • Edit 工具的 file_path 参数
  • Write 工具的 file_path 参数
  • Windows 系统上的所有文件操作
文档指南

除非用户明确要求,否则绝不创建新的文档文件。

  • 优先级:更新现有的 README.md 文件,而不是创建新的文档
  • 保持仓库整洁:保持仓库根目录整洁——除非用户另有要求,否则只保留 README.md
  • 风格:文档应简洁、直接且专业——避免 AI 生成式的语气
  • 用户偏好:只有在用户明确要求编写文档时,才创建其他 .md 文件

Lightning Web Components 2025 年功能

lightning/graphql 模块(Winter '26)

新模块,用于替代已弃用的 lightning/uiGraphQLApi:

迁移
// ❌ Old (deprecated)
import { gql, graphql } from 'lightning/uiGraphQLApi';

// ✅ New (Winter '26)
import { gql, graphql } from 'lightning/graphql';

export default class MyComponent extends LightningElement {
  @wire(graphql, {
    query: gql`
      query getAccount($id: ID!) {
        uiapi {
          query {
            Account(where: { Id: { eq: $id } }) {
              edges {
                node {
                  Id
                  Name
                  Industry
                }
              }
            }
          }
        }
      }
    `,
    variables: '$variables'
  })
  results;

  get variables() {
    return { id: this.recordId };
  }
}
优势
  • 性能更佳
  • 错误处理更好
  • 类型安全性更高
  • 面向未来的 API

本地开发(sf lightning dev component)

无需部署即可在本地运行 LWC 组件:

# Start local dev server
sf lightning dev component

# Opens browser at http://localhost:3333
# Live reload on file changes
# No deployment needed
# Faster development cycle

# Specify component
sf lightning dev component -n myComponent

# Specify target org
sf lightning dev component -o [email protected]

优势:

  • 即时反馈(无需等待部署)
  • 在真实浏览器的 DevTools 中调试
  • 热模块替换
  • 离线工作

在组件预览中访问平台模块

在单个组件预览中访问平台模块:

// Works in local preview now
import { getRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';

// Previously required full org deployment
// Now works in sf lightning dev component

Agentforce 目标(Winter '26)

面向 AI Agent 的新 LWC 目标:


<targets>
  
  <target>lightning__AgentforceInput</target>

  
  <target>lightning__AgentforceOutput</target>
</targets>
// agentInputComponent.js
import { LightningElement, api } from 'lwc';

export default class AgentInputComponent extends LightningElement {
  @api agentContext;  // Provided by Agentforce

  handleSubmit() {
    const userInput = this.template.querySelector('input').value;
    // Send to Agentforce
    this.dispatchEvent(new CustomEvent('agentinput', {
      detail: { input: userInput }
    }));
  }
}

Lightning Out 2.0(Winter '26 正式发布)

借助 Web Components 重新构想嵌入方式:

传统 Lightning Out(旧版)
<script src="https://MyDomain.lightning.force.com/lightning/lightning.out.js"></script>
<script>
  $Lightning.use("c:myApp", function() {
    $Lightning.createComponent("c:myComponent",
      { recordId: "001..." },
      "lightningContainer",
      function(cmp) { /* callback */ }
    );
  });
</script>
<div id="lightningContainer"></div>
Lightning Out 2.0(现代版)

<script src="https://MyDomain.lightning.force.com/c/myComponent.js" type="module"></script>


<c-my-component record-id="001..." ></c-my-component>




优势:

  • 包体积缩小 50–70%
  • 加载速度更快
  • 基于标准(无需专有框架)
  • 浏览器兼容性更好
  • 集成更简单

支持暗色模式的 SLDS 2.0(Winter '26 正式发布)

Salesforce Lightning Design System 2.0:

/* Dark mode support in custom themes */
:host([data-theme="dark"]) {
  --lwc-colorBackground: #16325c;
  --lwc-colorTextPrimary: #ffffff;
  --lwc-brandPrimary: #1589ee;
}

/* Light mode */
:host([data-theme="light"]) {
  --lwc-colorBackground: #ffffff;
  --lwc-colorTextPrimary: #181818;
  --lwc-brandPrimary: #0176d3;
}
// Toggle dark mode
export default class ThemeToggle extends LightningElement {
  handleThemeChange(event) {
    const theme = event.target.checked ? 'dark' : 'light';
    this.template.host.setAttribute('data-theme', theme);
  }
}
带修复选项的 SLDS Linter
# Install SLDS linter
npm install -D @salesforce-ux/slds-linter

# Lint with auto-fix
npx slds-linter --fix src/

# CI/CD integration
npx slds-linter src/ --format json > slds-report.json

统一测试 API(Winter '26)

测试发现和测试运行器 API 统一了 Apex 与 Flow 测试:

// Discover all tests
Test.DiscoveryResult discovery = Test.discoverTests();

// Get Apex tests
List<Test.ApexTestInfo> apexTests = discovery.getApexTests();

// Get Flow tests
List<Test.FlowTestInfo> flowTests = discovery.getFlowTests();

// Run all tests from single location
Test.RunResult result = Test.runTests(discovery);

// Check results
System.debug('Apex passed: ' + result.getApexTestsPassed());
System.debug('Flow passed: ' + result.getFlowTestsPassed());

优势:

  • 统一执行测试
  • 单一测试报告
  • 简化 CI/CD
  • 更好的测试编排

Lightning Web Security 增强

通过 API 扭曲新增安全防护:

// Additional secure protections automatically applied
export default class SecureComponent extends LightningElement {
  connectedCallback() {
    // Web APIs now include security distortions
    // ESLint rules validate distortion compliance

    // Example: Secure window access
    const secureWindow = window;  // LWS-secured reference
  }
}
安全相关的 ESLint 规则
// .eslintrc.json
{
  "extends": ["@salesforce/eslint-config-lwc/recommended"],
  "rules": {
    "@lwc/lwc/no-inner-html": "error",
    "@lwc/lwc/no-document-query": "error",
    "@salesforce/lwc-security/no-unsafe-references": "error"
  }
}

实用迁移示例

GraphQL 模块更新
// Before (Winter '25)
import { gql, graphql } from 'lightning/uiGraphQLApi';

@wire(graphql, { query: gql`...` })
results;

// After (Winter '26)
import { gql, graphql } from 'lightning/graphql';

@wire(graphql, { query: gql`...` })
results;
本地开发工作流
# Old workflow (deploy every change)
sf project deploy start
# Wait 30-60 seconds
# Test in org
# Repeat...

# New workflow (instant feedback)
sf lightning dev component
# Changes reflect immediately
# No deployment
# Test in local browser
# Deploy only when ready
使用 Lightning Out 2.0 嵌入

<script src="/lightning/lightning.out.js"></script>
<script>
  $Lightning.use("c:app", function() {
    $Lightning.createComponent("c:comp", {}, "div", callback);
  });
</script>


<script src="/c/comp.js" type="module"></script>
<c-comp></c-comp>

资源

评论

支持 Markdown