Skip to content

Commit 84a1501

Browse files
authored
tooling: fix two more spots where vite complains it can't HMR (#2341)
fix two more spots where vite complains it can't HMR
1 parent 6615cb6 commit 84a1501

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

app/forms/image-upload.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { readBlobAsBase64 } from '~/util/file'
4444
import { invariant } from '~/util/invariant'
4545
import { links } from '~/util/links'
4646
import { pb } from '~/util/path-builder'
47+
import { isAllZeros } from '~/util/str'
4748
import { GiB, KiB } from '~/util/units'
4849

4950
/** Format file size with two decimal points */
@@ -113,12 +114,6 @@ function Step({ children, state, label, className }: StepProps) {
113114
)
114115
}
115116

116-
/**
117-
* Does a base64 string represent underlying data that's all zeros, i.e., does
118-
* it look like `AAAAAAAAAAAAAAAA==`?
119-
*/
120-
export const isAllZeros = (base64Data: string) => /^A*=*$/.test(base64Data)
121-
122117
const randInt = () => Math.floor(Math.random() * 100000000)
123118

124119
function getTmpDiskName(imageName: string) {

app/ui/lib/Modal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
*/
88
import * as Dialog from '@radix-ui/react-dialog'
99
import { animated, useTransition } from '@react-spring/web'
10-
import React, { createContext, forwardRef, useContext, useId } from 'react'
10+
import React, { forwardRef, useId } from 'react'
1111

1212
import { Close12Icon } from '@oxide/design-system/icons/react'
1313

1414
import { classed } from '~/util/classed'
1515

1616
import { Button } from './Button'
1717
import { DialogOverlay } from './DialogOverlay'
18-
19-
const ModalContext = createContext(false)
20-
21-
export const useIsInModal = () => useContext(ModalContext)
18+
import { ModalContext } from './modal-context'
2219

2320
export type ModalProps = {
2421
title?: string

app/ui/lib/SideModal.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@
88
import * as Dialog from '@radix-ui/react-dialog'
99
import { animated, useTransition } from '@react-spring/web'
1010
import cn from 'classnames'
11-
import React, { createContext, useContext, useRef, type ReactNode } from 'react'
11+
import React, { useRef, type ReactNode } from 'react'
1212

1313
import { Close12Icon, Error12Icon } from '@oxide/design-system/icons/react'
1414

1515
import { useIsOverflow } from '~/hooks'
1616
import { Message } from '~/ui/lib/Message'
17-
import { useIsInModal } from '~/ui/lib/Modal'
1817
import { classed } from '~/util/classed'
1918

2019
import { DialogOverlay } from './DialogOverlay'
21-
22-
const SideModalContext = createContext(false)
23-
24-
export const useIsInSideModal = () => useContext(SideModalContext)
20+
import { SideModalContext, useIsInModal, useIsInSideModal } from './modal-context'
2521

2622
export function usePopoverZIndex() {
2723
const isInModal = useIsInModal()

app/ui/lib/modal-context.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
9+
import { createContext, useContext } from 'react'
10+
11+
export const ModalContext = createContext(false)
12+
export const useIsInModal = () => useContext(ModalContext)
13+
14+
export const SideModalContext = createContext(false)
15+
export const useIsInSideModal = () => useContext(SideModalContext)

app/forms/all-zeros.spec.ts renamed to app/util/all-zeros.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { expect, test } from 'vitest'
99

10-
import { isAllZeros } from './image-upload'
10+
import { isAllZeros } from '~/util/str'
1111

1212
function numberToUint8Array(num: number) {
1313
const bytes = []

app/util/str.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ export const validateIp = (ip: string) => {
6565
const isv6 = !isv4 && IPV6_REGEX.test(ip)
6666
return { isv4, isv6, valid: isv4 || isv6 }
6767
}
68+
69+
/**
70+
* Does a base64 string represent underlying data that's all zeros, i.e., does
71+
* it look like `AAAAAAAAAAAAAAAA==`?
72+
*/
73+
export const isAllZeros = (base64Data: string) => /^A*=*$/.test(base64Data)

0 commit comments

Comments
 (0)