Skip to content

Commit

Permalink
Merge branch 'BuilderIO:main' into mitosis-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatgarg12 committed Jun 8, 2023
2 parents 14ebca9 + 041777d commit 93fc924
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 122 deletions.
24 changes: 19 additions & 5 deletions examples/swift/Shared/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import SwiftUI
import BuilderIO

class BuilderContentWrapper: ObservableObject {
var content: BuilderContent? = nil;
init(content: BuilderContent? = nil) {
self.content = content
}

func changeContent(_ newValue: BuilderContent?) {
self.content = newValue;
self.objectWillChange.send();
}
}

struct ContentView: View {
@State var content: BuilderContent? = nil
@ObservedObject var content: BuilderContentWrapper = BuilderContentWrapper();

init() {
registerComponent(name: "HeroComponent", factory: { (options, styles) in
Expand All @@ -12,15 +24,17 @@ struct ContentView: View {
}

func fetchContent() {
Content.getContent(model: "page", apiKey: "e084484c0e0241579f01abba29d9be10", url: "/custom-components") { content in
self.content = content
Content.getContent(model: "page", apiKey: "e084484c0e0241579f01abba29d9be10", url: "/custom-components", locale: "", preview: "") { content in
DispatchQueue.main.async {
self.content.changeContent(content);
}
}
}

var body: some View {
ScrollView {
if $content.wrappedValue != nil {
RenderContent(content: $content.wrappedValue!)
if $content.content.wrappedValue != nil {
RenderContent(content: $content.content.wrappedValue!)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sdks-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export default defineConfig({
})),

webServer: things.map(({ packageName, port, portFlag }) => {
const server = {
return {
command: `PORT=${port} yarn workspace @builder.io/${packageName} run serve ${portFlag}`,
port,
reuseExistingServer: false,
...(packageName === 'e2e-react-native' ? { timeout: 120 * 1000 } : {}),
};
return server;
}),
});
133 changes: 73 additions & 60 deletions packages/sdks-tests/src/tests/ab-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Browser } from '@playwright/test';
import type { Browser, BrowserContext } from '@playwright/test';
import { expect } from '@playwright/test';
import { findTextInPage, isRNSDK, test } from './helpers.js';

Expand All @@ -12,54 +12,62 @@ const createContextWithCookies = async ({
cookies,
baseURL,
browser,
context,
}: {
browser: Browser;
baseURL: string;
cookies: { name: string; value: string }[];
context: BrowserContext;
}) => {
const context = await browser.newContext({
storageState: isRNSDK
? {
origins: [
{
origin: new URL(baseURL).origin,
localStorage: cookies.map(({ name, value }) => ({
name: `builderio.${name}`,
value: JSON.stringify({
rawData: { value },
// add long expiry
expires: Date.now() + 1000 * 60 * 60 * 24 * 365 * 10,
}),
})),
},
],
cookies: [],
}
: {
cookies: cookies.map(cookie => {
const newCookie = {
name: cookie.name,
value: cookie.value,
// this is valid but types seem to be mismatched.
url: baseURL,
} as any;
return newCookie;
}),
origins: [],
},
if (isRNSDK) {
context.addInitScript(
items => {
items.map(({ name, value }) => {
window.localStorage.setItem(name, value);
});
},
cookies.map(({ name, value }) => ({
name: `builderio.${name}`,
value: JSON.stringify({
rawData: { value },
// add long expiry
expires: Date.now() + 1000 * 60 * 60 * 24 * 365 * 10,
}),
}))
);
return context;
}
return await browser.newContext({
storageState: {
cookies: cookies.map(cookie => {
const newCookie = {
name: cookie.name,
value: cookie.value,
// this is valid but types seem to be mismatched.
url: baseURL,
} as any;
return newCookie;
}),
origins: [],
},
});

return context;
};

// Forbid retries as A/B tests are not deterministic, and we don't want to give any leeway to flakiness.
test.describe.configure({ retries: 0 });

test.describe('A/B tests', () => {
let i = 0;
const runTests = () => {
i++;
test(`#${i}: Render default w/ SSR`, async ({ baseURL, packageName, browser }) => {
const TRIES = 10;

// Manually run tests 10 times to ensure we don't have any flakiness.
for (let i = 1; i <= TRIES; i++) {
test(`#${i}/${TRIES}: Render default w/ SSR`, async ({
page: _page,
baseURL,
packageName,
browser,
context: _context,
}) => {
if (!baseURL) {
throw new Error('Missing baseURL');
}
Expand All @@ -69,24 +77,36 @@ test.describe('A/B tests', () => {
test.skip();
}

// React Native is slow for this particular test. Increasing timeout helps.
if (packageName === 'e2e-react-native') {
test.slow();
}

const context = await createContextWithCookies({
baseURL,
browser,
cookies: [{ name: COOKIE_NAME, value: CONTENT_ID }],
context: _context,
});

const page = await context.newPage();
let page = _page;
if (!isRNSDK) {
page = await context.newPage();
}

await page.goto('/ab-test');

await findTextInPage({ page, text: 'hello world default' });
await expect(page.locator(SELECTOR, { hasText: 'hello world variation 1' })).toBeHidden();

// Gracefully close up everything
await context.close();
});

test(`#${i}: Render variant w/ SSR`, async ({ browser, baseURL, packageName }) => {
test(`#${i}/${TRIES}: Render variant w/ SSR`, async ({
browser,
baseURL,
packageName,
context: _context,
page: _page,
}) => {
if (!baseURL) {
throw new Error('Missing baseURL');
}
Expand All @@ -96,34 +116,27 @@ test.describe('A/B tests', () => {
test.skip();
}

// React Native is slow for this particular test. Increasing timeout helps.
if (packageName === 'e2e-react-native') {
test.slow();
}

const context = await createContextWithCookies({
baseURL,
browser,
cookies: [{ name: COOKIE_NAME, value: VARIANT_ID }],
context: _context,
});

const page = await context.newPage();
let page = _page;
if (!isRNSDK) {
page = await context.newPage();
}

await page.goto('/ab-test');

await findTextInPage({ page, text: 'hello world variation 1' });
await expect(page.locator(SELECTOR, { hasText: 'hello world default' })).toBeHidden();

// Gracefully close up everything
await context.close();
});
};

// Manually run tests 10 times to ensure we don't have any flakiness.
// Having a for-loop here causes issues with the test runner in React Native for some reason.
runTests();
runTests();
runTests();
runTests();
runTests();
runTests();
runTests();
runTests();
runTests();
runTests();
}
});
6 changes: 6 additions & 0 deletions packages/sdks/output/qwik/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
- Feature: Add support for `enrich` API flag.
- Mark `noTraverse` and `includeRefs` as deprecated.

### 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/qwik/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/sdk-qwik",
"version": "0.4.0",
"version": "0.4.1",
"description": "Builder.io Qwik SDK",
"type": "module",
"main": "./lib/index.qwik.cjs",
Expand Down
4 changes: 4 additions & 0 deletions packages/sdks/output/react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- No changes.
Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/sdk-react-native",
"description": "Builder.io SDK for React Native",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/sdks/output/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
- Feature: Add support for `enrich` API flag.
- Mark `noTraverse` and `includeRefs` as deprecated.

### 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/sdk-react",
"description": "Builder.io SDK for React",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"files": [
"dist"
Expand Down
6 changes: 6 additions & 0 deletions packages/sdks/output/solid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
- Feature: Add support for `enrich` API flag.
- Mark `noTraverse` and `includeRefs` as deprecated.

### 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/sdk-solid",
"version": "0.4.0",
"version": "0.4.1",
"description": "",
"type": "module",
"main": "./solid-index.jsx",
Expand Down
6 changes: 6 additions & 0 deletions packages/sdks/output/svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
- Feature: Add support for `enrich` API flag.
- Mark `noTraverse` and `includeRefs` as deprecated.

### 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/sdk-svelte",
"description": "Builder.io SDK for Svelte",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"files": [
"package",
Expand Down
6 changes: 6 additions & 0 deletions packages/sdks/output/vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
### 0.4.1

- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.

### 0.4.0

- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
- Fix: memory leak caused by passing reactive component references.
- Feature: Add support for `enrich` API flag.
- Mark `noTraverse` and `includeRefs` as deprecated.- Fix: memory leak caused by passing reactive component references.

### 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/output/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"workspaces": [
"packages/*"
],
"version": "0.4.0",
"version": "0.4.1",
"main": "./packages/_vue2/dist/sdk.js",
"module": "./packages/_vue2/dist/sdk.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const convertSearchParamsToQueryObject = (
return options;
};

/**
* Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
* relevant to the Builder SDK.
*
* @returns
*/
export const getBuilderSearchParams = (
_options: QueryObject | URLSearchParams | undefined
) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/sdks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export {
processContentResult,
} from './functions/get-content/index.js';

export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';

export { track } from './functions/track/index.js';

export type { RegisteredComponent } from './context/types';
Expand Down

0 comments on commit 93fc924

Please sign in to comment.