Skip to content

Commit cd174ca

Browse files
committed
fix(filter-pill, mode-island): NO-JIRA make next-only code SSR-safe after static rendering merge
1 parent 628ce32 commit cd174ca

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

apps/dialtone-documentation/docs/components/filter-pill.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ The filter pill is built on `DtButton` and `DtPopover`/`DtDropdown`, inheriting
436436
<component-class-table component-name="filter-pill"></component-class-table>
437437

438438
<script setup>
439-
import { ref, computed } from 'vue';
439+
import { ref, computed, inject } from 'vue';
440440

441441
const heroConversationTypes = ref([
442442
{name: 'All Conversations'},
@@ -514,5 +514,6 @@ function selectDropdownType (name, close) {
514514
function resetDropdownType () {
515515
dropdownTypes.value.forEach(f => { f.active = false; });
516516
}
517-
const sizes = Object.keys(window.DIALTONE_CONSTANTS.BUTTON_SIZE_MODIFIERS).filter(k => /^\d+$/.test(k));
517+
const dialtoneConstants = inject('dialtoneConstants', {});
518+
const sizes = Object.keys(dialtoneConstants.BUTTON_SIZE_MODIFIERS ?? {}).filter(k => /^\d+$/.test(k));
518519
</script>

packages/dialtone-vue/components/FilterPill/FilterPill.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206

207207
<script>
208208
import { DtPopover, POPOVER_APPEND_TO_VALUES, POPOVER_PADDING_CLASSES } from '@/components/Popover';
209+
import { HTML_ELEMENT_TYPE } from '@/common/constants';
209210
import { CONTENT_MODE_PROP } from '@/common/mode_constants';
210211
import { BUTTON_SIZE_MODIFIERS, BUTTON_ICON_SIZES, DtButton } from '@/components/Button';
211212
import { DtIconChevronDown, DtIconClose } from '@dialpad/dialtone-icons/vue';
@@ -324,7 +325,7 @@ export default {
324325
* @values body, parent, root, HTMLElement
325326
*/
326327
popoverAppendTo: {
327-
type: [HTMLElement, String],
328+
type: [HTML_ELEMENT_TYPE, String],
328329
default: 'body',
329330
validator: appendTo => {
330331
return POPOVER_APPEND_TO_VALUES.includes(appendTo) ||

packages/dialtone-vue/components/ModeIsland/Utils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ export function getOppositeMode (currentMode) {
88
}
99

1010
/**
11-
* Get the mode from the root HTML element
11+
* Get the mode from the root HTML element.
12+
* Returns the default during SSR, where no DOM exists.
1213
* @returns {string} The root mode or 'light' as default
1314
*/
1415
export function getRootMode () {
16+
if (typeof document === 'undefined') return 'light';
1517
const rootMode = document.documentElement.getAttribute('data-dt-mode');
1618
return rootMode || 'light';
1719
}
1820

1921
/**
20-
* Get the contrast from the root HTML element
22+
* Get the contrast from the root HTML element.
23+
* Returns the default during SSR, where no DOM exists.
2124
* @returns {string} The root contrast or 'default' as default
2225
*/
2326
export function getRootContrast () {
27+
if (typeof document === 'undefined') return 'default';
2428
const rootContrast = document.documentElement.getAttribute('data-dt-contrast');
2529
return rootContrast || 'default';
2630
}
2731

2832
/**
29-
* Get the material from the root HTML element
33+
* Get the material from the root HTML element.
34+
* Returns the default during SSR, where no DOM exists.
3035
* @returns {string} The root material or 'sandstone' as default
3136
*/
3237
export function getRootMaterial () {
38+
if (typeof document === 'undefined') return 'sandstone';
3339
const rootMaterial = document.documentElement.getAttribute('data-dt-material');
3440
return rootMaterial || 'sandstone';
3541
}

0 commit comments

Comments
 (0)