@c15t/astro 3.0.0-alpha.0 → 3.0.0-alpha.2

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.
@@ -0,0 +1,208 @@
1
+ ---
2
+ title: Granular consent
3
+ description: Let visitors grant a category and still turn one vendor off,
4
+ without adopting IAB TCF.
5
+ group: integrations
6
+ ---
7
+
8
+ Granular consent is choice below the category level: a visitor grants
9
+ marketing and still turns Meta off. The unit of that choice is a vendor, so
10
+ the API names them `vendors`, `vendor` and `data-vendor`, and the hooks
11
+ `useVendorAllowed` and `useVendorDraft`. Everything else stays as it is:
12
+ categories, policies, and the preference center gain vendor rows rather than
13
+ a second consent model.
14
+
15
+ ## Declare vendors
16
+
17
+ Add `vendors` to your runtime options. Each vendor sits inside a category
18
+ condition and needs a name and a privacy policy URL so the preference surface
19
+ can list it. The React provider takes the same option once its preference
20
+ center renders vendor rows; scripts, rules and iframes are gated the same way
21
+ whichever place declares it:
22
+
23
+ ```ts
24
+ import { hosted, type Vendor } from 'c15t';
25
+ import { createConsentRuntime } from 'c15t/runtime';
26
+
27
+ const vendors = [
28
+ {
29
+ id: 'meta-pixel',
30
+ name: 'Meta Pixel',
31
+ category: 'marketing',
32
+ privacyPolicyUrl: 'https://www.facebook.com/privacy/policy/',
33
+ description: 'Ad conversion measurement and audiences.',
34
+ },
35
+ {
36
+ id: 'google-analytics',
37
+ name: 'Google Analytics',
38
+ category: 'measurement',
39
+ privacyPolicyUrl: 'https://policies.google.com/privacy',
40
+ },
41
+ ] satisfies Vendor[];
42
+
43
+ const runtime = createConsentRuntime({
44
+ mode: hosted({ url: '/api/c15t' }),
45
+ vendors,
46
+ scripts: [
47
+ {
48
+ id: 'meta-pixel',
49
+ category: 'marketing',
50
+ vendor: 'meta-pixel',
51
+ src: 'https://connect.facebook.net/en_US/fbevents.js',
52
+ },
53
+ ],
54
+ });
55
+
56
+ // Start in the browser after mount. The endpoint must serve your c15t backend.
57
+ runtime.start();
58
+ ```
59
+
60
+ The `id` is a lowercase slug of up to 64 characters. Reuse it as the `vendor`
61
+ field on scripts and network rules and as the `data-vendor` attribute on
62
+ iframes. Integrations from `@c15t/scripts` already set `vendor` to their
63
+ manifest slug, so `gtag()` and `metaPixel()` need no extra wiring.
64
+
65
+ A backend can also declare vendors. Add `vendors` and an optional
66
+ `vendorListVersion` to the manifest configuration; `/init` returns them and the
67
+ client merges them with the vendors declared in code. When both declare the
68
+ same id, the copy declared in code wins, and the backend copy comes back if the
69
+ code declaration is removed later. A slug used by a script, rule or iframe
70
+ but declared nowhere still gates loading. It is hidden from the preference surface, and the
71
+ runtime warns about it outside production.
72
+
73
+ ## How a vendor is gated
74
+
75
+ A target loads when its category condition passes and the visitor has not
76
+ turned its vendor off:
77
+
78
+ ```text
79
+ loads = category condition satisfied AND vendor not denied
80
+ ```
81
+
82
+ The category is evaluated first, so an unknown category still throws as a
83
+ configuration error. A vendor toggle never grants a category on its own: with
84
+ marketing denied, `meta-pixel` stays blocked whatever its own switch says.
85
+ A script with `alwaysLoad` still mounts, as it does for a denied category;
86
+ its callbacks receive the vendor result in `info.vendor.granted` so a
87
+ self-managing SDK can honor it.
88
+
89
+ Under an `iab` policy the `vendor` slug is inert. Vendor consent then comes from
90
+ the TC string through `vendorId`, and the vendor rows are not shown.
91
+
92
+ The same rule applies to the three gates:
93
+
94
+ | Surface | Field |
95
+ | --------------- | ------------------------------- |
96
+ | Script loader | `Script.vendor` |
97
+ | Network blocker | `NetworkBlockerRule.vendor` |
98
+ | Iframe blocker | `data-vendor` on the `<iframe>` |
99
+
100
+ An iframe with `data-vendor` and no `data-category` is gated on the vendor
101
+ alone. An unknown `data-vendor` value is granted rather than thrown: a vendor
102
+ the visitor never saw cannot have been turned off. Such a frame has no
103
+ category to follow, so a denial the visitor recorded earlier holds even while
104
+ nothing declares the slug, for example before the backend's vendor list has
105
+ arrived on a cold start.
106
+
107
+ A script, rule or frame keeps its slug declared for as long as it is
108
+ configured. If a backend list or a provider update drops the entry, the
109
+ loader or blocker puts it back, so a stored denial keeps gating it. A slug
110
+ several modules share stays under every category they name it with, whichever
111
+ module updates last, and drops a category only once no module names it there.
112
+ Disposing a loader or blocker, or removing a gated frame from the page, drops
113
+ what only it named, so a vendor no live module owns stops being toggleable.
114
+
115
+ ## Record a vendor choice
116
+
117
+ Vendor grants travel with the save. Stage them and confirm with the next save,
118
+ or pass them next to the categories:
119
+
120
+ ```ts
121
+ // Stage from a toggle handler; nothing changes until save({}) runs. The
122
+ // empty patch confirms no category, so only the staged vendor is recorded;
123
+ // save() with no input would reconfirm every displayed category too.
124
+ runtime.stageVendorConsent('meta-pixel', false);
125
+ await runtime.kernel.commands.save({});
126
+
127
+ // Or confirm categories and vendors in one action.
128
+ await runtime.kernel.commands.save({
129
+ marketing: true,
130
+ measurement: true,
131
+ vendors: { 'meta-pixel': false },
132
+ });
133
+ ```
134
+
135
+ `stageVendorConsent` stages a vendor slug for the next save; it is not the
136
+ IAB handle's `setVendorConsent`, which sets a TCF vendor by numeric id and
137
+ takes effect at once. The grants can also travel in the save context as
138
+ `{ vendors }`, which wins when both are given.
139
+
140
+ Only the vendors the visitor turned off are stored. Accept all and reject all
141
+ both clear that list, so vendors follow their category on a bulk action. A bulk
142
+ action narrowed to the displayed categories only lifts the denials of vendors
143
+ those categories decide on their own; a vendor another granted category would
144
+ still load keeps its denial. A
145
+ vendor that is not declared, or is declared with `disabled: true`, is ignored.
146
+ Under an opt-out policy every vendor starts on and the stored list is the
147
+ do-not-sell list.
148
+
149
+ A vendor-only change records without touching category receipts. The kernel
150
+ emits `vendors:recorded` rather than `choice:recorded`, writes the
151
+ `<storageKey>-vendors` cookie and localStorage entry, and sends the complete
152
+ grant map to the backend as `vendorChoice`. Category confirmation times are not
153
+ renewed. The vendor entry also carries the subject id, so a visitor whose first
154
+ act only decided vendors keeps the same subject after a reload even though no
155
+ category record exists yet.
156
+
157
+ Scripts see the vendor result in their callbacks. `ScriptCallbackInfo.vendor`
158
+ carries `{ id, granted }` outside IAB mode. Integrations that send Google
159
+ Consent Mode or RudderStack signals send every category as denied while their
160
+ vendor is off, so the vendor's own consent API cannot re-enable tracking.
161
+
162
+ ## Show vendors in the preference center
163
+
164
+ The `ConsentWidget` and `ConsentDialog` in React, Vue and Svelte list vendors
165
+ under their category when the provider declares them. Pass the same `vendors`
166
+ array to `ConsentProvider`, to the `vendors` prop of `ConsentRoot` in
167
+ [Next.js](https://c15t.com/docs/frameworks/next/script-loader#granular-consent) and
168
+ [TanStack Start](https://c15t.com/docs/frameworks/tanstack-start/quickstart#granular-consent),
169
+ to the Nuxt module or Vue plugin config next to `scripts`, or to
170
+ `ConsentManagerProvider` options in Svelte:
171
+
172
+ ```tsx
173
+ import { ConsentProvider, hosted } from 'c15t/react';
174
+
175
+ <ConsentProvider options={{ mode: hosted({ url: '/api/c15t' }), vendors }}>
176
+ {children}
177
+ </ConsentProvider>;
178
+ ```
179
+
180
+ Each category row expands to one card per vendor with its own switch. The
181
+ switches disable while the category is off in the draft, and Save records the
182
+ vendors the visitor moved. A custom control uses `useVendorDraft()` from
183
+ `c15t/react` to read and stage the same grants, with `isStale` and `reset` for
184
+ a draft the policy or vendor list changed under, and `useVendorAllowed(id)` to
185
+ read one vendor's effective result. Copy comes from
186
+ `consentManagerDialog.vendors.{title, privacyPolicy, disabledByCategory,
187
+ switchLabel}` in the translations. In Vue, `useConsentDraft()` returns the
188
+ same `vendors` map and `setVendor`; in Svelte, `getConsentManager()` exposes
189
+ `selectedVendors`, `setSelectedVendor` and `getDisplayedVendors(category)`.
190
+ The three frameworks render the same cards, and the parity suite compares
191
+ their markup, accessibility tree, computed styles and geometry.
192
+
193
+ ## What a denial does not do
194
+
195
+ Turning a vendor off blocks future loads and requests. It does not delete the
196
+ cookies that vendor already set, and
197
+ [clear on revocation](./clear-on-revocation.md) does not help here:
198
+ it runs when a category is denied, and the category stays granted when only one
199
+ of its vendors is off. Remove that vendor's cookies yourself from an
200
+ `onConsentChange` callback that checks `info.vendor.granted`.
201
+
202
+ A vendor denial has no expiry and no policy basis. It stays until the visitor
203
+ changes it or a bulk action clears it, including across a policy change that
204
+ requires the category choice again.
205
+
206
+ Adding a vendor to the list does not reopen consent. New vendors default to on
207
+ inside a granted category. Use the policy rule's `copyRevision` when a new
208
+ vendor should prompt the visitor again.
@@ -34,15 +34,16 @@ behavior before choosing either approach.
34
34
  | [Google Maps](./google-maps.md) | Framework-specific consent-gated map iframe | Iframe mounts only while the chosen permission is allowed |
35
35
  | [YouTube](./youtube.md) | Framework-specific consent-gated video iframe | Iframe mounts only while the chosen permission is allowed |
36
36
 
37
- Both guides include all nine framework examples. React and Svelte use `Frame`;
37
+ Both guides include all nine framework examples. React and Svelte use `ConsentGate`;
38
38
  Vue conditionally renders the iframe, and Astro and JavaScript use the existing
39
39
  kernel to control its DOM lifecycle. Embeds do not require `@c15t/scripts`.
40
40
 
41
41
  ## Tag managers
42
42
 
43
- | Integration | Helper | Category | Loading behavior |
44
- | --------------------------------------------- | ------------------ | ----------- | ------------------------------------ |
45
- | [Google Tag Manager](./google-tag-manager.md) | `googleTagManager` | `necessary` | Always loads; signals Google consent |
43
+ | Integration | Helper | Category | Loading behavior |
44
+ | --------------------------------------------- | ------------------ | ----------- | ------------------------------------------------ |
45
+ | [Cloudflare Zaraz](./cloudflare-zaraz.md) | `cloudflareZaraz` | `necessary` | Synchronizes purposes; Zaraz owns tool execution |
46
+ | [Google Tag Manager](./google-tag-manager.md) | `googleTagManager` | `necessary` | Always loads; signals Google consent |
46
47
 
47
48
  ## Analytics
48
49
 
@@ -33,12 +33,12 @@ Render this component inside your existing consent boundary or provider.
33
33
  ```tsx title="src/consent-embed.tsx"
34
34
  'use client';
35
35
 
36
- import { Frame } from 'c15t/next';
36
+ import { ConsentGate } from 'c15t/next';
37
37
  import { embedCategory, embedURL, embedTitle, embedAspectRatio } from './embed-config';
38
38
 
39
39
  export function ConsentEmbed() {
40
40
  return (
41
- <Frame category={embedCategory}>
41
+ <ConsentGate category={embedCategory}>
42
42
  <iframe
43
43
  src={embedURL}
44
44
  title={embedTitle}
@@ -46,12 +46,12 @@ export function ConsentEmbed() {
46
46
  allowFullScreen
47
47
  style={{ width: '100%', aspectRatio: embedAspectRatio, minHeight: 200, border: 0 }}
48
48
  />
49
- </Frame>
49
+ </ConsentGate>
50
50
  );
51
51
  }
52
52
  ```
53
53
 
54
- `Frame` keeps the iframe absent while permission is denied and removes it
54
+ `ConsentGate` keeps the iframe absent while permission is denied and removes it
55
55
  on revocation. Keep your existing consent styles and preferences dialog.
56
56
 
57
57
  **TanStack Start**
@@ -59,12 +59,12 @@ on revocation. Keep your existing consent styles and preferences dialog.
59
59
  Render this component inside your existing consent boundary or provider.
60
60
 
61
61
  ```tsx title="src/consent-embed.tsx"
62
- import { Frame } from 'c15t/tanstack-start';
62
+ import { ConsentGate } from 'c15t/tanstack-start';
63
63
  import { embedCategory, embedURL, embedTitle, embedAspectRatio } from './embed-config';
64
64
 
65
65
  export function ConsentEmbed() {
66
66
  return (
67
- <Frame category={embedCategory}>
67
+ <ConsentGate category={embedCategory}>
68
68
  <iframe
69
69
  src={embedURL}
70
70
  title={embedTitle}
@@ -72,12 +72,12 @@ export function ConsentEmbed() {
72
72
  allowFullScreen
73
73
  style={{ width: '100%', aspectRatio: embedAspectRatio, minHeight: 200, border: 0 }}
74
74
  />
75
- </Frame>
75
+ </ConsentGate>
76
76
  );
77
77
  }
78
78
  ```
79
79
 
80
- `Frame` keeps the iframe absent while permission is denied and removes it
80
+ `ConsentGate` keeps the iframe absent while permission is denied and removes it
81
81
  on revocation. Keep your existing consent styles and preferences dialog.
82
82
 
83
83
  **React**
@@ -85,12 +85,12 @@ on revocation. Keep your existing consent styles and preferences dialog.
85
85
  Render this component inside your existing consent boundary or provider.
86
86
 
87
87
  ```tsx title="src/consent-embed.tsx"
88
- import { Frame } from 'c15t/react';
88
+ import { ConsentGate } from 'c15t/react';
89
89
  import { embedCategory, embedURL, embedTitle, embedAspectRatio } from './embed-config';
90
90
 
91
91
  export function ConsentEmbed() {
92
92
  return (
93
- <Frame category={embedCategory}>
93
+ <ConsentGate category={embedCategory}>
94
94
  <iframe
95
95
  src={embedURL}
96
96
  title={embedTitle}
@@ -98,12 +98,12 @@ export function ConsentEmbed() {
98
98
  allowFullScreen
99
99
  style={{ width: '100%', aspectRatio: embedAspectRatio, minHeight: 200, border: 0 }}
100
100
  />
101
- </Frame>
101
+ </ConsentGate>
102
102
  );
103
103
  }
104
104
  ```
105
105
 
106
- `Frame` keeps the iframe absent while permission is denied and removes it
106
+ `ConsentGate` keeps the iframe absent while permission is denied and removes it
107
107
  on revocation. Keep your existing consent styles and preferences dialog.
108
108
 
109
109
  **Nuxt**
@@ -223,11 +223,11 @@ The provider from your quickstart supplies its consent state.
223
223
 
224
224
  ```svelte title="src/ConsentEmbed.svelte"
225
225
  <script lang="ts">
226
- import { Frame } from '@c15t/svelte';
226
+ import { ConsentGate } from '@c15t/svelte';
227
227
  import { embedCategory, embedURL, embedTitle, embedAspectRatio } from './embed-config';
228
228
  </script>
229
229
 
230
- <Frame category={embedCategory}>
230
+ <ConsentGate category={embedCategory}>
231
231
  <iframe
232
232
  src={embedURL}
233
233
  title={embedTitle}
@@ -238,10 +238,10 @@ The provider from your quickstart supplies its consent state.
238
238
  style:min-height="200px"
239
239
  style:border="0"
240
240
  ></iframe>
241
- </Frame>
241
+ </ConsentGate>
242
242
  ```
243
243
 
244
- The Svelte `Frame` waits until the browser is mounted and the category is
244
+ The Svelte `ConsentGate` waits until the browser is mounted and the category is
245
245
  allowed. Its default placeholder opens preferences. Revocation removes the
246
246
  iframe.
247
247
 
@@ -252,11 +252,11 @@ Keep the SvelteKit root provider and its server prefetch unchanged.
252
252
 
253
253
  ```svelte title="src/lib/ConsentEmbed.svelte"
254
254
  <script lang="ts">
255
- import { Frame } from '@c15t/svelte';
255
+ import { ConsentGate } from '@c15t/svelte';
256
256
  import { embedCategory, embedURL, embedTitle, embedAspectRatio } from '../embed-config';
257
257
  </script>
258
258
 
259
- <Frame category={embedCategory}>
259
+ <ConsentGate category={embedCategory}>
260
260
  <iframe
261
261
  src={embedURL}
262
262
  title={embedTitle}
@@ -267,10 +267,10 @@ Keep the SvelteKit root provider and its server prefetch unchanged.
267
267
  style:min-height="200px"
268
268
  style:border="0"
269
269
  ></iframe>
270
- </Frame>
270
+ </ConsentGate>
271
271
  ```
272
272
 
273
- The Svelte `Frame` waits until the browser is mounted and the category is
273
+ The Svelte `ConsentGate` waits until the browser is mounted and the category is
274
274
  allowed. Its default placeholder opens preferences. Revocation removes the
275
275
  iframe.
276
276
 
@@ -380,7 +380,7 @@ Set playback options in the iframe URL. For example, append `start=36` to begin
380
380
  [YouTube player parameters](https://developers.google.com/youtube/player_parameters)
381
381
  and reserve at least a 200-by-200-pixel player area.
382
382
 
383
- React and Svelte `Frame` components provide a blocked-state placeholder and
383
+ React and Svelte `ConsentGate` components provide a blocked-state placeholder and
384
384
  consent action. Their `placeholder` APIs differ: React takes a node, Svelte
385
385
  takes a snippet. Keep a clear way to reopen preferences when customizing them.
386
386
  The Vue and browser examples show that action explicitly. `loading="lazy"` delays an
@@ -388,6 +388,11 @@ allowed iframe for performance; it does not implement consent gating.
388
388
 
389
389
  ## Consent behavior
390
390
 
391
+ Add `data-vendor="youtube"` next to `data-category` and declare a `youtube`
392
+ vendor in the runtime's `vendors` option or the backend manifest to let visitors
393
+ turn YouTube off while keeping the rest of the category on. See
394
+ [granular consent](./granular-consent.md).
395
+
391
396
  Each example keeps the iframe absent until the category is allowed. After
392
397
  permission, the iframe can load. Revoking permission removes the iframe and its
393
398
  embedded document. Requests already sent cannot be recalled.
@@ -5,6 +5,13 @@ description: Migrate policy configuration, consent records, callbacks, and
5
5
  group: reference
6
6
  ---
7
7
 
8
+ ## React version requirement
9
+
10
+ The v3 React and Next.js adapters require React and React DOM 18 or newer.
11
+ Upgrade both packages together before installing v3. Earlier alpha peer ranges
12
+ incorrectly allowed React 16 and 17 even though v3 already uses `useId` and
13
+ `useSyncExternalStore`, which those versions do not provide.
14
+
8
15
  ## Start with a policy rule
9
16
 
10
17
  ```ts
@@ -252,6 +259,24 @@ TanStack Start (`c15t/tanstack-start`, `c15t/tanstack-start/server`):
252
259
  `consentLoaderOptions`, `backendURL`, `initRoute` and `DEFAULT_INIT_ROUTE` are
253
260
  unchanged.
254
261
 
262
+ ## `Frame` is now `ConsentGate`
263
+
264
+ The component that mounts an embed only while its category is allowed is now
265
+ `ConsentGate` in React, Next.js, TanStack Start, Svelte and Vue. The old names
266
+ still work as deprecated aliases and will be removed in a later major release.
267
+
268
+ | v2 | v3 |
269
+ | -------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
270
+ | `Frame`, `Frame.Root`, `Frame.Title`, `Frame.Button` | `ConsentGate`, `ConsentGate.Root`, `ConsentGate.Title`, `ConsentGate.Button` |
271
+ | `FrameProps`, `FrameCompoundComponent` | `ConsentGateProps`, `ConsentGateCompoundComponent` |
272
+ | `c15t/react/frame`, `c15t/react/components/frame` | `c15t/react/consent-gate`, `c15t/react/components/consent-gate` |
273
+ | Vue `ConsentFrame`, `@c15t/vue/runtime/components/consent-frame.vue` | `ConsentGate`, `@c15t/vue/runtime/components/consent-gate.vue` |
274
+
275
+ Props and behavior are unchanged. The placeholder keeps its `frame.*`
276
+ translation keys, `--frame-*` CSS custom properties and
277
+ `data-testid="frame-placeholder"`, so custom copy, styles and tests continue
278
+ to apply.
279
+
255
280
  ## Next.js RSC banner removal
256
281
 
257
282
  The `@c15t/nextjs/rsc` entry (`c15t/next/rsc`) and its `RscConsentBanner`,
@@ -332,3 +357,25 @@ export function Banner() {
332
357
  );
333
358
  }
334
359
  ```
360
+
361
+ ## Session reports in manifest mode
362
+
363
+ A host that resolves init from a cached manifest never calls `/init`, so a v3
364
+ backend could not count the visitors it served. From this release every
365
+ server-side resolution sends `POST /sessions` to the backend after the fact,
366
+ server-to-server and detached from the response: the Next.js, TanStack Start,
367
+ SvelteKit, Nuxt and Astro init routes, and the Next.js, TanStack Start and
368
+ Astro render-time prefetches. The browser makes no request.
369
+
370
+ This is a new outbound data flow from your server to the consent backend. The
371
+ report carries the manifest revision, the matched policy, the jurisdiction,
372
+ country, region, language and GPC signal, plus the visitor's user agent and
373
+ address as request headers. It carries no cookies and no identifier. Nothing is
374
+ stored on the backend; the report reaches a `sessions.onReport` sink and the
375
+ request log.
376
+
377
+ Reporting is on by default and needs an absolute backend URL. Set
378
+ `reportSessions: false` on the adapter to send none. Each report is one
379
+ resolution, not one visitor: a page view can produce a `render` report and a
380
+ `route` report, and nothing in them links the two. A consumer counting sessions
381
+ groups reports by the forwarded address and user agent within a window.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c15t/astro",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "Astro consent management: server-rendered cookie banner, on-demand Svelte, React or Vue preference-centre islands, geo-aware middleware, and consent-gated script loading.",
5
5
  "keywords": [
6
6
  "astro",
@@ -133,12 +133,12 @@
133
133
  "test:watch": "vitest"
134
134
  },
135
135
  "dependencies": {
136
- "@c15t/core": "3.0.0-alpha.0",
137
- "@c15t/iab": "3.0.0-alpha.0",
138
- "@c15t/schema": "3.0.0-alpha.0",
139
- "@c15t/svelte": "3.0.0-alpha.0",
140
- "@c15t/translations": "3.0.0-alpha.0",
141
- "@c15t/ui": "3.0.0-alpha.0"
136
+ "@c15t/core": "3.0.0-alpha.2",
137
+ "@c15t/iab": "3.0.0-alpha.2",
138
+ "@c15t/schema": "3.0.0-alpha.1",
139
+ "@c15t/svelte": "3.0.0-alpha.2",
140
+ "@c15t/translations": "3.0.0-alpha.2",
141
+ "@c15t/ui": "3.0.0-alpha.2"
142
142
  },
143
143
  "devDependencies": {
144
144
  "@c15t/conformance": "0.0.1",
@@ -153,8 +153,8 @@
153
153
  "vue": "^3.5.0"
154
154
  },
155
155
  "peerDependencies": {
156
- "@c15t/react": "^3.0.0-alpha.0",
157
- "@c15t/vue": "^3.0.0-alpha.0",
156
+ "@c15t/react": "^3.0.0-alpha.2",
157
+ "@c15t/vue": "^3.0.0-alpha.2",
158
158
  "astro": "^5.0.0",
159
159
  "react": "^18.0.0 || ^19.0.0",
160
160
  "react-dom": "^18.0.0 || ^19.0.0",
@@ -22,13 +22,61 @@ import {
22
22
  ConsentDraftProvider,
23
23
  ConsentProvider,
24
24
  } from '@c15t/react';
25
- import { lazy, Suspense } from 'react';
25
+ import { useEffect, useState } from 'react';
26
+ import type { ComponentType } from 'react';
26
27
 
27
28
  import type { DialogPresentationOptions } from '../../ui/provider-props';
29
+ import type { IABDialogSurfaceProps } from './iab-dialog-surface';
28
30
 
29
31
  // The TCF surface is the larger half of this island and only an IAB site
30
32
  // ever opens it, so it arrives on its own chunk.
31
- const IABDialogSurface = lazy(() => import('./iab-dialog-surface'));
33
+ let loadedIABSurface: ComponentType<IABDialogSurfaceProps> | undefined;
34
+ let iabSurfacePromise:
35
+ | Promise<ComponentType<IABDialogSurfaceProps>>
36
+ | undefined;
37
+ const loadIABSurface = () => {
38
+ iabSurfacePromise ??= (async () => {
39
+ const module = await import('./iab-dialog-surface');
40
+ loadedIABSurface = module.default;
41
+ return loadedIABSurface;
42
+ })();
43
+ return iabSurfacePromise;
44
+ };
45
+
46
+ // This island only mounts in the browser. Resolve its component through state
47
+ // so the first open does not wait for React's Suspense retry throttle.
48
+ const IABDialogSurface = (props: IABDialogSurfaceProps) => {
49
+ const [loadedComponent, setLoadedComponent] = useState(
50
+ () => loadedIABSurface
51
+ );
52
+ const [failure, setFailure] = useState<{ error: unknown }>();
53
+ useEffect(() => {
54
+ if (loadedComponent) {
55
+ return;
56
+ }
57
+ let active = true;
58
+ void (async () => {
59
+ try {
60
+ const loaded = await loadIABSurface();
61
+ if (active) {
62
+ setLoadedComponent(() => loaded);
63
+ }
64
+ } catch (error) {
65
+ if (active) {
66
+ setFailure({ error });
67
+ }
68
+ }
69
+ })();
70
+ return () => {
71
+ active = false;
72
+ };
73
+ }, [loadedComponent]);
74
+ if (failure) {
75
+ throw failure.error;
76
+ }
77
+ const Component = loadedComponent;
78
+ return Component ? <Component {...props} /> : null;
79
+ };
32
80
 
33
81
  /** Props the React dialog adapter passes in. */
34
82
  export interface ConsentDialogSurfaceProps {
@@ -53,9 +101,7 @@ const ConsentDialogSurface = ({
53
101
  options={options}
54
102
  >
55
103
  {kind === 'iab' ? (
56
- <Suspense fallback={null}>
57
- <IABDialogSurface tab={tab} />
58
- </Suspense>
104
+ <IABDialogSurface tab={tab} />
59
105
  ) : (
60
106
  <ConsentDraftProvider>
61
107
  <ConsentDialog />