Skip to content

Commit c8fba5c

Browse files
Jeffrey Lauwersclaude
andcommitted
Improve TokenTable polling to detect CSS value changes
- Add direct CSS value polling in addition to data-attribute checking - Poll actual computed CSS value every 500ms - Catches token changes even when data-dsn-tokens attribute isn't updated - Should fix live value updates on GitHub Pages Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 51c4b61 commit c8fba5c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/storybook/src/components/TokenTable.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,27 @@ function useComputedCssValue(cssVar: string): string {
221221
window.addEventListener('storybook-globals-updated', handleStorybookUpdate);
222222

223223
// Poll for changes as fallback (useful for docs-only pages where decorator doesn't run)
224+
// Check both the data attribute AND the actual CSS value to catch all changes
224225
const pollInterval = setInterval(() => {
225-
// Check if data-dsn-tokens attribute changed
226+
// Method 1: Check if data-dsn-tokens attribute changed
226227
const currentToken = document
227228
.querySelector('[data-dsn-tokens]')
228229
?.getAttribute('data-dsn-tokens');
229230
if (currentToken && currentToken !== window.__lastDsnToken) {
230231
window.__lastDsnToken = currentToken;
231232
triggerUpdate();
233+
return;
234+
}
235+
236+
// Method 2: Poll the actual CSS value to detect changes
237+
// This catches cases where tokens load but data attribute isn't set yet
238+
const currentValue = getComputedStyle(document.documentElement)
239+
.getPropertyValue(cssVar)
240+
.trim();
241+
242+
if (currentValue && currentValue !== window.__lastDsnToken) {
243+
window.__lastDsnToken = currentValue;
244+
triggerUpdate();
232245
}
233246
}, 500);
234247

0 commit comments

Comments
 (0)