@tanstack/redact 0.0.19 → 0.0.21

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.
@@ -147,7 +147,7 @@ function renderSuspense(fiber: Fiber, domParent: Node, anchor: Node | null): voi
147
147
  renderFiber(state.f, domParent, anchor)
148
148
  } else {
149
149
  // First-mount suspension — nothing to preserve.
150
- unmountAllChildren(fiber, domParent)
150
+ unmountAllChildren(fiber)
151
151
  reconcileChildren(fiber, childrenToArray(props.fallback), domParent, anchor)
152
152
  }
153
153
  } else {
@@ -160,7 +160,7 @@ function renderSuspense(fiber: Fiber, domParent: Node, anchor: Node | null): voi
160
160
  state.d = null
161
161
  }
162
162
  if (state.f) {
163
- unmountFiber(state.f, domParent)
163
+ unmountFiber(state.f)
164
164
  state.f = null
165
165
  }
166
166
  }
@@ -210,7 +210,7 @@ function hydrateSuspenseBoundary(
210
210
  } catch (e) {
211
211
  if (!isHydrationBailout(e)) {
212
212
  clearBoundaryRange(startMark, endMark)
213
- unmountAllChildren(fiber, parent)
213
+ unmountAllChildren(fiber)
214
214
  throw e
215
215
  }
216
216
  recoverBoundaryHydration(fiber, props.children, parent, startMark, endMark)
@@ -258,14 +258,14 @@ function recoverBoundaryHydration(
258
258
  const prevHydrating = root.h
259
259
  discardPendingWork(root)
260
260
  clearBoundaryRange(startMark, endMark)
261
- unmountAllChildren(fiber, parent)
261
+ unmountAllChildren(fiber)
262
262
  root.h = false
263
263
  try {
264
264
  reconcileChildren(fiber, childrenToArray(children), parent, endMark)
265
265
  advanceCursorPast(fiber.parent!, endMark)
266
266
  } catch (clientError) {
267
267
  clearBoundaryRange(startMark, endMark)
268
- unmountAllChildren(fiber, parent)
268
+ unmountAllChildren(fiber)
269
269
  throw clientError
270
270
  } finally {
271
271
  root.h = prevHydrating
@@ -277,13 +277,13 @@ function recoverFallbackHydration(fiber: Fiber, fallback: any, parent: HTMLEleme
277
277
  const prevHydrating = root.h
278
278
  discardPendingWork(root)
279
279
  parent.textContent = ''
280
- unmountAllChildren(fiber, parent)
280
+ unmountAllChildren(fiber)
281
281
  root.h = false
282
282
  try {
283
283
  reconcileChildren(fiber, childrenToArray(fallback), parent, null)
284
284
  } catch (clientError) {
285
285
  parent.textContent = ''
286
- unmountAllChildren(fiber, parent)
286
+ unmountAllChildren(fiber)
287
287
  throw clientError
288
288
  } finally {
289
289
  root.h = prevHydrating
@@ -303,7 +303,7 @@ function rehydrateBoundary(fiber: Fiber): void {
303
303
  withCurrentRoot(root, () => {
304
304
  const prevHydrating = root.h
305
305
  try {
306
- unmountAllChildren(fiber, parent)
306
+ unmountAllChildren(fiber)
307
307
 
308
308
  // Re-hydrate with real children against the now-real DOM range.
309
309
  root.h = true
@@ -312,7 +312,7 @@ function rehydrateBoundary(fiber: Fiber): void {
312
312
  } catch (e) {
313
313
  if (!isHydrationBailout(e)) {
314
314
  clearBoundaryRange(state.b, state.e)
315
- unmountAllChildren(fiber, parent)
315
+ unmountAllChildren(fiber)
316
316
  throw e
317
317
  }
318
318
 
@@ -531,14 +531,14 @@ export function reconcileChildren(
531
531
  // Unmount unclaimed
532
532
  for (const f of existing) {
533
533
  if (!claimed.has(f)) {
534
- unmountFiber(f, domParent)
534
+ unmountFiber(f)
535
535
  structurallyChanged = true
536
536
  }
537
537
  }
538
538
  // Leftover keyed
539
539
  for (const f of keyed.values()) {
540
540
  if (!claimed.has(f)) {
541
- unmountFiber(f, domParent)
541
+ unmountFiber(f)
542
542
  structurallyChanged = true
543
543
  }
544
544
  }
@@ -1017,13 +1017,13 @@ export function isThenable(x: any): x is Promise<any> {
1017
1017
  // Unmount
1018
1018
  // ---------------------------------------------------------------------------
1019
1019
 
1020
- export function unmountFiber(fiber: Fiber, domParent: Node): void {
1020
+ export function unmountFiber(fiber: Fiber, removeDom = true): void {
1021
1021
  fiber.um = true
1022
1022
  // Recurse first
1023
1023
  let c = fiber.child
1024
1024
  while (c) {
1025
1025
  const next = c.sibling
1026
- unmountFiber(c, fiber.tag === FiberTag.Host ? fiber.dom! : domParent)
1026
+ unmountFiber(c, removeDom || fiber.tag === FiberTag.Portal)
1027
1027
  c = next
1028
1028
  }
1029
1029
  fiber.child = null
@@ -1040,12 +1040,7 @@ export function unmountFiber(fiber: Fiber, domParent: Node): void {
1040
1040
  fiber.cu = null
1041
1041
  }
1042
1042
 
1043
- if (fiber.tag === FiberTag.Class && fiber.sn?.componentWillUnmount) {
1044
- try {
1045
- fiber.sn.componentWillUnmount()
1046
- } catch (e) {
1047
- if (currentRoot?.re) currentRoot.re(e)
1048
- }
1043
+ if (fiber.tag === FiberTag.Class && fiber.sn) {
1049
1044
  fiber.sn._fiber = null
1050
1045
  fiber.sn._enqueueUpdate = null
1051
1046
  fiber.sn._forceUpdate = null
@@ -1054,19 +1049,17 @@ export function unmountFiber(fiber: Fiber, domParent: Node): void {
1054
1049
  // Detach ref
1055
1050
  if (fiber.ref) detachRef(fiber.ref)
1056
1051
 
1057
- // Remove DOM if host
1058
- if (fiber.tag === FiberTag.Host && fiber.dom && fiber.dom.parentNode) {
1059
- fiber.dom.parentNode.removeChild(fiber.dom)
1060
- } else if (fiber.tag === FiberTag.Text && fiber.dom && fiber.dom.parentNode) {
1061
- fiber.dom.parentNode.removeChild(fiber.dom)
1052
+ // Only host and text fibers own DOM nodes.
1053
+ if (removeDom) {
1054
+ fiber.dom?.parentNode?.removeChild(fiber.dom)
1062
1055
  }
1063
1056
  }
1064
1057
 
1065
- export function unmountAllChildren(parent: Fiber, domParent: Node): void {
1058
+ export function unmountAllChildren(parent: Fiber): void {
1066
1059
  let c = parent.child
1067
1060
  while (c) {
1068
1061
  const next = c.sibling
1069
- unmountFiber(c, domParent)
1062
+ unmountFiber(c)
1070
1063
  c = next
1071
1064
  }
1072
1065
  parent.child = null
@@ -1228,8 +1221,8 @@ export function enqueueEffect(fiber: Fiber, effect: Effect): void {
1228
1221
  }
1229
1222
  }
1230
1223
 
1231
- export function scheduleLifecycle(_fiber: Fiber, fn: () => void): void {
1232
- pendingLifecycles.push(fn)
1224
+ export function scheduleLifecycle(fiber: Fiber, fn: () => void): void {
1225
+ pendingLifecycles.push(() => { if (!fiber.um) fn() })
1233
1226
  }
1234
1227
 
1235
1228
  export function runEffects(root: FiberRoot): void {
@@ -1257,6 +1250,7 @@ export function runEffects(root: FiberRoot): void {
1257
1250
  }
1258
1251
 
1259
1252
  function runEffect(fiber: Fiber, effect: Effect, root: FiberRoot): void {
1253
+ if (fiber.um) return
1260
1254
  try {
1261
1255
  const cleanup = effect.c()
1262
1256
  if (typeof cleanup == 'function') {
@@ -1,4 +1,4 @@
1
- import { attributeName } from '../core/attributes'
1
+ import { attributeName, STRING_BOOLEAN_ATTRS } from '../core/attributes'
2
2
 
3
3
  const ATTR_MAP: Record<string, string> = {
4
4
  '&': '&amp;',
@@ -96,11 +96,12 @@ export function attrToHtml(name: string, value: unknown, isSvg = false): string
96
96
 
97
97
  const htmlName = attributeName(name, isSvg)
98
98
 
99
- // aria-* and data-* stringify booleans to `"true"`/`"false"` rather than
100
- // using boolean-attribute presence semantics — matches React and the ARIA
101
- // spec. Must branch before the general `value === false` / BOOLEAN_ATTRS
102
- // path, which would drop them.
103
- if (name.startsWith('aria-') || name.startsWith('data-')) {
99
+ // These attributes need explicit "false", not boolean-attribute absence.
100
+ if (
101
+ STRING_BOOLEAN_ATTRS.has(htmlName) ||
102
+ name.startsWith('aria-') ||
103
+ name.startsWith('data-')
104
+ ) {
104
105
  return ` ${htmlName}="${escapeAttr(String(value))}"`
105
106
  }
106
107