@datalayer/primer-addons 1.0.33 → 1.0.34

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.
@@ -109,7 +109,9 @@ export function DatalayerThemeProvider(props) {
109
109
  * React trees; what they share with the application is the document.
110
110
  */
111
111
  const sentinel = useRef(null);
112
- const [themedAncestor, setThemedAncestor] = useState(null);
112
+ // `undefined` until the DOM has been read: until then this provider does
113
+ // not know whether the page is its to theme, and writes nothing on it.
114
+ const [themedAncestor, setThemedAncestor] = useState(undefined);
113
115
  const [ancestorMode, setAncestorMode] = useState(null);
114
116
  useLayoutEffect(() => {
115
117
  // The sentinel's parent is this provider's own element; anything themed
@@ -134,7 +136,8 @@ export function DatalayerThemeProvider(props) {
134
136
  });
135
137
  return () => observer.disconnect();
136
138
  }, []);
137
- const nested = themedAncestor !== null;
139
+ const nested = themedAncestor != null;
140
+ const placed = themedAncestor !== undefined;
138
141
  // This provider's scope: what its theme's stylesheet is scoped to, and
139
142
  // where an outer provider's stylesheet stops.
140
143
  const scope = useId().replace(/[^A-Za-z0-9_-]/g, "");
@@ -165,8 +168,13 @@ export function DatalayerThemeProvider(props) {
165
168
  // next overlay came up in the wrong colour. Nesting is read from the DOM
166
169
  // rather than from React context, because those widget roots are separate
167
170
  // React trees: what they share with the application is the document.
171
+ //
172
+ // Not before the DOM has been read: the first commit's effects run before
173
+ // the update that says whether this provider is nested, and a nested one
174
+ // — an application embedded in another product's page, in its own shadow
175
+ // root (LOOP T-13) — wrote its theme on that page's <body> before it knew.
168
176
  useEffect(() => {
169
- if (nested) {
177
+ if (!placed || nested) {
170
178
  // Another provider owns the page's portal root; see above.
171
179
  return;
172
180
  }
@@ -176,13 +184,15 @@ export function DatalayerThemeProvider(props) {
176
184
  ? "light"
177
185
  : resolvedColorMode);
178
186
  syncPortalThemeStyles(portalStyles);
179
- }, [nested, resolvedColorMode, portalStyles]);
187
+ }, [placed, nested, resolvedColorMode, portalStyles]);
180
188
  // The theme's own stylesheet, if it has one: for this provider's element,
181
189
  // and for the portal root when this provider owns it (see above). Removed
182
190
  // when the theme changes, or the provider goes. A layout effect, so the
183
191
  // first paint is already in the theme's shapes.
184
192
  const themeCss = styles.css;
185
- useLayoutEffect(() => injectThemeStylesheet(scope, themeCss, !nested), [scope, themeCss, nested]);
193
+ useLayoutEffect(() => placed
194
+ ? injectThemeStylesheet(scope, themeCss, !nested)
195
+ : () => undefined, [scope, themeCss, placed, nested]);
186
196
  return (_jsx(ThemeProvider, { colorMode: resolvedColorMode, theme: resolvedTheme, ...rest, children: _jsxs(BaseStyles, { [THEME_SCOPE_ATTRIBUTE]: scope, style: {
187
197
  lineHeight: "1.7",
188
198
  transition: "background-color 0.25s ease, color 0.25s ease",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",