Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: columns props updates #3220

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions .changeset/six-worms-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@builder.io/sdk-react-nextjs': patch
'@builder.io/sdk-qwik': patch
'@builder.io/sdk-react': patch
'@builder.io/sdk-react-native': patch
'@builder.io/sdk-solid': patch
'@builder.io/sdk-svelte': patch
'@builder.io/sdk-vue': patch
---

Fix: make Column block's state reactive to its `props`
13 changes: 10 additions & 3 deletions packages/sdks-tests/src/specs/columns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NEW_TEXT } from './helpers.js';

export const CONTENT = {
export const COLUMNS = {
createdBy: 'OcOewqA7uqVVlVfqY453F8vgcc33',
createdDate: 1644861548711,
data: {
Expand Down Expand Up @@ -1187,6 +1187,13 @@ export const CONTENT = {
rev: 'zxiskiseoj',
};

export const MODIFIED_COLUMNS = JSON.parse(JSON.stringify(CONTENT));
MODIFIED_COLUMNS.data.blocks[2].children![1]!.component.options.columns![0].blocks[1].component.options.text =
export const COLUMNS_WITH_NEW_TEXT = JSON.parse(JSON.stringify(COLUMNS));
COLUMNS_WITH_NEW_TEXT.data.blocks[2].children![1]!.component.options.columns![0].blocks[1].component.options.text =
NEW_TEXT;

export const COLUMNS_WITH_NEW_SPACE = JSON.parse(JSON.stringify(COLUMNS));
COLUMNS_WITH_NEW_SPACE.data.blocks[2].children![1]!.component.options.space = 10;

export const COLUMNS_WITH_NEW_WIDTHS = JSON.parse(JSON.stringify(COLUMNS));
COLUMNS_WITH_NEW_WIDTHS.data.blocks[2].children![1]!.component.options.columns![0].width = 30;
COLUMNS_WITH_NEW_WIDTHS.data.blocks[2].children![1]!.component.options.columns![1].width = 70;
12 changes: 10 additions & 2 deletions packages/sdks-tests/src/specs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { AB_TEST_INTERACTIVE } from './ab-test-interactive.js';
import { CONTENT as abTest } from './ab-test.js';
import { ANIMATIONS } from './animations.js';
import { CONTENT as columns } from './columns.js';
import {
COLUMNS,
COLUMNS_WITH_NEW_SPACE,
COLUMNS_WITH_NEW_TEXT,
COLUMNS_WITH_NEW_WIDTHS,
} from './columns.js';
import { CONTENT as contentBindings } from './content-bindings.js';
import { CONTENT as cssNesting } from './css-nesting.js';
import { CSS_PROPERTIES } from './css-properties.js';
Expand Down Expand Up @@ -57,7 +62,10 @@ const PAGES = {
'/api-version-default': CONTENT_WITHOUT_SYMBOLS,
'/can-track-false': homepage,
'/css-nesting': cssNesting,
'/columns': columns,
'/columns': COLUMNS,
'/columns-with-new-text': COLUMNS_WITH_NEW_TEXT,
'/columns-with-new-space': COLUMNS_WITH_NEW_SPACE,
'/columns-with-new-widths': COLUMNS_WITH_NEW_WIDTHS,
'/symbols': symbols,
'/js-code': JS_CODE_CONTENT,
'/symbols-without-content': CONTENT_WITHOUT_SYMBOLS,
Expand Down
74 changes: 58 additions & 16 deletions packages/sdks-tests/src/tests/editing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { expect, type Page } from '@playwright/test';
import { MODIFIED_COLUMNS } from '../specs/columns.js';
import {
COLUMNS_WITH_NEW_SPACE,
COLUMNS_WITH_NEW_TEXT,
COLUMNS_WITH_NEW_WIDTHS,
} from '../specs/columns.js';
import { MODIFIED_EDITING_STYLES } from '../specs/editing-styles.js';
import { NEW_TEXT } from '../specs/helpers.js';
import { MODIFIED_HOMEPAGE } from '../specs/homepage.js';
Expand Down Expand Up @@ -84,22 +88,60 @@
test.describe('Visual Editing', () => {
test.skip(excludeTestFor({ angular: true }), 'Angular Gen2 SDK not implemented.');
editorTests({ noTrustedHosts: false });
test('correctly updates Text block in a Column block', async ({
page,
basePort,
packageName,
}) => {
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
packageName === 'gen1-next' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);
test.describe('Column block', () => {
test('correctly updates nested Text block', async ({ page, basePort, packageName }) => {
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
packageName === 'gen1-next' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);

await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page });
await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_TEXT, model: 'page' });
await page.frameLocator('iframe').getByText(NEW_TEXT).waitFor();
});
test('correctly updates space prop', async ({ page, basePort, packageName }) => {
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
packageName === 'gen1-next' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);

await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page });
const secondColumn = page.frameLocator('iframe').locator('.builder-column').nth(1);

await expect(secondColumn).toHaveCSS('margin-left', '20px');
await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_SPACE, model: 'page' });
await expect(secondColumn).toHaveCSS('margin-left', '10px');
});
test('correctly updates width props', async ({ page, basePort, packageName }) => {
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
packageName === 'gen1-next' ||
packageName === 'gen1-react' ||
packageName === 'gen1-remix'
);

await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page });
await sendContentUpdateMessage({ page, newContent: MODIFIED_COLUMNS, model: 'page' });
await page.frameLocator('iframe').getByText(NEW_TEXT).waitFor();
await launchEmbedderAndWaitForSdk({ path: '/columns', basePort, page });
const secondColumn = page.frameLocator('iframe').locator('.builder-column').nth(1);

