Skip to content

Commit

Permalink
fix: guard change handler since toggle is fired from programatic chan…
Browse files Browse the repository at this point in the history
…ges to open
  • Loading branch information
mlrawlings authored and DylanPiercey committed Dec 16, 2024
1 parent 9421a60 commit da44e24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .sizes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{
"name": "*",
"total": {
"min": 18048,
"brotli": 6515
"min": 18045,
"brotli": 6518
}
},
{
Expand Down
8 changes: 5 additions & 3 deletions .sizes/dom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// size: 18048 (min) 6515 (brotli)
// size: 18045 (min) 6518 (brotli)
var empty = [],
rest = Symbol();
function attrTag(attrs2) {
Expand Down Expand Up @@ -742,14 +742,16 @@ function controllable_detailsOrDialog_open(
(scope[nodeAccessor].open = normalizeBoolProp(open));
}
function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
let el = scope[nodeAccessor];
let el = scope[nodeAccessor],
hasChanged = () => el.open !== scope[nodeAccessor + ":"];
syncControllable(
el,
"DIALOG" === el.tagName ? "close" : "toggle",
() => scope[nodeAccessor + ";"] && el.open !== scope[nodeAccessor + ":"],
hasChanged,
() => {
let openChange = scope[nodeAccessor + ";"];
openChange &&
hasChanged() &&
((scope[nodeAccessor + "="] = 6),
openChange(el.open),
run(),
Expand Down
11 changes: 4 additions & 7 deletions packages/runtime-tags/src/dom/controllable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,17 @@ export function controllable_detailsOrDialog_open_effect(
nodeAccessor: Accessor,
) {
const el = scope[nodeAccessor] as HTMLDetailsElement;
const hasChanged = () =>
el.open !== scope[nodeAccessor + AccessorChar.ControlledValue];
syncControllable(
el,
el.tagName === "DIALOG" ? "close" : "toggle",
() => {
return (
scope[nodeAccessor + AccessorChar.ControlledHandler] &&
el.open !== scope[nodeAccessor + AccessorChar.ControlledValue]
);
},
hasChanged,
() => {
const openChange = scope[
nodeAccessor + AccessorChar.ControlledHandler
] as undefined | ((value: unknown) => unknown);
if (openChange) {
if (openChange && hasChanged()) {
scope[nodeAccessor + AccessorChar.ControlledType] =
ControlledType.Pending;
openChange(el.open);
Expand Down

0 comments on commit da44e24

Please # to comment.