How to use @shopify/react-html - 10 common examples

To help you get started, we’ve selected a few @shopify/react-html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Shopify / quilt / packages / react-server / src / render / render.tsx View on Github external
logger.log(rendering);
          logger.log(resolving);
        },
        ...options,
      });
      applyToContext(ctx, networkManager);

      const immediateAsyncAssets = asyncAssetManager.used(
        AssetTiming.Immediate,
      );
      const [styles, scripts] = await Promise.all([
        assets.styles({name: 'main', asyncAssets: immediateAsyncAssets}),
        assets.scripts({name: 'main', asyncAssets: immediateAsyncAssets}),
      ]);

      const response = stream(
        
          {app}
        ,
      );

      ctx.set(Header.ContentType, 'text/html');
      ctx.body = response;
    } catch (error) {
      const errorMessage = `React server-side rendering error:\n${error.stack ||
        error.message}`;

      logger.log(errorMessage);
      ctx.status = StatusCode.InternalServerError;

      // eslint-disable-next-line no-process-env
      if (process.env.NODE_ENV === 'development') {
github Shopify / quilt / packages / react-universal-provider / src / create-universal-provider.tsx View on Github external
({value: explicitValue, children}: UniversalProviderProps) => {
      const [value = explicitValue, Serialize] = useSerialized(id);

      if (value == null) {
        throw new Error(
          `You must provide a ${id} value, or have one previously serialized.`,
        );
      }

      return (
        <>
          {children}
           value} />
        
      );
    },
  );
github Shopify / quilt / packages / react-self-serializers / src / I18n.tsx View on Github external
export function I18n({children, ...givenI18nDetails}: Props) {
  const [serialized, Serialize] = useSerialized('i18n');

  const i18nDetails: I18nDetails = {
    locale: givenI18nDetails.fallbackLocale || 'en',
    ...givenI18nDetails,
    ...(serialized ? serialized.i18nDetails : {}),
  };

  const manager = useRef(
    new I18nManager(
      i18nDetails,
      serialized ? serialized.translations : undefined,
    ),
  );

  useHtmlAttributes({lang: i18nDetails.locale});
github Shopify / quilt / packages / react-graphql-universal-provider / src / GraphQLUniversalProvider.tsx View on Github external
export function GraphQLUniversalProvider({
  children,
  createClientOptions,
}: Props) {
  const [initialData, Serialize] = useSerialized('apollo');

  const [client, link] = useLazyRef<
    [
      import('apollo-client').ApolloClient,
      ReturnType
    ]
  >(() => {
    const clientOptions = createClientOptions();
    const link = createSsrExtractableLink();

    const apolloClient = new ApolloClient({
      ...clientOptions,
      link: clientOptions.link ? link.concat(clientOptions.link) : link,
      cache: initialData
        ? clientOptions.cache.restore(initialData)
        : clientOptions.cache,
github Shopify / quilt / packages / react-i18n-universal-provider / src / I18nUniversalProvider.tsx View on Github external
export function I18nUniversalProvider({
  children,
  ...explicitI18nDetails
}: Props) {
  const [serialized, Serialize] = useSerialized('i18n');

  const i18nDetails: I18nDetails = {
    locale: explicitI18nDetails.fallbackLocale || 'en',
    ...(serialized ? serialized : {}),
    ...explicitI18nDetails,
  };

  const manager = useLazyRef(
    () =>
      new I18nManager(
        i18nDetails,
        serialized ? serialized.translations : undefined,
      ),
  ).current;

  useHtmlAttributes({lang: i18nDetails.locale});
github Shopify / quilt / packages / react-self-serializers / src / GraphQLComponent.tsx View on Github external
export function GraphQL({children, createClient}: Props) {
  const [initialData, Serialize] = useSerialized('apollo');

  const [client, link] = useLazyRef<
    [
      import('apollo-client').ApolloClient,
      ReturnType
    ]
  >(() => {
    const link = createSsrExtractableLink();
    const client = createClient();
    client.link = link.concat(client.link);

    if (initialData) {
      client.cache = client.cache.restore(initialData);
    }

    return [client, link];
github Shopify / quilt / packages / react-self-serializers / src / I18n.tsx View on Github external
const [serialized, Serialize] = useSerialized('i18n');

  const i18nDetails: I18nDetails = {
    locale: givenI18nDetails.fallbackLocale || 'en',
    ...givenI18nDetails,
    ...(serialized ? serialized.i18nDetails : {}),
  };

  const manager = useRef(
    new I18nManager(
      i18nDetails,
      serialized ? serialized.translations : undefined,
    ),
  );

  useHtmlAttributes({lang: i18nDetails.locale});

  return (
    <>
      
        {children}
      
       {
          const getData = () => ({
            translations: manager.current.extract(),
            i18nDetails,
          });

          if (manager.current.loading) {
            return manager.current.resolve().then(getData);
          }
github Shopify / quilt / packages / react-i18n-universal-provider / src / I18nUniversalProvider.tsx View on Github external
const i18nDetails: I18nDetails = {
    locale: explicitI18nDetails.fallbackLocale || 'en',
    ...(serialized ? serialized : {}),
    ...explicitI18nDetails,
  };

  const manager = useLazyRef(
    () =>
      new I18nManager(
        i18nDetails,
        serialized ? serialized.translations : undefined,
      ),
  ).current;

  useHtmlAttributes({lang: i18nDetails.locale});

  const {onError, ...primitiveI18nDetails} = i18nDetails;

  return (
    <>
      {children}
       {
          const getData = () => ({
            translations: manager.extract(),
            ...primitiveI18nDetails,
          });

          if (manager.loading) {
            return manager.resolve().then(getData);
          }
github Shopify / quilt / packages / react-server / src / render / render.tsx View on Github external
async function renderFunction(ctx: Context) {
    const logger = getLogger(ctx) || console;
    const assets = getAssets(ctx);

    const networkManager = new NetworkManager({
      headers: ctx.headers,
      cookies: ctx.request.headers.cookie || '',
    });
    const htmlManager = new HtmlManager();
    const asyncAssetManager = new AsyncAssetManager();
    const hydrationManager = new HydrationManager();

    function Providers({children}: {children: React.ReactElement}) {
      return (
        
          
            
              {children}
            
          
        
      );
    }

    try {
github Shopify / quilt / packages / koa-react-sidecar / src / render / render.tsx View on Github external
return async function render(ctx: RenderContext) {
    const app = renderFunction(ctx);
    const networkManager = new NetworkManager();
    const htmlManager = new HtmlManager();

    try {
      await extract(app, {
        decorate(app) {
          return (
            
              
                {app}
              
            
          );
        },
      });
    } catch (error) {
      logger.error(error);
      throw error;

@shopify/react-html

A component to render your React app with no static HTML

MIT
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis

Similar packages