Open fbartho opened 1 month ago
I did this in an earlier implementation, but removed it before release. However, very roughly I think the solution could be trivial: all elements are rendered with the current page context provided, so they can adjust that as needed – Images that use icons could enable the icon CSS, CodeBlock with a language could add that highlighter, etc.
Some Components depend on specific assets like CSS, JS, or other resources. It’d be great if there was a way for components to dynamically register those assets only if they’re used by the page they’re rendering into.
As an example, there’s some Ignite code that tries to figure out which languages are in use in order to add the correct
prism
code for that language to the page. This relies currently on users configuring the languages at the page level.With an appropriate API, the Prism CodeBlock component could instead inspect the language it’s provided as an attribute, and request that Ignite ensures the dependency for that language was included.
Proposal
@depends(on: […])
RenderContext
methodregisterDependency
under the hood, these could be implemented using the
willRender
method proposed elsewhereAn advantage of this approach is that Ignite’s core could be agnostic of what JS/CSS is in your page, and the Bootstrap-specific components would only pull in bootstrap if they’re used. The majority of Ignite’s components/Elements seem agnostic of Bootstrap.