fix: 修复下拉菜单不显示的多处回归#28
Open
PrintNow wants to merge 5 commits into
Open
Conversation
PHP 8 现代化改造(#13)把 renderOption() 中 mb_strpos($v, '</a>') 的「包含」判断机械替换成了 str_starts_with,后者几乎恒为 false, 导致已是完整 <a> 链接的菜单项被再包一层 <a>,产生非法嵌套 HTML, Dropdown::make() 渲染的菜单(含每页条数下拉)显示异常。 改为 str_contains,与 DropdownActions 中的正确转换保持一致。
config/admin.php 已定义 'assets_version' => env('ADMIN_ASSETS_VERSION'),
键存在且为 null 时 config($key, $default) 不会取第二参默认值,导致
withVersionQuery() 判定为空、所有 JS/CSS 的 ?v 缓存破坏参数被静默移除,
浏览器长期使用旧缓存资源,升级后下拉等 JS 组件行为异常。
改为 config('admin.assets_version') ?? Admin::VERSION:env 未设置时
回退框架版本(恢复 #27 之前行为),显式置空字符串才禁用版本参数
(保留 #27 的新能力),并同步修正配置注释。
af0d4db 引入的 .off('change.select2') 会连带移除 select2 自身以同 命名空间绑定在原生 select 上的内部处理器(负责 selection:update 重绘已选项)。脚本被二次求值且 select2 已初始化时(LazyRenderable 重载、校验失败回显、弹窗内表单重渲染),该处理器被永久摘除且因 initialized 守卫不会重建,表现为选中/取消后不再回显。 改用自有命名空间 change.dcat-msel,保留幂等去重意图;select2 选择 变化最终会触发原生 change 事件,隐藏 input 按需禁用的功能不变。
SessionMessage 迁移(#25)后,alerts/toastr 模板统一经 tryFrom() 读取 flash 值,外部代码沿用旧契约直接 flash 的 MessageBag 会返回 null 而被静默吞掉(旧模板可正常渲染)。 tryFrom() 增加兼容分支:MessageBag 实例(php 序列化会话)与其 序列化数组形态 ['title' => ['x'], 'message' => ['y']](Laravel 13 或 json 序列化会话)均可还原为 SessionMessage;带类型标识数组的 防篡改守卫保持不变。补充 4 个单测覆盖新路径。
重复代码提取(#14)将 Grid Filter 的 find()(走真实主键)与 Form 的 whereIn 统一为 whereIn($idField),但 idField 默认值硬编码为 'id',非 id 主键的模型在筛选/表单回显时会查错列。 改为 idField 未传时取 (new $model)->getKeyName(),恢复重构前 Grid 分支的正确语义;显式传参的调用方不受影响。同时补上 in_array 严格比较第三参(编码规范要求)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
近期多个 PR 叠加引入了三个相互独立的回归,导致弹窗/Modal 等场景下表单 select/multipleSelect 与各类下拉菜单显示异常。经排查逐一定位并修复,同时顺带修复审计中发现的两个相关问题。
回归修复
1. Dropdown 菜单项被套非法嵌套
<a>(#13 引入)Widgets/Dropdown.php中mb_strpos($v, '</a>')的「包含」判断被机械替换成str_starts_with,后者几乎恒为 false,导致已是完整链接的菜单项被再包一层<a>,破坏Dropdown::make()渲染的所有菜单(含每页条数下拉)。改为str_contains。2. JS/CSS 缓存破坏参数被静默移除(#27 引入)
config/admin.php已定义'assets_version' => env('ADMIN_ASSETS_VERSION'),键存在且为 null 时config($key, $default)不会取默认值,withVersionQuery()判空后移除所有?v版本参数,浏览器长期使用旧缓存 JS,升级后下拉等组件行为异常。改为config('admin.assets_version') ?? Admin::VERSION:未配置回退框架版本,显式置空字符串才禁用。3. multipleselect 误摘 select2 内部处理器(#23 引入)
.off('change.select2')会连带移除 select2 自身以同命名空间绑定的内部处理器(负责选中项重绘)。脚本二次求值且 select2 已初始化时(LazyRenderable 重载、校验回显、弹窗内重渲染),处理器被永久摘除且不会重建,选中/取消后不再回显。改用自有命名空间change.dcat-msel。顺带修复
4. SessionMessage 向后兼容旧式 MessageBag(#25 遗留)
外部代码沿用旧契约直接 flash 的
MessageBag会被tryFrom()返回 null 静默吞掉。增加兼容分支:MessageBag 实例与其序列化数组形态均可还原;防篡改守卫不变。补充 4 个单测。5. HasModelOptions 默认按模型主键查询(#14 遗留)
idField硬编码默认'id',非 id 主键模型筛选/回显查错列。改为未传时取getKeyName(),恢复重构前 Grid 分支走真实主键的语义;并补in_array严格比较。验证
SessionMessageTest27 个测试全部通过(含新增 4 个)resources/dist重编译