-
Notifications
You must be signed in to change notification settings - Fork 11
setTimeout
callback doesn't seem 100 % reliable
#69
Comments
setTimeout
callback doesn't seem 100 % reliablesetTimeout
callback doesn't seem 100 % reliable
setTimeout
callback doesn't seem 100 % reliablesetTimeout
callback doesn't seem 100 % reliable
@senadir and I have been looking more deeply into this, and there doesn't seem to be a way to solve this using the mutation observer alone. So unless there's a new idea, we would need to go with the element hack described above. @senadir suggested that instead of a custom element, we could use a combination of a CSS-neutral element (like |
HTML comments are picked up by In my testing, it seems that |
While |
I'd be happy to know the rationale behind the First of all using
Also, from a custom element life-cycle perspective,
|
We need a callback that triggers once the custom element's children have been created because they are required for the hydration (to extract sourced attribute, use |
Given this is an element in the live document. So in DOM "Have been created" is not an event that happens only once, but may happen later in runtime. New children elements could be added, and old ones could be removed. So to be precise on what we need, I guess "created" is also not the thing we need, as children may be created far before or When you write "sourced attribute" what do you mean by "sourced" and that's the attribute of what? Please correct me if I'm wrong here because it's all based on suspicions ;) And I don't know the lingo you use in this project, but rather stick to HTML definitions. What we need here is that: Run a piece of code:
So if the above is what we want, for sure If we really want to achieve "parser reaches the end of our element" then the problem is HTML parser does expose any callback for parsing the end tag. AFAIR this is due to how the HTML parser is implemented deep in browser engines. The only element that somewhat has that feature is the That is precisely the reason why Declarative Shadow DOM eventually ended up being specified & implemented as BTW, DSD was created among others to support Server Side Rendering. So I think it's worth looking for inspiration, especially since most of the points I mentioned above, were also discussed and covered there. |
Also, as I usually like to step back from the solution, to define a problem, and find a new out without a bias of having one in mind: Do we really need to do it "once the custom element's children have been created"? If so, why? Maybe we can hydrate the elements as they come? |
Sourcing attributes is a common way to store block attributes in the HTML to avoid duplication of data and sync issues: documentation.
Yes. Before we can hydrate the block, we need to get the sourced attributes, whose values are stored somewhere in the children instead of the JSON (block comment) and we also need all the children already created to be able to call React/Preact's By the way, this issue is only relevant if we finally use a custom element to do the hydration, which is still not clear. Let's continue that conversation on this issue instead. |
Closed as we're not actively working on this experiment anymore. |
As discussed here, it looks like the setTimeout callback we are using inside
connectedCallback
is not 100% reliable. It seems to be running before the HTML parsing has finished. Here you have one example of when this is a problem:It seems that if the page is loaded quickly, the state defined in PHP and sent as an attribute is undefined in the view.js files. These are the two examples I'm talking about: Title & Date.
As Luis shared here, Jake Archibald talks about this problem in this video. He proposes:
The text was updated successfully, but these errors were encountered: