fast
fast copied to clipboard
Adds support for FASTElement hydration
Adds support for FASTElement hydration
Pull Request
📖 Description
This PR consolidates Server-Side Rendering (SSR) related changes made by @nicholasrice from a Microsoft internal fork. Below is the commit description from the original PR.
This PR enables hydration of FAST custom elements from HTML emitted by SSR processes.
This PR has three core areas:
- I've added a SSR example application to
/examplesto aid in debugging. This code was ported from external FAST. - I've updated
fast-ssrto accept aemitHydratableMarkupattribute. Configuring this option causes markers to be emitted during template rendering. These markers manifest either as element attributes (for attribute bindings / directives) and HTML comments (for content bindings / directives). These markers are used byfast-elementto identify which elements belong to which views and bindings. -
fast-elementhas been updated to support hydrating views, details below.
fast-element changes:
- Updated
HydratableElementControllerto invokehydrateon it's template during connection, also refactoredElementControllerbase class to allow better direct extension by makingprivatepropertiesprotected. - Added a
HydrationViewclass. An instance of this class represents a region of DOM created by a template during the SSR process. When this class binds for the first time, it walks the DOM tree between it's first and last nodes looking for binding markers emitted duringfast-ssrrendering. When it finds binding markers, it associates the template binding to that DOM location. After all the nodes have been walked and the bindings targeted, behaviors for those bindings are created and bound, hooking up observable behavior. - Updated bindings and directives to handle hydration scenarios. Unfortunately, I was not able to identify a good way to separate the hydration behavior from the CSR binding behavior without implementing a large amount of code duplication. Instead, I added a lightweight
isHydratable()test to determine whether bindings should go through hydration flows. Bindings and directives were then updated to not affect DOM during hydration flows.
🎫 Issues
- https://github.com/microsoft/fast/issues/5182
- https://github.com/microsoft/fast/issues/5577
👩💻 Reviewer Notes
📑 Test Plan
✅ Checklist
General
- [x] I have included a change request file using
$ yarn change - [x] I have added tests for my changes.
- [x] I have tested my changes.
- [ ] I have updated the project documentation to reflect my changes.
- [ ] I have read the CONTRIBUTING documentation and followed the standards for this project.
⏭ Next Steps
Thanks for bringing this over @prabhujayapal! Give me a few days and I can get a review on it.