返回顶部
l

liveview-code-reviewLiveView代码审查

Reviews Phoenix LiveView code for lifecycle patterns, assigns/streams usage, components, and security. Use when reviewing LiveView modules, .heex templates, or LiveComponents.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.2.0
安全检测
已通过
128
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

liveview-code-review

LiveView 代码审查

快速参考

问题类型参考文档
mount、handleparams、handleevent、handleasyncreferences/lifecycle.md
何时使用 assigns 与 streams、AsyncResult
references/assigns-streams.md | | 函数组件与 LiveComponent、slots、attrs | references/components.md | | 每个事件的授权、phx-value 信任 | references/security.md |

审查清单

关键问题

  • - [ ] 异步函数中不复制 socket(先提取值)
  • [ ] 每个 handle_event 都验证授权
  • [ ] assigns 中不包含敏感数据(在 DOM 中可见)
  • [ ] phx-value 数据经过验证(用户可修改)

生命周期

  • - [ ] 订阅包裹在 connected?(socket) 中
  • [ ] handleparams 用于基于 URL 的状态
  • [ ] handleasync 处理 :loading 和 :error 状态

数据管理

  • - [ ] 大型集合(100+ 项)使用 Streams
  • [ ] 渲染后不需要的数据使用 temporary_assigns
  • [ ] 加载状态使用 AsyncResult 模式

组件

  • - [ ] 函数组件优先于 LiveComponents
  • [ ] LiveComponents 在 update/2 中保留 :inner_block
  • [ ] Slots 使用正确的 attr 声明
  • [ ] 文本输入使用 phx-debounce

有效模式(不要标记)

  • - 空的 mount 返回 {:ok, socket} - 对简单 LiveView 有效
  • 对小列表使用 assigns - 只有 100+ 项才需要 Streams
  • 没有 update/2 的 LiveComponent - 默认 update/2 会分配所有内容
  • 没有 phx-value 的 phx-click - 事件可能不需要数据
  • heex 中的内联函数 - 对简单转换有效

上下文相关规则

问题仅在以下情况标记
缺少防抖输入是文本/文本域且触发服务器事件
使用 streams
集合有 100+ 项或已分页 | | 缺少授权检查 | 事件修改数据且 mount 中没有授权 |

关键反模式

Socket 复制(最重要)

elixir

错误 - socket 被复制到异步函数中


def handleevent(load, , socket) do
Task.async(fn ->
user = socket.assigns.user # Socket 被复制!
fetch_data(user.id)
end)
{:noreply, socket}
end

正确 - 先提取值

def handleevent(load, , socket) do user_id = socket.assigns.user.id Task.async(fn -> fetchdata(userid) # 只复制了原始值 end) {:noreply, socket} end

缺少授权

elixir

错误 - 信任 phx-value 而没有授权


def handle_event(delete, %{id => id}, socket) do
Posts.delete_post!(id) # 任何人都可以删除任何帖子!
{:noreply, socket}
end

正确 - 验证授权

def handle_event(delete, %{id => id}, socket) do post = Posts.get_post!(id)

if post.userid == socket.assigns.currentuser.id do
Posts.delete_post!(post)
{:noreply, stream_delete(socket, :posts, post)}
else
{:noreply, put_flash(socket, :error, 未授权)}
end
end

提交发现结果前

对每个发现结果使用问题格式:[文件:行号] 问题标题。

在报告任何问题之前,加载并遵循 审查验证协议

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 liveview-code-review-1776114491 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 liveview-code-review-1776114491 技能

通过命令行安装

skillhub install liveview-code-review-1776114491

下载

⬇ 下载 liveview-code-review v1.2.0(免费)

文件大小: 7.95 KB | 发布时间: 2026-4-14 11:01

v1.2.0 最新 2026-4-14 11:01
- Revamped SKILL.md with clear quick references for lifecycle, assigns/streams, components, and security review.
- Added concise review checklist covering critical issues, lifecycle, data management, and component best practices.
- Provided explicit examples of valid patterns (to avoid false positives).
- Updated context-sensitive rules and anti-patterns (emphasizing socket copying and authorization checks).
- Introduced a standardized format for submitting findings and referenced the review verification protocol.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部