永久加载...在Smartedit预览中

时间:2020-05-07 13:07:55

标签: angular sap spartacus-storefront

我在SmartEdit中预览页面时遇到一些问题。有时,“ Loading ...”将永远停留在那里,并且此问题似乎与DOM加载时间有关。

如果我打开了devtools控制台,则该页面可能会加载1/10次,在Mozilla上,它可以在没有浏览器控制台的情况下运行10/10。因此,基本上,设置似乎很好,除了这个烦人的永久性加载问题之外,一切都按预期工作。

在“网络”标签中,cx预览崩溃,出现200错误,并且尽管页面中的组件在“加载”叠加层的后面可见,但仍保留了“加载”状态

在cx-preview调用出现200错误之前,还有另一个红色的,其末尾带有文本(已取消)。

enter image description here

enter image description here

更新: 似乎在序列化器中设置cx-preview的问题。 如果删除state.url.length条件,则加载将是永久的。

import { RouterStateSnapshot } from '@angular/router';
import {
  ActivatedRouterStateSnapshot,
  CmsActivatedRouteSnapshot,
  PageContext,
  PageType
} from '@spartacus/core';

export class AokCuRouterStateSerializer {
  serialize(routerState: RouterStateSnapshot): ActivatedRouterStateSnapshot {
    const { url } = routerState;
    const { queryParams } = routerState.root;

    let state: CmsActivatedRouteSnapshot = routerState.root as CmsActivatedRouteSnapshot;
    let cmsRequired = false;
    let context: PageContext;

    while (state.firstChild) {
      state = state.firstChild as CmsActivatedRouteSnapshot;

      if (state.data && state.data.cxCmsRouteContext) {
        context = state.data.cxCmsRouteContext;
      }

      if (
        !cmsRequired &&
        (context ||
          (state.routeConfig &&
            state.routeConfig.canActivate &&
            state.routeConfig.canActivate.find(
              x => x && x.guardName === 'CmsPageGuard'
            )))
      ) {
        cmsRequired = true;
      }
    }
    const { params } = state;

    if (state.url.length > 0 && state.url[0].path === 'cx-preview') {
      context = {
        id: 'smartedit-preview',
        type: PageType.CONTENT_PAGE
      };
    } else {
      if (params['productCode']) {
        context = { id: params['productCode'], type: PageType.PRODUCT_PAGE };
      } else if (params['orderCode']) {
        context = {
          id: 'order-' + params['orderCode'],
          type: PageType.CONTENT_PAGE
        };
      } else if (params['categoryCode']) {
        context = { id: params['categoryCode'], type: PageType.CATEGORY_PAGE };
      } else if (params['brandCode']) {
        context = { id: params['brandCode'], type: PageType.CATEGORY_PAGE };
      } else if (state.data.pageLabel !== undefined) {
        context = { id: state.data.pageLabel, type: PageType.CONTENT_PAGE };
      } else if (!context) {
        if (state.url.length > 0) {
          const pageLabel =
            '/' + state.url.map(urlSegment => urlSegment.path).join('/');
          context = {
            id: pageLabel,
            type: PageType.CONTENT_PAGE
          };
        } else {
          context = {
            id: 'homepage',
            type: PageType.CONTENT_PAGE
          };
        }
      }
    }

    return { url, queryParams, params, context, cmsRequired };
  }
}

1 个答案:

答案 0 :(得分:0)

显然,这是一个与SmartEdit和Spartacus相关的问题,并将在以后的某处修复:https://github.com/SAP/spartacus/issues/2358-检查最新更新