Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ded9bc
Track and clear initial applied params on slotted child views
schultek Nov 12, 2026
0318557
Update CHANGELOG.md
schultek Nov 12, 2026
5e509f4
fix: track applied params with data-j-apply and client boundary markers
schultek Nov 13, 2026
eb7000b
refactor: add data-j-apply in AppliedParamsAdapter when client bounda…
schultek Nov 13, 2026
08fe1df
Merge remote-tracking branch 'origin/main' into fix/slotted-child-vie…
schultek Nov 13, 2026
57e6ad9
refactor: walk client boundary subtree to apply data-j-apply without …
schultek Nov 13, 2026
ae6dc03
perf: stop descending at nested client boundaries when applying params
schultek Nov 13, 2026
cbe6eb7
test: remove obsolete apply= substring test now that <...> delimiters…
schultek Nov 13, 2026
0ec58cb
Use compact key-prefix encoding for data-j-apply with delimiter escaping
schultek Nov 13, 2026
5aa7b67
Only add data-j-apply to server component elements
schultek Nov 13, 2026
23da14d
Merge branch 'main' into fix/slotted-child-view-applied-params
schultek Nov 13, 2026
e9212ea
Ignore RenderFragment in client apply check and only emit data-j-appl…
schultek Nov 13, 2026
a0d3269
Optimize client-managed apply check and support nested client compone…
schultek Nov 13, 2026
df2fcab
Isolate client-managed apply bounds between parent and current server…
schultek Nov 13, 2026
5ee7b4d
Simplify _isClientManaged to depth check and add test for client-defi…
schultek Nov 13, 2026
ba88b5e
Deduplicate apply matching and diff computation to DomElement and use…
schultek Nov 13, 2026
d464390
Store applied params in updateRenderObject and reuse in computeApplie…
schultek Nov 13, 2026
4928e58
Restore Map.of in updateRenderObject
schultek Nov 13, 2026
d55a89b
Hide DomParamsElement from public jaspr.dart export
schultek Nov 13, 2026
3e1079f
Address review comments: support SVG and range anchors in hydration, …
schultek Nov 13, 2026
e5d145e
Address review comments: account for dedicated fields in attribute di…
schultek Nov 18, 2026
022fbe4
Merge branch 'main' into fix/slotted-child-view-applied-params
schultek Nov 18, 2026
1c26931
Address review comments: respect child slot boundaries during hydrati…
schultek Nov 18, 2026
73211a5
Do not apply wrapper styles to elements with raw style attributes
schultek Nov 18, 2026
b533129
Merge branch 'main' into fix/slotted-child-view-applied-params
schultek Nov 18, 2026
9a91b8d
Address review comments: simplify style merging, align raw class hand…
schultek Nov 18, 2026
5ee41f0
Add skipped hydration test for raw class attributes
schultek Nov 18, 2026
fb1ce0d
Merge branch 'main' into fix/slotted-child-view-applied-params
schultek Nov 18, 2026
d5f9575
Update CHANGELOG with Component.apply behavior changes
schultek Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/concepts/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ The above component renders the following HTML:
</div>
```

#### Precedence and Merging Rules

When properties are applied, the following rules and special cases apply:

- **Target Precedence**: Properties defined on the target element always take precedence over applied properties. Where multiple nested `Component.apply()` components target the same element, inner (closer) wrappers take precedence over outer ones.
- **Classes**: Applied class names are merged as a set of whitespace-separated tokens with the target's classes. If a target element specifies class names via `attributes: {'class': ...}`, classes from `Component.apply()` are **never applied** to that element to preserve raw attributes and prevent duplicate HTML attributes.
- **Styles**: Applied styles are merged on a per-property basis. Any style property already defined on the target element is preserved. If a target element specifies raw inline styles via `attributes: {'style': ...}`, styles from `Component.apply()` are **never applied** to that element to avoid corrupting raw style declarations or unsafe mixing of structured and raw styles.
- **ID & Attributes**: An `id` or other attributes defined on the target element (or in its `attributes` map) are never overwritten by applied values.
- **Events**: Event listeners on the target element take precedence; applied listeners are added as supplementary listeners if not already bound.

## Formatting Whitespace

When pre-rendering your components in **server** and **static** mode, Jaspr will output cleanly formatted html on a best-effort basis. This means it will add newlines and indentations to your html element, while trying to not affect the way the html is rendered.
Expand Down
6 changes: 6 additions & 0 deletions packages/jaspr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

### Fixes

- Fixed `Component.apply` not applying to server-rendered components inside `@client` components on the client, and fixed applied properties not being removed from slotted child elements when toggled off.
- Applied properties and classes are now tracked and cleanly removed on toggle-off without clearing the child element's own properties.
- Target-defined properties always take precedence over applied properties, with structured styles merging on a per-property basis.
- Raw `class` and `style` attributes defined in an element's `attributes` map are preserved verbatim without wrapper styles or classes applied, preventing duplicate HTML attributes.
- Child elements with an `id` or attributes in their `attributes` map are never overwritten by applied values.
- Slotted child views reset applied parameters and event listeners on reload before re-hydration.
- Fixed a server built with `dart build cli` on Linux with Dart 3.14 or later not finding its `web` directory and failing with "Could not resolve project directory containing pubspec.yaml" when no `pubspec.yaml` is above it. Since Dart 3.14 such a bundle keeps the snapshot in `lib/libdartaot<name>.so`, which `Platform.script` points at.
- Fixed `jaspr serve` with Flutter embedding or plugins failing on Flutter 3.50, which moved the precompiled DDC SDK to `kernel/ddc/canary` and `kernel/ddc/stable`.
- Fixed `jaspr build` and `jaspr serve` stopping a build daemon that another Jaspr process in the same directory started, which left that process serving empty 503 responses.
Expand Down
8 changes: 7 additions & 1 deletion packages/jaspr/lib/jaspr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export 'src/foundation/scheduler.dart';
export 'src/foundation/sync.dart';
export 'src/foundation/synchronous_future.dart';
export 'src/framework/framework.dart'
hide GlobalComponentsBinding, DomRenderObjectElement, ApplyParams, DomParamsResolver;
hide
GlobalComponentsBinding,
DomRenderObjectElement,
ApplyParams,
DomParamsResolver,
ApplyDomComponent,
DomParamsElement;
export 'src/stub/app_context_stub.dart'
if (dart.library.js_interop) 'src/client/app_context.dart'
if (dart.library.io) 'src/server/app_context.dart'
Expand Down
56 changes: 52 additions & 4 deletions packages/jaspr/lib/src/client/component_anchors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:universal_web/web.dart' as web;

import '../../client.dart';
import '../dom/styles/styles.dart';
import '../dom/validator.dart';

sealed class ComponentAnchor {
Expand All @@ -16,12 +17,24 @@ sealed class ComponentAnchor {
}

class ClientComponentAnchor extends ComponentAnchor {
ClientComponentAnchor._(super.name, super.key, super.startNode, this.data);
ClientComponentAnchor._(super.name, super.key, super.startNode, this.data, this.apply);

String? data;
String? apply;
late FutureOr<ClientBuilder> builder;
final List<ServerComponentAnchor> serverAnchors = [];

List<_ApplyData> get _decodedApplyParams {
if (apply case final rawApply?) {
final unescaped = const DomValidator().unescapeMarkerText(rawApply);
final list = jsonDecode(unescaped) as List;
return [
for (final item in list) _ApplyData.fromMap(item as Map<String, dynamic>),
];
}
return const [];
}

/// The decoded parameters for this client component.
Map<String, Object?> get _decodedParameters {
if (data case final rawData?) {
Expand All @@ -43,7 +56,19 @@ class ClientComponentAnchor extends ComponentAnchor {
assert(builder is ClientBuilder, 'ClientComponentAnchor was not resolved before calling build()');

final clientParameters = ClientParams(_decodedParameters, serverAnchors);
final component = (builder as ClientBuilder)(clientParameters);
var component = (builder as ClientBuilder)(clientParameters);

for (final apply in _decodedApplyParams) {
component = Component.apply(
target: apply.target,
id: apply.id,
classes: apply.classes,
styles: apply.styles != null ? Styles(raw: apply.styles) : null,
attributes: apply.attributes,
child: component,
);
}

return Builder(key: _ClientAnchorKey(key), builder: (_) => component);
}

Expand Down Expand Up @@ -146,7 +171,9 @@ class ServerComponentElement extends BuildableElement {
}
}

final _clientStartRegex = RegExp('^${DomValidator.clientMarkerPrefixRegex}(\\S+)(?:\\s+#(\\S*))?(?:\\s+data=(.*))?\$');
final _clientStartRegex = RegExp(
'^${DomValidator.clientMarkerPrefixRegex}(\\S+)(?:\\s+#(\\S*))?(?:\\s+data<([^>]*)>)?(?:\\s+apply<([^>]*)>)?\$',
);
final _clientEndRegex = RegExp('^/${DomValidator.clientMarkerPrefixRegex}(\\S+)\$');

final _serverStartRegex = RegExp('^s${DomValidator.clientMarkerPrefixRegex}(\\d+)(?:\\s+#(\\S*))?\$');
Expand Down Expand Up @@ -183,6 +210,7 @@ List<ClientComponentAnchor> extractAnchors({List<web.Node>? nodes}) {
final name = match.group(1)!;
final key = match.group(2);
final data = match.group(3);
final apply = match.group(4);

final resolvedKey = key != null
? '@$name#$key'
Expand All @@ -192,7 +220,7 @@ List<ClientComponentAnchor> extractAnchors({List<web.Node>? nodes}) {
return '@$name-${anchors.length}-$count';
})();

anchors.add(ClientComponentAnchor._(name, resolvedKey, currNode, data));
anchors.add(ClientComponentAnchor._(name, resolvedKey, currNode, data, apply));
continue;
}

Expand Down Expand Up @@ -269,3 +297,23 @@ List<ClientComponentAnchor> extractAnchors({List<web.Node>? nodes}) {

return clientAnchors;
}

class _ApplyData {
_ApplyData({required this.target, this.id, this.classes, this.styles, this.attributes});

final ApplyTarget target;
final String? id;
final String? classes;
final Map<String, String>? styles;
final Map<String, String>? attributes;

factory _ApplyData.fromMap(Map<String, dynamic> map) {
return _ApplyData(
target: map['t'] != null ? ApplyTarget.fromMap(map['t'] as Map<String, dynamic>) : ApplyTarget.anyChild,
id: map['i'] as String?,
classes: map['c'] as String?,
styles: (map['s'] as Map?)?.cast<String, String>(),
attributes: (map['a'] as Map?)?.cast<String, String>(),
);
}
}
Loading
Loading