Skip to content

Commit

Permalink
chore: Improve hot reloading (#4808)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Nov 6, 2024
1 parent 9db91ae commit fd5c532
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 25 deletions.
169 changes: 162 additions & 7 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.10.0",
"webpack-dev-middleware": "5.3.4",
"webpack-hot-middleware": "2.25.3",
"webpack-hot-middleware": "2.26.1",
"whatwg-fetch": "3.0.0",
"x-frame-options": "^1.0.0",
"yaml": "^2.2.2"
},
"devDependencies": {
"@dword-design/eslint-plugin-import-alias": "^2.0.7",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@types/classnames": "^2.3.1",
"@types/color": "^3.0.3",
"@types/dompurify": "^3.0.2",
Expand All @@ -171,6 +172,7 @@
"eslint-plugin-sort-keys-fix": "^1.1.2",
"nodemon": "^3.0.1",
"raw-loader": "0.5.1",
"react-refresh": "^0.14.2",
"ssgrtk": "^0.3.5",
"testcafe": "^3.2.0",
"typescript": "4.6.4"
Expand Down
31 changes: 16 additions & 15 deletions frontend/web/components/datadog-client.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { DDClient, init } from '@datadog/ui-extensions-sdk'
import API from 'project/api'

const client: DDClient = init({
authProvider: {
authStateCallback: async () => {
const user = API.getCookie('t')
return {
isAuthenticated: !!user,
}
},
resolution: 'message',
const client: () => DDClient = () =>
init({
authProvider: {
authStateCallback: async () => {
const user = API.getCookie('t')
return {
isAuthenticated: !!user,
}
},
resolution: 'message',

/**
* This where we want Datadog to direct users to authenticate.
*/
url: '/',
},
})
/**
* This where we want Datadog to direct users to authenticate.
*/
url: '/',
},
})
export default client
13 changes: 11 additions & 2 deletions frontend/web/components/pages/WidgetPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { Component, ReactNode, useEffect, useState } from 'react'
import React, {
Component,
ReactNode,
useEffect,
useMemo,
useState,
} from 'react'
import TagFilter from 'components/tags/TagFilter'
import Tag from 'components/tags/Tag'
import FeatureRow from 'components/FeatureRow'
Expand Down Expand Up @@ -27,7 +33,7 @@ import {
TagStrategy,
} from 'common/types/responses'
import { useCustomWidgetOptionString } from '@datadog/ui-extensions-react'
import client from 'components/datadog-client'
import ddClient from 'components/datadog-client'
import { resolveAuthFlow } from '@datadog/ui-extensions-sdk'
import AuditLog from 'components/AuditLog'
import OrgEnvironmentSelect from 'components/OrgEnvironmentSelect'
Expand Down Expand Up @@ -463,6 +469,9 @@ export default function Widget() {
useEffect(() => {
document.body.classList.add('widget-mode')
}, [])
const client = useMemo(() => {
return ddClient()
}, [])
const projectId = useCustomWidgetOptionString(client, 'Project')
const environmentId = useCustomWidgetOptionString(client, 'Environment')
const pageSize = useCustomWidgetOptionString(client, 'PageSize') || '5'
Expand Down
3 changes: 3 additions & 0 deletions frontend/webpack/webpack.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

const base = require('../webpack.config');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

module.exports = {
...base,
Expand All @@ -15,6 +16,7 @@ module.exports = {
'./web/main.js',
],
devServer: {
hot: true,
outputPath: __dirname,
},
output: {
Expand All @@ -26,6 +28,7 @@ module.exports = {

plugins: require('./plugins').concat([
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
new webpack.DefinePlugin({
__DEV__: true,
whitelabel: JSON.stringify(process.env.WHITELABEL),
Expand Down

0 comments on commit fd5c532

Please sign in to comment.