Skip to content

Commit 84b5036

Browse files
committed
fix: pass system to resources in builder (#4926)
Closes #4925 Loading resources with system variables broken while switching to global system.
1 parent 55c98d2 commit 84b5036

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

apps/builder/app/shared/nano-states/props.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { uploadingFileDataToAsset } from "~/builder/shared/assets/asset-utils";
3636
import { fetch } from "~/shared/fetch.client";
3737
import { $selectedPage, getInstanceKey } from "../awareness";
3838
import { computeExpression } from "../data-variables";
39-
import { $currentSystem, $currentSystemVariableId } from "../system";
39+
import { $currentSystem } from "../system";
4040

4141
export const assetBaseUrl = "/cgi/asset/";
4242

@@ -168,14 +168,10 @@ const $unscopedVariableValues = computed(
168168
* circular updates
169169
*/
170170
const $loaderVariableValues = computed(
171-
[
172-
$dataSources,
173-
$dataSourceVariables,
174-
$currentSystemVariableId,
175-
$currentSystem,
176-
],
177-
(dataSources, dataSourceVariables, systemVariableId, system) => {
171+
[$dataSources, $dataSourceVariables, $selectedPage, $currentSystem],
172+
(dataSources, dataSourceVariables, selectedPage, system) => {
178173
const values = new Map<string, unknown>();
174+
values.set(SYSTEM_VARIABLE_ID, system);
179175
for (const [dataSourceId, dataSource] of dataSources) {
180176
if (dataSource.type === "variable") {
181177
values.set(
@@ -185,7 +181,7 @@ const $loaderVariableValues = computed(
185181
}
186182
if (dataSource.type === "parameter") {
187183
let value = dataSourceVariables.get(dataSourceId);
188-
if (dataSource.id === systemVariableId) {
184+
if (dataSource.id === selectedPage?.systemDataSourceId) {
189185
value = system;
190186
}
191187
values.set(dataSourceId, value);

apps/builder/app/shared/system.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { atom, computed } from "nanostores";
2-
import {
3-
findPageByIdOrPath,
4-
type Page,
5-
type System,
6-
SYSTEM_VARIABLE_ID,
7-
} from "@webstudio-is/sdk";
2+
import { findPageByIdOrPath, type Page, type System } from "@webstudio-is/sdk";
83
import {
94
compilePathnamePattern,
105
matchPathnamePattern,
@@ -14,12 +9,6 @@ import { $selectedPage } from "./awareness";
149
import { $pages, $publishedOrigin } from "./nano-states";
1510
import { serverSyncStore } from "./sync";
1611

17-
export const $currentSystemVariableId = computed(
18-
$selectedPage,
19-
// fallback to global system variable
20-
(page) => page?.systemDataSourceId ?? SYSTEM_VARIABLE_ID
21-
);
22-
2312
export const $systemDataByPage = atom(
2413
new Map<Page["id"], Pick<System, "search" | "params">>()
2514
);

0 commit comments

Comments
 (0)