jsx-framework-test-pb 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,48 +49,59 @@ export function createElement(element) {
49
49
  function createReactiveChild(fn) {
50
50
  // Use an empty text node as a stable anchor point (invisible in DOM)
51
51
  const anchor = document.createTextNode('');
52
- let currentNode = null;
52
+ // Track actual inserted nodes (not the DocumentFragment which empties on insert)
53
+ let currentNodes = [];
53
54
  let isFirstRun = true;
54
55
  const cleanup = effect(() => {
55
56
  const value = fn();
56
- // Clean up previous node (skip on first run)
57
- if (!isFirstRun && currentNode) {
58
- cleanupTree(currentNode);
59
- currentNode.parentNode?.removeChild(currentNode);
60
- currentNode = null;
57
+ // Clean up previous nodes (skip on first run)
58
+ if (!isFirstRun) {
59
+ currentNodes.forEach(node => {
60
+ cleanupTree(node);
61
+ node.parentNode?.removeChild(node);
62
+ });
63
+ currentNodes = [];
61
64
  }
62
65
  // Handle different return types
66
+ let newNode = null;
63
67
  if (value == null || value === false) {
64
- currentNode = null;
68
+ newNode = null;
65
69
  }
66
70
  else if (typeof value === 'string' || typeof value === 'number') {
67
- currentNode = document.createTextNode(String(value));
71
+ newNode = document.createTextNode(String(value));
68
72
  }
69
73
  else if (isElement(value) || Array.isArray(value)) {
70
- currentNode = createElement(value);
74
+ newNode = createElement(value);
71
75
  }
72
76
  else {
73
- currentNode = document.createTextNode(String(value));
77
+ newNode = document.createTextNode(String(value));
78
+ }
79
+ // Track the actual nodes before a DocumentFragment empties on insertion
80
+ if (newNode) {
81
+ if (newNode instanceof DocumentFragment) {
82
+ currentNodes = Array.from(newNode.childNodes);
83
+ }
84
+ else {
85
+ currentNodes = [newNode];
86
+ }
74
87
  }
75
88
  // Insert new node after anchor (skip on first run - handled by fragment)
76
- if (!isFirstRun && currentNode && anchor.parentNode) {
77
- anchor.parentNode.insertBefore(currentNode, anchor.nextSibling);
89
+ if (!isFirstRun && newNode && anchor.parentNode) {
90
+ anchor.parentNode.insertBefore(newNode, anchor.nextSibling);
78
91
  }
79
92
  isFirstRun = false;
80
93
  });
81
94
  trackCleanup(anchor, () => {
82
95
  cleanup();
83
- if (currentNode) {
84
- cleanupTree(currentNode);
85
- currentNode.parentNode?.removeChild(currentNode);
86
- }
96
+ currentNodes.forEach(node => {
97
+ cleanupTree(node);
98
+ node.parentNode?.removeChild(node);
99
+ });
87
100
  });
88
- // Return fragment with anchor and initial node
101
+ // Return fragment with anchor and initial nodes
89
102
  const fragment = document.createDocumentFragment();
90
103
  fragment.appendChild(anchor);
91
- if (currentNode) {
92
- fragment.appendChild(currentNode);
93
- }
104
+ currentNodes.forEach(node => fragment.appendChild(node));
94
105
  return fragment;
95
106
  }
96
107
  function cleanupTree(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsx-framework-test-pb",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",