@rocapine/react-native-onboarding 1.66.0 → 1.67.1

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.
@@ -316,13 +316,51 @@ const TextUIElementSchema = z.object({
316
316
  props: TextElementPropsSchema,
317
317
  });
318
318
 
319
+ // DISCRIMINATED on `type`, not a plain union — this is load-bearing for more
320
+ // than speed. A plain `z.union` of these ~25 recursive variants has to try
321
+ // every branch at every node, and each container branch re-parses the whole
322
+ // subtree on the way, so any shape that misses on all of them costs
323
+ // exponential time and memory rather than linear. Three observed consequences,
324
+ // all of them crashes rather than validation errors:
325
+ //
326
+ // - a real 52-node paywall with every `id` stripped exhausted a 512 MB heap
327
+ // in ~10s ("Ineffective mark-compacts near heap limit") instead of
328
+ // reporting a missing `id`. `PaywallHost` parses serve-path payloads
329
+ // deliberately outside its error boundary — and a boundary cannot catch an
330
+ // OOM anyway — so that was an app-kill vector reachable from data.
331
+ // - a single container missing its `children` key threw
332
+ // `RangeError: Invalid string length` from `JSON.stringify` INSIDE zod's own
333
+ // error constructor: the error object was too large to build, so nothing
334
+ // could report it.
335
+ // - even when it did return, the top-level issue was always `invalid_union` /
336
+ // "Invalid input" at the array index, with the real cause buried under 25
337
+ // nested branch errors — which is why callers saw `0: Invalid input`.
338
+ //
339
+ // Note `id` being REQUIRED on every variant is what made the first case
340
+ // maximal rather than mild: a missing `id` misses every branch at every node.
341
+ // So "make `id` required and fail fast" cannot work — a required field has no
342
+ // way to fail fast inside a non-discriminated union. The discriminator is the
343
+ // fix, and it makes all three cases return in ~0ms with the exact path.
344
+ //
345
+ // Consequence for maintainers: every variant needs exactly ONE literal `type`.
346
+ // That is why YStack and XStack are two entries below sharing one props
347
+ // schema, rather than one entry with `z.union([literal, literal])` — a
348
+ // discriminated union cannot key off a union of literals.
319
349
  export const UIElementSchema: z.ZodType<UIElement> = z.lazy(() =>
320
- z.union([
350
+ z.discriminatedUnion("type", [
321
351
  z.object({
322
352
  id: z.string(),
323
353
  name: z.string().optional(),
324
354
  renderWhen: z.union([LeafConditionSchema, ConditionGroupSchema]).optional(),
325
- type: z.union([z.literal("YStack"), z.literal("XStack")]),
355
+ type: z.literal("YStack"),
356
+ props: StackElementPropsSchema,
357
+ children: z.array(UIElementSchema),
358
+ }),
359
+ z.object({
360
+ id: z.string(),
361
+ name: z.string().optional(),
362
+ renderWhen: z.union([LeafConditionSchema, ConditionGroupSchema]).optional(),
363
+ type: z.literal("XStack"),
326
364
  props: StackElementPropsSchema,
327
365
  children: z.array(UIElementSchema),
328
366
  }),