Closed pauleveritt closed 2 months ago
Yes, this is a reasonable requirement. In Jeasx (which is the initial reason for jsx-async-runtime) we use "guards" to prepare data before rendering, so this usually is not a problem.
But I will give it some thought if there's an easy way to implement such a feature.
This feature can now be implemented via jsx interception (introduced in 0.5.0). Have a look at the example app:
https://github.com/jeasx/jsx-async-runtime/blob/main/example/src/index.jsx
I'd like let subcomponents to add CSS/JS that goes in
<head>
. There are similar needs/patterns, e.g. shoving data into Open Graph<meta>
in the<head>
.In React, this pattern was popular with various "React Helmet" approaches. In
preact-render-to-string
they recommended context provider plususeState
. (It didn't ultimately work.)11ty is solving this with bundles. During render, the "bundle" writes a magic/structured string into where the "bucket" data is supposed to go. Then, any part of the system can set data into a bucket.
After render, something scans for the magic string and writes in the bucket contents.
I wonder if
jsx-async-runtime
could have some kind of mini-lifecycle that does this a bit more sanely. Or, some other technique: async generators, or two-pass JSX trees (to avoid parsing strings).