const initialWidth = await (
await secondColumn.evaluateHandle(el => Number(getComputedStyle(el).width))
).jsonValue();

await sendContentUpdateMessage({ page, newContent: COLUMNS_WITH_NEW_WIDTHS, model: 'page' });

const finalWidth = await (
await secondColumn.evaluateHandle(el => Number(getComputedStyle(el).width))
).jsonValue();

expect(finalWidth).toBeGreaterThan(initialWidth);

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (svelte)

[svelte] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

1) [svelte] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (svelte)

[sveltekit] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

2) [sveltekit] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (qwik)

[qwik-city] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

1) [qwik-city] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (react)

[next-pages-dir] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

1) [next-pages-dir] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (react)

[react] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

2) [react] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (react)

[next-app-dir-client] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

3) [next-app-dir-client] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (solid)

[solid] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

1) [solid] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (solid)

[solid-start] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

2) [solid-start] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (vue)

[vue] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

1) [vue] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props ─ Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26

Check failure on line 143 in packages/sdks-tests/src/tests/editing.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (vue)

[nuxt] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props

2) [nuxt] › editing.spec.ts:121:5 › Visual Editing › Column block › correctly updates width props Error: expect(received).toBeGreaterThan(expected) Expected: > NaN Received: NaN 141 | ).jsonValue(); 142 | > 143 | expect(finalWidth).toBeGreaterThan(initialWidth); | ^ 144 | }); 145 | }); 146 | test.describe('fails for empty trusted hosts', () => { at /home/runner/work/builder/builder/packages/sdks-tests/src/tests/editing.spec.ts:143:26
});
});
test.describe('fails for empty trusted hosts', () => {
test.fail();
Expand Down
19 changes: 13 additions & 6 deletions packages/sdks/src/blocks/columns/columns.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ useMetadata({

export default function Columns(props: ColumnProps) {
const state = useStore({
gutterSize: typeof props.space === 'number' ? props.space || 0 : 20,
cols: props.columns || [],
stackAt: props.stackColumnsAt || 'tablet',
get gutterSize() {
return typeof props.space === 'number' ? props.space || 0 : 20;
},
get cols() {
return props.columns || [];
},
get stackAt() {
return props.stackColumnsAt || 'tablet';
},
getTagName(column: Column) {
return column.link
? props.builderLinkComponent ||
Expand Down Expand Up @@ -81,12 +87,13 @@ export default function Columns(props: ColumnProps) {
return state.stackAt === 'never' ? desktopStyle : stackedStyle;
},

flexDir:
props.stackColumnsAt === 'never'
get flexDir() {
return props.stackColumnsAt === 'never'
? 'row'
: props.reverseColumnsWhenStacked
? 'column-reverse'
: 'column',
: 'column';
},

columnsCssVars(): Dictionary<string> {
return useTarget({
Expand Down