Giter VIP home page Giter VIP logo

Comments (8)

jjergus avatar jjergus commented on June 16, 2024 1

In my example I thought we'd just mention the double-rendered element's name (Can't render because a child (<br>) was already rendered) but the full path is nicer, I like that.

from xhp-lib.

lexidor avatar lexidor commented on June 16, 2024

I thought I had fixed that confusing error message in ac61647, but I guess not for nested cases. I'll see if there is a fix possible which generates such an error message, which doesn't have a heavy runtime cost.

from xhp-lib.

lexidor avatar lexidor commented on June 16, 2024

This may also require addressing in the migration guide, it seems that "Can't ... after render" errors are much more common in v4.

And yes, Can't X after render is new in XHP-4.

from xhp-lib.

jjergus avatar jjergus commented on June 16, 2024

I've also noticed that these errors often pop up when you try to do something sketchy during rendering:

use XHPHTMLHelpers;
protected async function renderAsync(): Awaitable<x\node> {
  $id = $this->getID();
  // ...
}

will give you "Can't addAttribute after render" if ID wasn't set previously.

from xhp-lib.

lexidor avatar lexidor commented on June 16, 2024

I've also noticed that these errors often pop up when you try to do something sketchy during rendering:

use XHPHTMLHelpers;
protected async function renderAsync(): Awaitable<x\node> {
  $id = $this->getID();
  // ...
}

will give you "Can't addAttribute after render" if ID wasn't set previously.

That is because ->__isRendered = true happens before ->renderAsync().

  protected async function __renderAndProcess(): Awaitable<node> {
    if ($this->__isRendered) {
      throw new UseAfterRenderException(
        'Attempted to render XHP element twice',
      );
    }
    $this->__isRendered = true; // < needs to be moved from here
    if (\Facebook\XHP\ChildValidation\is_enabled()) {
      $this->validateChildren();
    }

    $composed = await $this->renderAsync();
    // to here (1)
    $composed->__transferContext($this->getAllContexts());
    if ($this is HTML\HasXHPAttributeClobbering_DEPRECATED) {
      $this->transferAttributesToRenderedRoot($composed);
    }
    // or here (2)
    return $composed;
  }

@fredemmott We want to allow modification during ->renderAsync(), right?

from xhp-lib.

lexidor avatar lexidor commented on June 16, 2024

It would be better if it said something like Can't render because a child (<li>) was already rendered instead of Can't replaceChildren after render.

I can't quite match that, but this is already worlds better. #281

<div><ui:div><ui:div><span>{$br}</span></ui:div></ui:div></div>
//                          ^^^ rendered already
Attempted to render XHP element twice
Via XHPPath: HTML\\div -> ui\\div -> HTML\\div -> ui\\div -> HTML\\div -> HTML\\span -> HTML\\br.

XHPPath will only be included when a subnode throws during render.
If you are doing something to a node directly, the exception messages are unchanged.

from xhp-lib.

lexidor avatar lexidor commented on June 16, 2024

Fixed by #281

from xhp-lib.

jjergus avatar jjergus commented on June 16, 2024

Thanks!

from xhp-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.