Skip to content

Handling ConfigProvider Theme for SSR #34217

@wuifdesign

Description

@wuifdesign
  • I have searched the issues of this repository and believe that this is not a duplicate.

What is expected?

Also add the config property to the ConfigProvider to render on SSR instead of using updateCSS.

Maybe something like this:

const ConfigProvider: React.FC<ConfigProviderProps> & {
  ConfigContext: typeof ConfigContext;
  SizeContext: typeof SizeContext;
  config: typeof setGlobalConfig;
} = props => {
  React.useEffect(() => {
    if (props.direction) {
      message.config({
        rtl: props.direction === 'rtl',
      });
      notification.config({
        rtl: props.direction === 'rtl',
      });
    }
  }, [props.direction]);
  
  // getThemeVariables() -> return ':root { --primary-color: #00a; ... }
  const variables = props.config.theme ? getThemeVariables(getGlobalPrefixCls(), props.theme) : null

  return (
    <>
      {variables && <style>{variables}</style>}
      <LocaleReceiver>
        {(_, __, legacyLocale) => (
          <ConfigConsumer>
            {context => (
              <ProviderChildren
                parentContext={context}
                legacyLocale={legacyLocale as Locale}
                {...props}
              />
            )}
          </ConfigConsumer>
        )}
      </LocaleReceiver>
    </>
  );
};

If this is not possible, at least export a function where we can get the colors object created in ./components/config-provider/cssVariables.tsx to manually add it to the code on SSR.

const cssList = Object.keys(variables).map(
key => `--${globalPrefixCls}-${key}: ${variables[key]};`,
);

What is actually happening?

Cant use it and on SSR the colors will not be added.

Environment Info
antd 4.18.7
React 17
System Mac OS
Browser -

Connected to issue: #34100

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions