Remix "Enhancers" #2386
ryanflorence
started this conversation in
Proposals
Replies: 2 comments
-
I know it's a long shot... But what would require me to specify what is an enhancer? Could Remix not determine what needs to be enhanced automatically based on components that use hooks/events 🤔 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Interesting discussion on some different tactics people are exploring https://twitter.com/Katy_Wings/status/1283384379549650946?s=20 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Don't have a good name for this API yet, but it's a lot like "partial hydration" or even "progressive enhancement".
A lot of the time your page is mostly static markup with just a few dynamic bits (a carousel, some tabs, a dropdown, a fancy form, a chart, etc.) At the moment, you have to bring in a lot of JavaScript and HTML on the initial page load to have a highly dynamic page.
Enhancements will allow you to render mostly static markup, and then just "enhance" a few roots.
Two approaches, I don't know pros and cons yet, but probably have some. In either case, Remix will statically analyze your code to find enhancements at build time and create bundled entry points out of them. At runtime, we know the asset manifest and can load that bundle with the same mechanisms that we load route bundles:
/_remix/manifest
. When an enhancement is on the page, its JavaScript will be loaded and executed.Dynamic Component
Point to a file in your app and Remix will bundle it up:
Or use inline JavaScript:
Static function
Alternative approach is a static function, unsure of pros-cons right now.
Magic variables
You probably want access to the root element almost every time, could be like
__filename
.You probably want to pass in some stuff you know from the outer world.
Or require an enhancement to be a function, then we can pass stuff in rather than use magic globals:
React Root Enhancers
While the previous examples would just run some really basic JavaScript, if you want a React root, we could have a special component for that that would automatically create a react root, render into it, and pass props down from the server app to it.
Server placeholder
If children are provided, they are the server placeholder.
For
EnhanceReact
, we can call renderToString() on it.Bring our friends to the party
While React will be rendering the server generated HTML, there's no reason we couldn't create something like a Svelte enhancer:
There's a good chance some of your marketing pages would do well to not load all of React onto the page!
Separate Scripts component
To get these scripts on the page we'll likely need a separate
<Scripts/>
component, like:Because some pages don't need the React app scripts, but will need enhancers.
Beta Was this translation helpful? Give feedback.
All reactions