Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-24007

Macro returning a MacroBlock is not displayed by the BlockAsyncRenderer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 14.10.20, 17.10.2
    • Rendering - Async
    • None
    • Unknown

    Description

      Created a kind-of-minimal example that can reproduce the issue. I tried to create the examples in Groovy components but didnt manage.

      Macro class:

      @Component
      @Singleton
      @Named("test123")
      public class TestClass extends AbstractMacro<Object>
      {
          @Inject
          private ComponentManager componentManager;
      
          @Inject
          private BlockAsyncRendererExecutor executor;
      
          public TestClass()
          {
              super("TestClass");
          }
      
          @Override
          public boolean supportsInlineMode()
          {
              return false;
          }
      
          @Override
          public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
              throws MacroExecutionException
          {
              AsyncRendererConfiguration configuration = new AsyncRendererConfiguration();
      
              Block result = null;
      
              try {
                  TestAsyncRenderer asyncRenderer =
                      componentManager.getInstance(TestAsyncRenderer.class);
                  asyncRenderer.initialize(this, context);
                  result = executor.execute(asyncRenderer, configuration);
              } catch (JobException | RenderingException | ComponentLookupException e) {
                  throw new RuntimeException(e);
              }
              return result instanceof CompositeBlock ? result.getChildren() : Collections.singletonList(result);
          }
      
          public List<Block> internalExecute()
          {
              return Collections.singletonList(new MacroBlock("info", Collections.emptyMap(), "Hello there", false));
          }
      }

      Async renderer class:

      @Component(roles = TestAsyncRenderer.class)
      public class TestAsyncRenderer extends AbstractBlockAsyncRenderer
      {
          private TestClass testClass;
      
          private MacroTransformationContext context;
      
          private Syntax targetSyntax;
      
          public void initialize(TestClass testClass, MacroTransformationContext context)
          {
              this.context = context;
              this.testClass = testClass;
              this.targetSyntax = context.getTransformationContext().getTargetSyntax();
          }
      
          @Override
          protected Block execute(boolean async, boolean cached) throws RenderingException
          {
              List<Block> result = testClass.internalExecute();
              return new GroupBlock(result);
          }
      
          @Override
          public boolean isInline()
          {
              return false;
          }
      
          @Override
          public Syntax getTargetSyntax()
          {
              return targetSyntax;
          }
      
          @Override
          public List<String> getId()
          {
              return createId("test", "async", "renderer", RandomUtils.nextInt());
          }
      
          @Override
          public boolean isAsyncAllowed()
          {
              return true;
          }
      
          @Override
          public boolean isCacheAllowed()
          {
              return false;
          }
      } 

      Result:

      The page containing the macro call `test123` is empty. If the page has the `async=false` query parameter, then the page displays the `info` macro as expected.

      A workaround to this issue would be to render the `info` block macro into xwiki syntax and the parse it with the `MacroContentParser`.

      Im also not sure if the macro returning the `MacroBlock` is problematic, the async renderer or if its a problem in the platform.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tcaras Teodor Caras
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: