cookie-prefs 0.2.0 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -145,10 +145,20 @@ var bind = (key, def, prefix, options) => {
145
145
  });
146
146
  }
147
147
  };
148
+ let rejected = false;
148
149
  const write = (value) => {
149
150
  try {
150
151
  document.cookie = serialize(attrs, value);
151
152
  post();
153
+ if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
154
+ const text = value.toWellFormed?.() ?? value;
155
+ if (rawOf(document.cookie, name) !== text) {
156
+ rejected = true;
157
+ console.warn(
158
+ `cookie-prefs: ${key}.set() wrote a cookie that does not read back: the browser dropped it, or another cookie named ${name} hides it. Browsers drop a cookie whose name and value exceed 4096 bytes (here ${name.length + encodeURIComponent(text).length}), one with a __Host- prefix, SameSite=None or Partitioned but no Secure, and one for a domain or path this page is not on.`
159
+ );
160
+ }
161
+ }
152
162
  } catch {
153
163
  }
154
164
  check();
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-BITLlZeg.cjs';
2
- export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-BITLlZeg.cjs';
1
+ import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-C5uwWL7s.cjs';
2
+ export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-C5uwWL7s.cjs';
3
3
 
4
4
  /**
5
5
  * Structural copy of the Standard Schema v1 interface (https://standardschema.dev, MIT).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-BITLlZeg.js';
2
- export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-BITLlZeg.js';
1
+ import { E as EnumPrefBuilder, S as ScalarPrefBuilder, P as PrefBuilder, a as PrefCodec, b as PrefShape, c as PrefsOptions, d as Prefs, e as PrefsRecord, C as CookieSource, f as PrefValues, g as PrefsSnapshot } from './types-C5uwWL7s.js';
2
+ export { A as AnyPref, h as AnyPrefBuilder, i as CookieGetter, j as CookieInit, k as CookieOptions, l as CookieSameSite, m as EnumReflectTarget, n as Pref, o as PrefOptions, p as PrefSetter, q as PrefTypes, r as PrefValue, R as ReflectTarget } from './types-C5uwWL7s.js';
3
3
 
4
4
  /**
5
5
  * Structural copy of the Standard Schema v1 interface (https://standardschema.dev, MIT).
package/dist/index.js CHANGED
@@ -143,10 +143,20 @@ var bind = (key, def, prefix, options) => {
143
143
  });
144
144
  }
145
145
  };
146
+ let rejected = false;
146
147
  const write = (value) => {
147
148
  try {
148
149
  document.cookie = serialize(attrs, value);
149
150
  post();
151
+ if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
152
+ const text = value.toWellFormed?.() ?? value;
153
+ if (rawOf(document.cookie, name) !== text) {
154
+ rejected = true;
155
+ console.warn(
156
+ `cookie-prefs: ${key}.set() wrote a cookie that does not read back: the browser dropped it, or another cookie named ${name} hides it. Browsers drop a cookie whose name and value exceed 4096 bytes (here ${name.length + encodeURIComponent(text).length}), one with a __Host- prefix, SameSite=None or Partitioned but no Secure, and one for a domain or path this page is not on.`
157
+ );
158
+ }
159
+ }
150
160
  } catch {
151
161
  }
152
162
  check();
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { p as PrefSetter } from '../types-BITLlZeg.cjs';
2
+ import { p as PrefSetter } from '../types-C5uwWL7s.cjs';
3
3
  import { PrefsSnapshot, PrefsRecord, PrefTypes, Pref, PrefValues } from '../index.cjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { p as PrefSetter } from '../types-BITLlZeg.js';
2
+ import { p as PrefSetter } from '../types-C5uwWL7s.js';
3
3
  import { PrefsSnapshot, PrefsRecord, PrefTypes, Pref, PrefValues } from '../index.js';
4
4
 
5
5
  /**
@@ -186,7 +186,12 @@ interface Pref<T, V = T> {
186
186
  * shared with every other reader: treat json and custom values as read-only.
187
187
  */
188
188
  get(): V;
189
- /** Write the cookie in the browser and notify subscribers in this and other tabs. No-op on the server. */
189
+ /**
190
+ * Write the cookie in the browser and notify subscribers in this and other tabs. No-op
191
+ * on the server. Browsers silently drop a cookie they do not accept (name and value
192
+ * over 4096 bytes, `SameSite=None` without `Secure`): the value then stays as it was,
193
+ * and in development `set()` warns once per pref.
194
+ */
190
195
  set(value: T | ((prev: V) => T)): void;
191
196
  /** Delete the cookie, so the value goes back to the default. No-op on the server. */
192
197
  reset(): void;
@@ -186,7 +186,12 @@ interface Pref<T, V = T> {
186
186
  * shared with every other reader: treat json and custom values as read-only.
187
187
  */
188
188
  get(): V;
189
- /** Write the cookie in the browser and notify subscribers in this and other tabs. No-op on the server. */
189
+ /**
190
+ * Write the cookie in the browser and notify subscribers in this and other tabs. No-op
191
+ * on the server. Browsers silently drop a cookie they do not accept (name and value
192
+ * over 4096 bytes, `SameSite=None` without `Secure`): the value then stays as it was,
193
+ * and in development `set()` warns once per pref.
194
+ */
190
195
  set(value: T | ((prev: V) => T)): void;
191
196
  /** Delete the cookie, so the value goes back to the default. No-op on the server. */
192
197
  reset(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cookie-prefs",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Typed cookie-backed user preference state for React and Next.js",
5
5
  "keywords": [
6
6
  "react",