@terpjs/react-core 0.41.0 → 0.42.0

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/styles.test.ts +27 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/react-core",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "type": "module",
5
5
  "description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@tanstack/react-router": "^1.170.46",
18
- "@terpjs/contract": "^0.41.0"
18
+ "@terpjs/contract": "^0.42.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": "^19.0.0",
@@ -26,13 +26,13 @@
26
26
  "@testing-library/react": "^16.3.3",
27
27
  "@types/react": "^19.3.0",
28
28
  "@types/react-dom": "^19.3.0",
29
- "@vitejs/plugin-react": "^6.1.2",
30
- "jsdom": "^30.1.3",
29
+ "@vitejs/plugin-react": "^6.2.1",
30
+ "jsdom": "^31.0.0",
31
31
  "react": "^19.3.1",
32
32
  "react-dom": "^19.3.1",
33
33
  "typescript": "^6.0.3",
34
- "vite": "^8.3.5",
35
- "vitest": "^5.0.5"
34
+ "vite": "^8.3.6",
35
+ "vitest": "^5.1.0"
36
36
  },
37
37
  "license": "Apache-2.0",
38
38
  "repository": {
@@ -131,10 +131,29 @@ afterEach(() => {
131
131
  document.querySelectorAll(`style#${TERP_STYLES_ID}`).forEach((node) => node.remove());
132
132
  });
133
133
 
134
+ /**
135
+ * Run *body* in a document with no `adoptedStyleSheets`, the one the injector's `<style>`
136
+ * route is for. jsdom 31 gave the document that property, so a test that means the element
137
+ * route has to say so: left to the environment, the injector adopts a sheet and appends
138
+ * no element, and these tests would read whichever route the installed jsdom happens to take.
139
+ */
140
+ function withoutAdoptedStyleSheets(body: () => void): void {
141
+ Object.defineProperty(document, "adoptedStyleSheets", {
142
+ configurable: true,
143
+ get: () => undefined,
144
+ });
145
+ try {
146
+ body();
147
+ } finally {
148
+ delete (document as unknown as { adoptedStyleSheets?: unknown }).adoptedStyleSheets;
149
+ }
150
+ }
151
+
134
152
  describe("injectTerpStyles", () => {
135
153
  it("adopts a constructable stylesheet when the document supports one", () => {
136
- // jsdom exposes the CSSStyleSheet constructor but not document.adoptedStyleSheets,
137
- // so the property is defined here to reach the branch a real browser takes. That
154
+ // jsdom below 31 exposes the CSSStyleSheet constructor but not
155
+ // document.adoptedStyleSheets, and the test reads what was adopted, so the property
156
+ // is defined here whichever jsdom runs it, to reach the branch a real browser takes. That
138
157
  // branch is the whole point of the injector: an adopted sheet is not governed by
139
158
  // CSP's style-src, so a generated app needs no 'unsafe-inline' — measured in
140
159
  // Chromium, where a <style> element is reported as style-src-elem and dropped.
@@ -165,9 +184,11 @@ describe("injectTerpStyles", () => {
165
184
  });
166
185
 
167
186
  it("appends the stylesheet once and is idempotent on re-invocation", () => {
168
- injectTerpStyles();
169
- injectTerpStyles();
170
- injectTerpStyles();
187
+ withoutAdoptedStyleSheets(() => {
188
+ injectTerpStyles();
189
+ injectTerpStyles();
190
+ injectTerpStyles();
191
+ });
171
192
  const nodes = document.querySelectorAll(`style#${TERP_STYLES_ID}`);
172
193
  expect(nodes.length).toBe(1);
173
194
  expect(nodes[0]?.textContent ?? "").toContain("data-terp");
@@ -176,7 +197,7 @@ describe("injectTerpStyles", () => {
176
197
  });
177
198
 
178
199
  it("themes scrollbars against the token palette (thin, not the OS default)", () => {
179
- injectTerpStyles();
200
+ withoutAdoptedStyleSheets(() => injectTerpStyles());
180
201
  const sheet = document.querySelector(`style#${TERP_STYLES_ID}`)?.textContent ?? "";
181
202
  expect(sheet).toContain("scrollbar-width: thin");
182
203
  expect(sheet).toContain("scrollbar-color: var(--color-neutral-300) transparent");