Bound data style not being applied to deployed site

Please fill out as many of the following questions as possible so we can help you promptly! If you don’t know how to answer or it does not apply, feel free to remove it or leave it blank.

Builder content link

Builder public api key
fd2fab869b6342598809d4af1f4ac419

What are you trying to accomplish
I’m passing my color palette as a data prop into <BuilderComponent /> as follows:

      <BuilderComponent
        content={content}
        model="page"
        data={{ palette }}
        context={{ palette }}
      />

I’m passing context too because I’m not sure of the difference, but data works on its own too.

This works perfectly when I’m viewing the site on localhost (both built and dev), or with the preview link on the deployed site using “View current draft”

However, these styles are not applied on the deployed site. The text style I’m applying this variable to has no color applied on the deployed site.
image

Here’s the deployed site (colors not applied):
https://pr-45.d2yqwjo13e4ks5.amplifyapp.com/builder-demo

Here’s the deployed site, draft link (colors applied):
https://pr-45.d2yqwjo13e4ks5.amplifyapp.com/builder-demo?builder.space=fd2fab869b6342598809d4af1f4ac419&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=b40f827785ba456497490655ee81eee8&builder.overrides.b40f827785ba456497490655ee81eee8=b40f827785ba456497490655ee81eee8&builder.overrides.page:/builder-demo=b40f827785ba456497490655ee81eee8

Am I doing something wrong, do I need an extra step to get this working outside of localhost and draft mode? I’ve followed the documentation and everything works nicely except on the deployed site.

Thank you :slightly_smiling_face:

Screenshots or video link

Code stack you are integrating Builder with
Next.JS 13.4

Reproducible code example
builder.tsx component:

'use client';

import { useTheme } from '@aspire/ui';
import { BuilderComponent, useIsPreviewing } from '@builder.io/react';
import { BuilderContent, builder } from '@builder.io/sdk';
import DefaultErrorPage from 'next/error';
import '../builder-registry';

interface BuilderPageProps {
  content?: BuilderContent;
}

// Builder Public API Key set in .env file
builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY!);

export function RenderBuilderContent({ content }: BuilderPageProps) {
  const { palette } = useTheme();
  // Call the useIsPreviewing hook to determine if
  // the page is being previewed in Builder
  const isPreviewing = useIsPreviewing();
  // If "content" has a value or the page is being previewed in Builder,
  // render the BuilderComponent with the specified content and model props.
  if (content || isPreviewing) {
    return (
      <BuilderComponent
        content={content}
        model="page"
        data={{ palette }}
        context={{ palette }}
      />
    );
  }
  // If the "content" is falsy and the page is
  // not being previewed in Builder, render the
  // DefaultErrorPage with a 404.
  return <DefaultErrorPage statusCode={404} />;
}

Just an update on this after some debugging:

If I bind a data model created within builder, it doesn’t work either. Color bindings seem to be scrubbed anywhere other than localhost or draft views.

On localhost & draft views:
Element style:
image
React component data:

{
    "@type": "@builder.io/sdk:Element",
    "@version": 2,
    "bindings": {
        "style.color": "var _virtual_index=state.palette.primary.plainColor;return _virtual_index"
    },
    "id": "builder-3512641e54c940d7bcee4ffb4e4895cd",
    "meta": {
        "previousId": "builder-5984ba68d874411483fa45c301e78056"
    },
    "component": {
        "name": "TextBox",
        "options": {
            "children": "We champion customers that others might overlook.",
            "level": "h1"
        }
    },
    "responsiveStyles": {
        "large": {
            "display": "flex",
            "flexDirection": "column",
            "position": "relative",
            "flexShrink": "0",
            "boxSizing": "border-box",
            "marginTop": "0px",
            "fontSize": "96px",
            "lineHeight": "0.9",
            "textAlign": "center"
        },
        "small": {
            "fontSize": "48px",
            "fontWeight": "800"
        }
    }
}

On published:
Element style (nothing):
image
React component data:

{
    "@type": "@builder.io/sdk:Element",
    "@version": 2,
    "bindings": {
        "style.color": "var _virtual_index=state.palette.primary.plainColor;return _virtual_index"
    },
    "id": "builder-3512641e54c940d7bcee4ffb4e4895cd",
    "meta": {
        "previousId": "builder-5984ba68d874411483fa45c301e78056"
    },
    "component": {
        "name": "TextBox",
        "options": {
            "children": "We champion customers that others might overlook.",
            "level": "h1"
        }
    },
    "responsiveStyles": {
        "large": {
            "display": "flex",
            "flexDirection": "column",
            "position": "relative",
            "flexShrink": "0",
            "boxSizing": "border-box",
            "marginTop": "0px",
            "fontSize": "96px",
            "lineHeight": "0.9",
            "textAlign": "center"
        },
        "small": {
            "fontSize": "48px",
            "fontWeight": "800"
        }
    }
}

HEX colors broken

Color bindings that resolve as HEX values do not work at all. If I choose this option as a binding, the color isn’t applied in preview or published versions.
image

I am forced to use manually type out our theme’s CSS vars as custom CSS properties. This is kind of a deal breaker trying to pitch this tool to my company as I can’t expect the non-technical website builders to do this to access our theme colors.

Hey @onurfesci

Could you please share the Custom Code of the TextBox?

Hi sheema, do you mean the register code? Here it is:

const BuilderTypography = (props) => (
  <Typography {...props} {...props.attributes} />
);
Builder.registerComponent(withChildren(BuilderTypography), {
  name: 'TextBox',
  canHaveChildren: true,
  override: true,
  noWrap: true,
  inputs: [
    {
      name: 'children',
      type: 'string',
      friendlyName: 'Text', 
    },
    {
      name: 'level',
      type: 'string',
      friendlyName: 'Variant',
      enum: Object.keys(theme.typography),
    },
  ],
});

@onurfesci I recommend having a look at the issue below:

This is a workaround for now. It appears to be a bug within the app. I will raise this internally and will keep you posted.

Unfortunately that workaround didn’t work for the data binding issue… I’ll have to create my own workaround with custom inputs that map to the correct styles in my own component for now.

This is a pretty bad bug though because it gives us a lot of unnecessary tech debt to be able to expose our theme colours in Builder, when we could just pass them in as data.

I hope it is an easy bugfix on your end. Thanks for keeping me updated :+1: