Skip to content

Commit 85147c8

Browse files
authored
fix: remove "show" toggles on descendant component (#4711)
Closes #4670
1 parent 44ca2d2 commit 85147c8

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

.github/workflows/fixtures-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
- name: Testing cli build command
5151
run: pnpm --filter='./fixtures/*' run --parallel fixtures:build
5252

53+
- name: Prepare for diffing
54+
run: find . -type f -path "./fixtures/*/.webstudio/data.json" -exec sed 's|"origin": ".*"|"origin": "https://main.development.webstudio.is"|g' {} +
55+
5356
- name: Test git diff
5457
# This command will fail if there are uncommitted changes, i.e something has broken
5558
run: git diff --name-only HEAD --exit-code

apps/builder/app/builder/features/navigator/navigator-tree.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
showAttribute,
2727
WsComponentMeta,
2828
blockTemplateComponent,
29+
descendantComponent,
2930
} from "@webstudio-is/react-sdk";
3031
import { ROOT_INSTANCE_ID, type Instance } from "@webstudio-is/sdk";
3132
import {
@@ -281,22 +282,28 @@ const handleExpand = (item: TreeItem, isExpanded: boolean, all: boolean) => {
281282
};
282283

283284
const ShowToggle = ({
284-
instanceId,
285+
instance,
285286
value,
286287
}: {
287-
instanceId: Instance["id"];
288+
instance: Instance;
288289
value: boolean;
289290
}) => {
291+
// descendant component is not actually rendered
292+
// but affects styling of nested elements
293+
// hiding descendant does not hide nested elements and confuse users
294+
if (instance.component === descendantComponent) {
295+
return;
296+
}
290297
const toggleShow = () => {
291298
const newValue = value === false;
292299
serverSyncStore.createTransaction([$props], (props) => {
293300
const { propsByInstanceId } = $propsIndex.get();
294-
const instanceProps = propsByInstanceId.get(instanceId);
301+
const instanceProps = propsByInstanceId.get(instance.id);
295302
let showProp = instanceProps?.find((prop) => prop.name === showAttribute);
296303
if (showProp === undefined) {
297304
showProp = {
298305
id: nanoid(),
299-
instanceId,
306+
instanceId: instance.id,
300307
name: showAttribute,
301308
type: "boolean",
302309
value: newValue,
@@ -660,9 +667,7 @@ export const NavigatorTree = () => {
660667
}
661668
},
662669
}}
663-
action={
664-
<ShowToggle instanceId={item.instance.id} value={show} />
665-
}
670+
action={<ShowToggle instance={item.instance} value={show} />}
666671
>
667672
<TreeNodeContent
668673
meta={meta}

apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
showAttribute,
66
textContentAttribute,
77
collectionComponent,
8+
descendantComponent,
89
} from "@webstudio-is/react-sdk";
910
import type { PropValue } from "../shared";
1011
import { useStore } from "@nanostores/react";
@@ -195,19 +196,32 @@ export const usePropsLogic = ({
195196

196197
const initialPropsNames = new Set(meta.initialProps ?? []);
197198

198-
const systemProps: PropAndMeta[] = systemPropsMeta.map(({ name, meta }) => {
199-
let saved = getAndDelete<Prop>(unprocessedSaved, name);
200-
if (saved === undefined && meta.defaultValue !== undefined) {
201-
saved = getStartingProp(instance.id, meta, name);
202-
}
203-
getAndDelete(unprocessedKnown, name);
204-
initialPropsNames.delete(name);
205-
return {
206-
prop: saved,
207-
propName: name,
208-
meta,
209-
};
210-
});
199+
const systemProps: PropAndMeta[] = systemPropsMeta
200+
.filter(({ name }) => {
201+
// descendant component is not actually rendered
202+
// but affects styling of nested elements
203+
// hiding descendant does not hide nested elements and confuse users
204+
if (
205+
instance.component === descendantComponent &&
206+
name === showAttribute
207+
) {
208+
return false;
209+
}
210+
return true;
211+
})
212+
.map(({ name, meta }) => {
213+
let saved = getAndDelete<Prop>(unprocessedSaved, name);
214+
if (saved === undefined && meta.defaultValue !== undefined) {
215+
saved = getStartingProp(instance.id, meta, name);
216+
}
217+
getAndDelete(unprocessedKnown, name);
218+
initialPropsNames.delete(name);
219+
return {
220+
prop: saved,
221+
propName: name,
222+
meta,
223+
};
224+
});
211225

212226
const canHaveTextContent =
213227
instanceMeta?.type === "container" &&

0 commit comments

Comments
 (0)