enonic / app-contentstudio

Content Studio of Enonic XP
GNU General Public License v3.0
10 stars 4 forks source link

Refresh page when new components with page contributions are inserted #2034

Open Bellfalasch opened 4 years ago

Bellfalasch commented 4 years ago

XP and Content Studio ignores PageContributions when components are inserted into the Page Editor. This means that react components will lack any styling the first time, until you reload the Page Editor (or add components that already are within the Page Editor before it loaded the first time). Enonic's planned solution for this is to just reload the Page Editor whenever a component uses PageContributions, a rather blunt solution.

We could instead check for req.mode == 'edit' and then instead of adding our things as PageContribution we'll inline scripts and styles.

This would require the PR enonic/lib-react4xp#32 to be merged first. Gjensidige has a working example of this running, will tweak it and send a PR.

espen42 commented 4 years ago

Sounds like a good suggestion!

sigdestad commented 4 years ago

Hmm, not so sure. Could easilycause conflicts. We are planning to automatically reload Page editor if components with contributions are added.

sigdestad commented 4 years ago

Also, why not load all relevant css always? This should be faster and cleaner since the browser will cache it?

espen42 commented 4 years ago

For reference, I'd really like it if we could support stuff like https://github.com/css-modules/css-modules (because working with it is nice!). And just like react JSX, that is declared in a kind of, uh, let's call it pseudo-JS, and compiled to regular assets by webpack - often originating in the same JSX files. That means it will be part of the same compile flow as react, and the css assets must get the same treatment as the react assets - and probably can't be used in the same way as "regular XP css".

This support might be an awkward thing to get going, or not a big problem at all. We'll see what's the best approach.

espen42 commented 4 years ago

@sigdestad , what kind of conflicts are you concerned about?

sigdestad commented 4 years ago

The idea behind Page contributions is typically to have a single script that is only placed on a Page once. If your content can be inlined, it should probably not have been a contribution in the first place?

espen42 commented 4 years ago

enonic/lib-react4xp#32 (CSS-modules support) is merged and part of the alpha branch - which is starting to look good now, and should be a good foundation for a closer look at this issue.

sigdestad commented 4 years ago

We have concluded this is a generic issue related to the page editor, and as such must be handled in Content Studio/XP