Skip to content

Commit

Permalink
fix(slots): Keep slots ordered by tpl order
Browse files Browse the repository at this point in the history
Issue: https://linear.app/plasmic/issue/PLA-11570
GitOrigin-RevId: 5411a003e8399b405b9d63158593697aa2d7d024
  • Loading branch information
FMota0 authored and actions-user committed Dec 18, 2024
1 parent 5ede1f9 commit 41b4090
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion platform/wab/src/wab/client/fixes-post-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { $$$ } from "@/wab/shared/TplQuery";
import { isBaseVariant } from "@/wab/shared/Variants";
import { getActiveVariantsForFrame } from "@/wab/shared/cached-selectors";
import { notNil, tuple } from "@/wab/shared/common";
import { isPageComponent } from "@/wab/shared/core/components";
import { isCodeComponent, isPageComponent } from "@/wab/shared/core/components";
import {
RecordedChanges,
mergeRecordedChanges,
Expand All @@ -35,6 +35,7 @@ import {
isGrid,
isTplComponent,
isTplContainer,
isTplSlot,
isTplTag,
isTplTagOrComponent,
isTplVariantable,
Expand All @@ -47,6 +48,7 @@ import {
TplComponent,
TplNode,
TplSlot,
isKnownSlotParam,
isKnownTplComponent,
isKnownTplSlot,
isKnownVirtualRenderExpr,
Expand Down Expand Up @@ -102,6 +104,10 @@ export function fixupForChanges(
fixupIncorrectlyNamedNodes(summary, studioCtx);
fixupImplicitStates(summary);
});

[changes, summary] = applyFix(() => {
fixupSlotParamsOrder(summary);
});
}

// Now do view-related fixes
Expand Down Expand Up @@ -419,3 +425,23 @@ export function fixupVirtualSlotArgs(
}
}
}

function fixupSlotParamsOrder(summary: ChangeSummary) {
for (const component of summary.updatedComponents) {
const slotParams = component.params.filter((param) =>
isKnownSlotParam(param)
);

// Skip code components, since they don't have tpl trees
// and ignore components with at most one slot param to avoid unnecessary work
if (isCodeComponent(component) || slotParams.length <= 1) {
return;
}

const slots = flattenTpls(component.tplTree).filter(isTplSlot);
component.params = [
...component.params.filter((param) => !isKnownSlotParam(param)),
...slots.map((slot) => slot.param),
];
}
}

0 comments on commit 41b4090

Please sign in to comment.