Repository navigation
Track and clear initial applied params on slotted child views - #987
Conversation
Package Version ReportThe following packages have been updated: |
There was a problem hiding this comment.
🟡 Changes recommended
Component.apply cleanup can remove child-owned DOM values and leave applied styles behind because ownership tracking and CSS value comparisons are incorrect.
2 open issues
What changed in this PR
This PR updates Jaspr’s slotted child views to track Component.apply parameters already present in server-rendered HTML, allowing client updates to remove them when toggled off.
Changes:
- Records existing applied classes and matching IDs, styles, and attributes for cleanup.
- Adds a browser regression test covering removal of initially rendered parameters.
- Documents the fix in the changelog.
| File | Description |
|---|---|
packages/jaspr/test/client/slotted_child_view_test.dart |
Tests cleanup of applied parameters initially present in HTML. |
packages/jaspr/lib/src/client/slotted_child_view.dart |
Updates tracking of existing DOM values for later cleanup. |
packages/jaspr/CHANGELOG.md |
Records the applied-parameter cleanup fix. |
Review effort: Balanced
b60f237 to
5e509f4
Compare
…w-applied-params # Conflicts: # packages/jaspr/CHANGELOG.md # packages/jaspr/lib/src/client/slotted_child_view.dart # packages/jaspr/test/server/client_test.dart
…AppBinding tracking
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved apply-ownership and boundary-handling bugs can remove server-owned classes during hydration or leave applied properties behind after disabling an apply or unmounting a view.
6 open issues
Load apply metadata from range-slot anchors · New Hydrate apply ownership on SVG roots · New Clear stale appliedDiff before each render update · New Stop apply collection at the current server-child boundary · New Ignore render fragments when resolving direct DOM children · New Exclude server-only apply contributions from cleanup metadata · New
2 resolved since last review
Review effort: Balanced
…y for client-managed params
… extension getter for hasInheritedDomParams
…and fix boundary check for server-child root
…ffs, reset hydration on reload, and collect server-child root apply
…on and include inline styles in baseline
…ling, and clean up ChildSlot filter
|
I agree with landing this. The more I dive into it the more edge cases pop up, but most of them are from uses of .apply that I never intended. I added a few skipped test cases that test edge cases that are not yet fully supported (maybe never will) just to keep track. |
parlough
left a comment
There was a problem hiding this comment.
Thanks for those adjustments and additional definition of the merging rules! Still looks good to me :)


Description
This PR fixes two related issues when using
Component.applyacross server and client boundaries:Component.applyabove a@clientcomponent was lost on the client after hydration.@clientcomponent couldn't clean up initial server-applied params when toggled off on the client.Case 1:
Component.applyAbove a@clientComponentThe Problem
When
Component.applywrapped a@clientcomponent on the server:The server rendered
<button class="btn-primary">into the initial HTML, but the client marker comment was just<!--@my_client_button-->. During client hydration,MyClientButtonwas mounted withoutComponent.applyin its context. Upon hydration or the first client-sidesetState(), the button rebuilt withoutbtn-primary, causing the applied classes/styles to disappear!The Fix
Component.applycomponents and serializes them into the client boundary marker:apply<...>and wraps the client component inComponent.apply(...), ensuring inherited DOM params remain active across client-side state changes and rebuilds.Case 2: Server Component Slotted Into a
@clientComponentThe Problem
When a server component is passed as a child/slot into a
@clientcomponent:The server baked
class="label highlight"into the server-rendered HTML. On the client,SlottedChildViewmounts the server-rendered DOM nodes, but had no record of what params were initially applied by the server versus originally owned by the child. If client-side state later toggledComponent.applyoff:SlottedChildViewcouldn't distinguish applied values from child-owned values.highlightor risked removing child-owned classes/properties likelabel.The Fix
data-j-apply):ServerComponentAdapterattaches a compactdata-j-applyattribute tracking the server-applied diff:i:<id>;c:<classes>;s:<styles>;a:<attributes>) with lightweight percent-escaping for%,;,,to avoid verbose JSON"escaping in HTML attributes.data-j-applybecause they rebuild in Dart and inherit from theapply<...>marker (Case 1).SlottedChildViewhydrates initial applied parameters fromdata-j-apply, registers them in_appliedParams, and strips the attribute from the DOM.Component.applyis toggled off or updated on the client,_resetElementParamscleanly reverts only the applied values while safely preserving child-owned values (e.g. removinghighlightwhile leavinglabel).Type of Change
Ready Checklist
CHANGELOG.mdfile using the semantic_changelog format.///).