@builder.io/react 8.2.1 → 8.2.2-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/builder-react-lite.cjs.js +1 -1
  3. package/dist/builder-react-lite.cjs.js.map +1 -1
  4. package/dist/builder-react-lite.esm.js +1 -1
  5. package/dist/builder-react-lite.esm.js.map +1 -1
  6. package/dist/builder-react.browser.js +2 -2
  7. package/dist/builder-react.browser.js.map +1 -1
  8. package/dist/builder-react.cjs.js +1 -1
  9. package/dist/builder-react.cjs.js.map +1 -1
  10. package/dist/builder-react.es5.js +1 -1
  11. package/dist/builder-react.es5.js.map +1 -1
  12. package/dist/builder-react.unpkg.js +2 -2
  13. package/dist/builder-react.unpkg.js.map +1 -1
  14. package/dist/lib/package.json +5 -4
  15. package/dist/lib/src/blocks/PersonalizationContainer.js +3 -3
  16. package/dist/lib/src/blocks/PersonalizationContainer.js.map +1 -1
  17. package/dist/lib/src/blocks/Router.js +2 -2
  18. package/dist/lib/src/blocks/Router.js.map +1 -1
  19. package/dist/lib/src/blocks/Symbol.js +1 -1
  20. package/dist/lib/src/blocks/Symbol.js.map +1 -1
  21. package/dist/lib/src/components/builder-component.component.js +13 -4
  22. package/dist/lib/src/components/builder-component.component.js.map +1 -1
  23. package/dist/lib/src/components/builder-content.component.js +1 -1
  24. package/dist/lib/src/components/builder-content.component.js.map +1 -1
  25. package/dist/lib/src/components/variants-provider.component.js +2 -2
  26. package/dist/lib/src/components/variants-provider.component.js.map +1 -1
  27. package/dist/lib/src/sdk-version.js +1 -1
  28. package/dist/types/src/components/builder-component.component.d.ts +5 -0
  29. package/dist/types/src/components/builder-content.component.d.ts +4 -0
  30. package/dist/types/src/components/variants-provider.component.d.ts +2 -1
  31. package/dist/types/src/sdk-version.d.ts +1 -1
  32. package/package.json +4 -3
  33. package/src/blocks/PersonalizationContainer.tsx +3 -0
  34. package/src/blocks/Router.tsx +2 -1
  35. package/src/blocks/Symbol.tsx +1 -0
  36. package/src/components/builder-component.component.tsx +19 -1
  37. package/src/components/builder-content.component.tsx +5 -1
  38. package/src/components/variants-provider.component.tsx +3 -1
@@ -39,6 +39,10 @@ export type BuilderContentProps<ContentType> = {
39
39
  * Required if `inline` is set to `true`.
40
40
  */
41
41
  content?: Content;
42
+ /**
43
+ * CSP nonce to allow the loading and execution of a script or style tag when Content-Security-Policy is enabled.
44
+ */
45
+ nonce?: string;
42
46
  } & ({
43
47
  model: string;
44
48
  } | {
@@ -3,6 +3,7 @@ import { BuilderContent } from '@builder.io/sdk';
3
3
  interface VariantsProviderProps {
4
4
  initialContent: BuilderContent;
5
5
  children: (variants: BuilderContent[], renderScript?: () => JSX.Element) => JSX.Element;
6
+ nonce?: string;
6
7
  }
7
- export declare const VariantsProvider: ({ initialContent, children }: VariantsProviderProps) => React.JSX.Element;
8
+ export declare const VariantsProvider: ({ initialContent, children, nonce }: VariantsProviderProps) => React.JSX.Element;
8
9
  export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "8.2.1";
1
+ export declare const SDK_VERSION = "8.2.2-3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/react",
3
- "version": "8.2.1",
3
+ "version": "8.2.2-3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "main": "dist/builder-react.cjs.js",
@@ -36,7 +36,7 @@
36
36
  "release:minor": "yarn build && yarn version minor && yarn npm publish",
37
37
  "release:patch": "yarn build && yarn version patch && yarn npm publish",
38
38
  "release:nightly": "yarn build && yarn version prerelease && yarn npm publish --tag nightly",
39
- "release:dev": "yarn build && yarn version prerelease && yarn npm publish --tag dev",
39
+ "release:dev": "yarn version prerelease && yarn pack && tar -zxvf package.tgz && cp package/package.json ./package.json && rm -rf package package.tgz && yarn build && yarn npm publish --tag dev",
40
40
  "fix-core-version": "bash ./scripts/fix-core-version.sh",
41
41
  "ci:test": "yarn test",
42
42
  "ci:build": "yarn build"
@@ -105,5 +105,6 @@
105
105
  },
106
106
  "installConfig": {
107
107
  "hoistingLimits": "workspaces"
108
- }
108
+ },
109
+ "stableVersion": "8.2.2"
109
110
  }
