⚡️(frontend) fix roomId RegExp recompilation
The regex was being recreated on every function call, causing unnecessary performance overhead. Hoist the RegExp to a module-level constant to reuse the compiled pattern.
This commit is contained in:
committed by
aleb_the_flash
parent
78ddb121e3
commit
555afe4abd
@@ -4,8 +4,10 @@ export const roomIdPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'
|
||||
export const flexibleRoomIdPattern =
|
||||
'(?:[a-zA-Z0-9]{3}-?[a-zA-Z0-9]{4}-?[a-zA-Z0-9]{3})'
|
||||
|
||||
const roomRegex = new RegExp(`^${roomIdPattern}$`)
|
||||
|
||||
export const isRoomValid = (roomIdOrUrl: string) =>
|
||||
new RegExp(`^${roomIdPattern}$`).test(roomIdOrUrl) ||
|
||||
roomRegex.test(roomIdOrUrl) ||
|
||||
new RegExp(`^${window.location.origin}/${roomIdPattern}$`).test(roomIdOrUrl)
|
||||
|
||||
export const normalizeRoomId = (roomId: string) => {
|
||||
|
||||
@@ -11,6 +11,8 @@ import { CreatePopup } from '@/features/sdk/routes/CreatePopup'
|
||||
import { CreateMeetingButton } from '@/features/sdk/routes/CreateMeetingButton'
|
||||
import { RecordingDownloadRoute } from '@/features/recording'
|
||||
|
||||
const roomIdRegex = new RegExp(`^[/](?<roomId>${flexibleRoomIdPattern})$`)
|
||||
|
||||
export const routes: Record<
|
||||
| 'home'
|
||||
| 'room'
|
||||
@@ -37,7 +39,7 @@ export const routes: Record<
|
||||
room: {
|
||||
name: 'room',
|
||||
to: (roomId: string) => `/${roomId.trim()}`,
|
||||
path: new RegExp(`^[/](?<roomId>${flexibleRoomIdPattern})$`),
|
||||
path: roomIdRegex,
|
||||
Component: RoomRoute,
|
||||
},
|
||||
feedback: {
|
||||
|
||||
Reference in New Issue
Block a user