compoxure icon indicating copy to clipboard operation
compoxure copied to clipboard

Layout slots don't work with cx-url

Open siosphere opened this issue 6 years ago • 2 comments

I'm not sure if this was the intended use-case. But if I have a layout that defines slot, and my app returns something like: <div cx-url="/some/other/place"></div> And /some/other/place returns the url with the cx-use-slots, I would expect it to be replaced. This doesn't happen though.

I've tried a few different ways. I've tried adding the cx-url on the cx-use-slot: <div cx-use-slot="siosphere:body" cx-url="/some/place/">Didn't work</div>

I got it to somewhat work when I nested the cx-url under the cx-use-slot but that doesn't quite do the use case I'm looking for.

Is there a different approach I should be doing? Essentially I want several fragment renderers to be able to write to the same slots (which the documentation says should be possible) but any cx-url that returns cx-use-slots are just completely ignored. I verified that cx-parse-me: true headers are being returned at all appropriate stages.

siosphere avatar Aug 29 '18 23:08 siosphere

To get this we should change the current implementation of the layout feature. This is what happens now:

  • we get the page
  • we extract the slots from the page (cx-use-slot) and put the strings on a dictionary
  • we get the layout
  • we parse the layout
    • during the parsing (parxer) cx-define-slot will fill the slot (using the dictionary) https://github.com/tes/parxer/blob/master/lib/plugins/define-slot.js#L20
    • and run parse on it https://github.com/tes/compoxure/blob/master/src/middleware/htmlparser.js#L111

We could change the process like this:

  • we get the page
  • we parse the page
  • we extract the slots from the page (cx-use-slot) and put the (already parsed) strings on a dictionary
  • we get the layout
  • we parse the layout
    • during the parsing (parxer) cx-define-slot will fill the slot (using the dictionary) https://github.com/tes/parxer/blob/master/lib/plugins/define-slot.js#L20
    • and we won't run parse on it

sithmel avatar Sep 06 '18 09:09 sithmel

We have attempted to fix the problem with the branch parse-order-fix. We followed the order explained in the comment above. We realised that is not going to work as expected: There are many compoxure behaviours that depends on the parsing order, and parsing the entire page BEFORE the layout creates many issues. For example it changes the order of cx-url in relation with cx-bundle and therefore some bundle can't resolve its url. The feature that removes duplicated bundles/libraries is impacted too.

We are thinking to close as "won't do" but we can leave it open in case we have some idea in the next weeks.

sithmel avatar Nov 01 '18 16:11 sithmel