@@ -106,6 +106,7 @@ export function PersonalizationContainer(props: PersonalizationContainerProps) {
106
106
  </template>
107
107
  ))}
108
108
  <script
109
+ nonce={builderStore.context.nonce}
109
110
  id={`variants-script-${props.builderBlock?.id}`}
110
111
  dangerouslySetInnerHTML={{
111
112
  __html: getPersonalizationScript(
@@ -123,6 +124,7 @@ export function PersonalizationContainer(props: PersonalizationContainerProps) {
123
124
  />
124
125
  </div>
125
126
  <script
127
+ nonce={builderStore.context.nonce}
126
128
  dangerouslySetInnerHTML={{
127
129
  __html: `
128
130
  window.__hydrated = window.__hydrated || {};
@@ -194,6 +196,7 @@ export function PersonalizationContainer(props: PersonalizationContainerProps) {
194
196
  )}
195
197
  </div>
196
198
  <script
199
+ nonce={builderStore.context.nonce}
197
200
  dangerouslySetInnerHTML={{
198
201
  __html: `
199
202
  window.__hydrated = window.__hydrated || {};
@@ -262,7 +262,7 @@ class RouterComponent extends React.Component<PropsWithChildren<RouterProps>> {
262
262
  return (
263
263
  <div className="builder-router" data-model={model}>
264
264
  {/* TODO: move to emotion */}
265
- <style>{`
265
+ <style nonce={state.context.nonce}>{`
266
266
  @keyframes builderLoadingSpinner {
267
267
  0% {
268
268
  transform: rotate(0deg);
@@ -297,6 +297,7 @@ class RouterComponent extends React.Component<PropsWithChildren<RouterProps>> {
297
297
  options={{
298
298
  key: Builder.isEditing ? undefined : this.model + ':' + url, // TODO: other custom targets specify if should refetch components on change
299
299
  }}
300
+ nonce={state.context.nonce}
300
301
  >
301
302
  {/* TODO: builder blocks option for loading stuff */}
302
303
  {/* TODO: input for builder blocks for this */}
@@ -172,6 +172,7 @@ class SymbolComponent extends React.Component<PropsWithChildren<SymbolProps>> {
172
172
  hydrate={state.state?._hydrate}
173
173
  builderBlock={this.props.builderBlock}
174
174
  dataOnly={this.props.dataOnly}
175
+ nonce={state.context.nonce}
175
176
  >
176
177
  {/* TODO: builder blocks option for loading stuff */}
177
178
  {this.props.children}
@@ -298,6 +298,11 @@ export interface BuilderComponentProps {
298
298
  * Pass a list of custom components to register with Builder.io.
299
299
  */
300
300
  customComponents?: Array<RegisteredComponent>;
301
+
302
+ /**
303
+ * CSP nonce to allow the loading and execution of a script or style tag when Content-Security-Policy is enabled.
304
+ */
305
+ nonce?: string;
301
306
  }
302
307
 
303
308
  export interface BuilderComponentState {
@@ -439,6 +444,7 @@ export class BuilderComponent extends React.Component<
439
444
  context: {
440
445
  ...props.context,
441
446
  apiKey: this.props.apiKey || builder.apiKey,
447
+ nonce: this.props.nonce,
442
448
  },
443
449
  state: Object.assign(this.rootState, {
444
450
  ...(this.inlinedContent && this.inlinedContent.data && this.inlinedContent.data.state),
@@ -782,17 +788,21 @@ export class BuilderComponent extends React.Component<
782
788
  }
783
789
 
784
790
  updateState = (fn?: (state: any) => void) => {
791
+ console.log('DEBUG: updateState', fn);
785
792
  const state = this.rootState;
786
793
  if (fn) {
794
+ console.log('DEBUG: updateState fn', fn);
787
795
  fn(state);
788
796
  }
789
797
  if (this.mounted) {
798
+ console.log('DEBUG: updateState if', state);
790
799
  this.setState({
791
800
  update: this.updateState,
792
801
  state,
793
802
  updates: ((this.state && this.state.updates) || 0) + 1,
794
803
  });
795
804
  } else {
805
+ console.log('DEBUG: updateState else', state);
796
806
  this.state = {
797
807
  ...this.state,
798
808
  update: this.updateState,
@@ -813,6 +823,7 @@ export class BuilderComponent extends React.Component<
813
823
 
814
824
  @debounceNextTick
815
825
  notifyStateChange() {
826
+ console.log('DEBUG: notifyStateChange');
816
827
  if (Builder.isServer) {
817
828
  return;
818
829
  }
@@ -1097,6 +1108,7 @@ export class BuilderComponent extends React.Component<
1097
1108
  }
1098
1109
  contentError={this.props.contentError}
1099
1110
  modelName={this.name || 'page'}
1111
+ nonce={this.props.nonce}
1100
1112
  >
1101
1113
  {(data, loading, fullData) => {
1102
1114
  if (this.props.dataOnly) {
@@ -1191,6 +1203,7 @@ export class BuilderComponent extends React.Component<
1191
1203
  >
1192
1204
  {!codegen && this.getCss(data) && (
1193
1205
  <style
1206
+ nonce={this.props.nonce}
1194
1207
  ref={ref => (this.styleRef = ref)}
1195
1208
  className="builder-custom-styles"
1196
1209
  dangerouslySetInnerHTML={{
@@ -1254,6 +1267,7 @@ export class BuilderComponent extends React.Component<
1254
1267
  headers?: Record<string, string>;
1255
1268
  }
1256
1269
  ) {
1270
+ console.log('DEBUG: handleRequest', propertyName, httpRequest);
1257
1271
  const { url, method, body, headers } = httpRequest;
1258
1272
 
1259
1273
  const fetchCacheKey = JSON.stringify({ url, method, body, headers });
@@ -1271,13 +1285,17 @@ export class BuilderComponent extends React.Component<
1271
1285
  }
1272
1286
  let json: any;
1273
1287
  try {
1288
+ console.log('DEBUG: handleRequest try', json);
1289
+
1274
1290
  const result = await fetch(url, {
1275
1291
  method,
1276
1292
  headers,
1277
- body,
1293
+ body: method === 'GET' ? undefined : body,
1278
1294
  });
1279
1295
  json = await result.json();
1296
+ console.log('DEBUG: handleRequest json', json);
1280
1297
  } catch (err) {
1298
+ console.log('DEBUG: handleRequest catch', err);
1281
1299
  const error = toError(err);
1282
1300
  if (this._errors) {
1283
1301
  this._errors.push(error);
@@ -50,6 +50,10 @@ export type BuilderContentProps<ContentType> = {
50
50
  * Required if `inline` is set to `true`.
51
51
  */
52
52
  content?: Content;
53
+ /**
54
+ * CSP nonce to allow the loading and execution of a script or style tag when Content-Security-Policy is enabled.
55
+ */
56
+ nonce?: string;
53
57
  } & ({ model: string } | { modelName: string }); // model and modelName are aliases of the same thing¸
54
58
 
55
59
  /**
@@ -314,7 +318,7 @@ export class BuilderContent<ContentType extends object = any> extends React.Comp
314
318
  const useData: any = this.data;
315
319
  const TagName = this.props.dataOnly ? NoWrap : 'div';
316
320
  return (
317
- <VariantsProvider initialContent={useData}>
321
+ <VariantsProvider initialContent={useData} nonce={this.props.nonce}>
318
322
  {(variants, renderScript) => {
319
323
  return (
320
324
  <React.Fragment>
@@ -99,9 +99,10 @@ const variantsScript = (variantsString: string, contentId: string) =>
99
99
  interface VariantsProviderProps {
100
100
  initialContent: BuilderContent;
101
101
  children: (variants: BuilderContent[], renderScript?: () => JSX.Element) => JSX.Element;
102
+ nonce?: string;
102
103
  }
103
104
 
104
- export const VariantsProvider = ({ initialContent, children }: VariantsProviderProps) => {
105
+ export const VariantsProvider = ({ initialContent, children, nonce }: VariantsProviderProps) => {
105
106
  if (Builder.isBrowser && !builder.canTrack) {
106
107
  return children([initialContent]);
107
108
  }
@@ -126,6 +127,7 @@ export const VariantsProvider = ({ initialContent, children }: VariantsProviderP
126
127
  );
127
128
  const renderScript = () => (
128
129
  <script
130
+ nonce={nonce}
129
131
  id={`variants-script-${initialContent.id}`}
130
132
  dangerouslySetInnerHTML={{
131
133
  __html: variantsScript(variantsJson, initialContent.id!),