Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sliver child is text without renderer should not accpet #898

Merged
merged 5 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
15 changes: 15 additions & 0 deletions integration_tests/specs/css/css-display/sliver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,19 @@ describe('display sliver', () => {
await snapshot();
});

it('sliver child is text or comment', async () => {
wssgcg1213 marked this conversation as resolved.
Show resolved Hide resolved
var comment = document.createComment('HelloWorld');
var text = document.createTextNode('HelloWorld');
// Empty text node has different logic in backend.
var emptyText = document.createTextNode('');

var container = createSliverBasicCase();

container.insertBefore(emptyText, container.firstChild);
container.insertBefore(text, container.firstChild);
container.insertBefore(comment, container.firstChild);
expect(container.childNodes.length).toEqual(103);

await snapshot(); // Not throws error is ok.
});
});
1 change: 1 addition & 0 deletions kraken/lib/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export 'src/dom/text_node.dart';
export 'src/dom/window.dart';
export 'src/dom/document.dart';
export 'src/dom/document_fragment.dart';
export 'src/dom/sliver_manager.dart';

// Elements
export 'src/dom/elements/semantics_text.dart';
Expand Down
1 change: 0 additions & 1 deletion kraken/lib/src/dom/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'package:kraken/bridge.dart';
import 'package:kraken/css.dart';
import 'package:kraken/dom.dart';
import 'package:kraken/rendering.dart';
import 'package:kraken/src/dom/sliver_manager.dart';
import 'package:meta/meta.dart';

import 'element_native_methods.dart';
Expand Down
10 changes: 4 additions & 6 deletions kraken/lib/src/dom/sliver_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RenderSliverElementChildManager implements RenderSliverBoxChildManager {

RenderSliverElementChildManager(this._target);

Iterable<Node> get _renderNodes => _target.childNodes.where((child) => child is Element || child is TextNode);
Iterable<Node> get _renderNodes => _target.childNodes.where((child) => child is Element || (child is TextNode && child.renderer != null));
andycall marked this conversation as resolved.
Show resolved Hide resolved

// Only count renderable child.
@override
Expand Down Expand Up @@ -64,9 +64,7 @@ class RenderSliverElementChildManager implements RenderSliverBoxChildManager {
assert(child != null, 'Sliver render node should own RenderBox.');

if (_hasLayout) {
_sliverListLayout
..setupParentData(child!)
..insertSliverChild(child, after: after);
_sliverListLayout.insertSliverChild(child!, after: after);
}

childNode.didAttachRenderer();
Expand Down Expand Up @@ -98,8 +96,8 @@ class RenderSliverElementChildManager implements RenderSliverBoxChildManager {
}
}

// Fallback operation.
child.detach();
// Fallback operation, remove child from sliver list.
_sliverListLayout.remove(child);
}

@override
Expand Down