Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix multiple local style sources (#981)

Bogdan Chadkin1e5caee26d21
diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
index a387bffd97..6c30c3cdbb 100644
--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
@@ -6,7 +6,6 @@ import type { StyleUpdates } from "@webstudio-is/project";
import type { StyleProperty, StyleValue } from "@webstudio-is/css-data";
import { type Publish } from "~/shared/pubsub";
import {
- selectedInstanceStyleSourcesStore,
selectedStyleSourceStore,
styleSourceSelectionsStore,
styleSourcesStore,
@@ -61,8 +60,6 @@ export const useStyleData = ({ selectedInstance, publish }: UseStyleData) => {
const publishUpdates = useCallback(
(type: "update" | "preview", updates: StyleUpdates["updates"]) => {
const selectedStyleSource = selectedStyleSourceStore.get();
- const selectedInstanceStyleSources =
- selectedInstanceStyleSourcesStore.get();
if (
updates.length === 0 ||
@@ -90,15 +87,16 @@ export const useStyleData = ({ selectedInstance, publish }: UseStyleData) => {
const instanceId = selectedInstance.id;
const breakpointId = selectedBreakpoint.id;
const styleSourceId = selectedStyleSource.id;
+ // set only selected style source and update selection with it
+ // generated local style source will not be written if not selected
styleSources.set(selectedStyleSource.id, selectedStyleSource);
- const selections = selectedInstanceStyleSources.map(
- (styleSource) => styleSource.id
- );
+ const selectionValues =
+ styleSourceSelections.get(instanceId)?.values ?? [];
styleSourceSelections.set(instanceId, {
instanceId,
- values: selections.includes(styleSourceId)
- ? selections
- : [...selections, styleSourceId],
+ values: selectionValues.includes(styleSourceId)
+ ? selectionValues
+ : [...selectionValues, styleSourceId],
});
for (const update of updates) {
diff --git a/apps/designer/app/designer/features/style-panel/style-source-section.tsx b/apps/designer/app/designer/features/style-panel/style-source-section.tsx
index 2fe570008c..7e6c0178fb 100644
--- a/apps/designer/app/designer/features/style-panel/style-source-section.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-source-section.tsx
@@ -29,6 +29,7 @@ const createStyleSource = (name: string) => {
id: nanoid(),
name,
};
+ // set style sources and selection along with generated local style source
const newStyleSources = [...selectedInstanceStyleSources, newStyleSource];
const newStyleSourceSelection: StyleSourceSelection = {
instanceId: selectedInstanceId,
@@ -55,6 +56,7 @@ const addStyleSourceToInstace = (styleSourceId: StyleSource["id"]) => {
if (selectedInstanceId === undefined) {
return;
}
+ // set style sources and selection along with generated local style source
const newStyleSourceSelection: StyleSourceSelection = {
instanceId: selectedInstanceId,
values: [