Skip to content

Commit

Permalink
Fix storybook webpack error (#267)
Browse files Browse the repository at this point in the history
* Fixed issue with storybook and webpack findDOMNode error

- With Next 15, we were getting some storybook errors about deprecated findDOMNode. The fix is to specify a nodeRef on TransitionGroups so findDOMNode is not called

* Added webpack typings to next.js and storybook

* Updated version for release
  • Loading branch information
tkmcmaster authored Nov 25, 2024
1 parent ac15d4f commit 44596cc
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ testmerge.json
.env.test.local*
.env.production.local*
.DS_Store
package-lock.json.scripting
2 changes: 1 addition & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-agent",
"version": "3.3.3",
"version": "3.3.4",
"description": "Agent Service for running pewpew tests",
"main": "dist/src/app.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-common",
"version": "3.3.3",
"version": "3.3.4",
"description": "Common Code for the PewPewController and PewPewAgent",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion controller/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Configuration } from "webpack";
import type { StorybookConfig } from "@storybook/nextjs";

const config: StorybookConfig = {
Expand All @@ -19,7 +20,7 @@ const config: StorybookConfig = {
propFilter: prop => prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
}
},
webpackFinal: (config) => {
webpackFinal: (config: Configuration) => {
if (!config.resolve) { config.resolve = {}; }
config.resolve.fallback = {
...(config.resolve.fallback || {}),
Expand Down
10 changes: 7 additions & 3 deletions controller/components/YamlEndpoints/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
PewPewHeader
} from "../../types/yamlwriter";
import { LogLevel, log } from "../../pages/api/util/log";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { QuestionBubble } from "../YamlQuestionBubble";
import styled from "styled-components";
import { uniqueId } from "../../pages/api/util/clientutil";
Expand Down Expand Up @@ -142,6 +142,10 @@ export const Endpoints = ({ urls, ...props }: EndpointsProps) => {
const invalidHitRate = !HIT_RATE_REGEX.test(state.hitRate);
const hitRateStyle: React.CSSProperties = getHitRateStyle(invalidHitRate);
const hitRateTitle: string | undefined = state.hitRate === "" ? "Please enter a Hit Rate" : (getHitRateTitle(invalidHitRate) || "Update all hit rates");

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => addUrl()}>
Expand All @@ -167,9 +171,9 @@ export const Endpoints = ({ urls, ...props }: EndpointsProps) => {
</button>
</NonFlexSpan>
</HitratesDiv>
<TransitionGroup className="endpoints-section_list">
<TransitionGroup className="endpoints-section_list" nodeRef={nodeRef}>
{Array.from(urlsMap.values()).map((url) => (
<CSSTransition key={url.id} timeout={300} classNames="point">
<CSSTransition key={url.id} timeout={300} classNames="point" nodeRef={nodeRef}>
<Urls
deleteUrl={props.deleteUrl}
changeUrl={props.changeUrl}
Expand Down
9 changes: 6 additions & 3 deletions controller/components/YamlLoadPatterns/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { Checkbox, Div, InputsDiv, Label, Span} from "../YamlStyles";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { PewPewLoadPattern } from "../../types/yamlwriter";
import QuestionBubble from "../YamlQuestionBubble";
import { uniqueId } from "../../pages/api/util/clientutil";
Expand Down Expand Up @@ -86,6 +86,9 @@ export function LoadPatterns ({ defaultYaml, patterns, ...props }: LoadPatternPr
props.clearAllPatterns();
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => props.addPattern(newLoadPattern())}>
Expand All @@ -101,13 +104,13 @@ export function LoadPatterns ({ defaultYaml, patterns, ...props }: LoadPatternPr
<QuestionBubble text="Set Default load and ramp time patterns"></QuestionBubble>
<Checkbox type="checkbox" id="defaultPatterns" name="defaultPatterns" onChange={handleClickDefault} checked={state.defaultPatterns} />

<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(loadPatternsMap.values()).map((pewpewPattern: PewPewLoadPattern) => {
// TODO: Do we want to check if they're greater than 0?
const validFrom: boolean = !pewpewPattern.from || NUMBER_REGEX.test(pewpewPattern.from);
const validTo: boolean = NUMBER_REGEX.test(pewpewPattern.to);
const validOver: boolean = OVER_REGEX.test(pewpewPattern.over);
return <CSSTransition key={pewpewPattern.id} timeout={300} classNames="load">
return <CSSTransition key={pewpewPattern.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<Div>
<Span>
<Label> From: </Label>
Expand Down
7 changes: 5 additions & 2 deletions controller/components/YamlLoggers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export function Loggers ({ defaultYaml, ...props }: LoggerProps) {
modalRef.current?.openModal();
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => props.addLogger(newLogger())}>
Expand All @@ -246,9 +249,9 @@ export function Loggers ({ defaultYaml, ...props }: LoggerProps) {
<QuestionBubble text="test_end logs status errors 500 and above and kills test with too many errors"></QuestionBubble>
<Checkbox type="checkbox" id={KILL_LOGGER} onChange={handleClickDefault} checked={state.killLogger} />
</Div>
<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(loggerMap.values()).map((logger: PewPewLogger) => (
<CSSTransition key={logger.id} timeout={300} classNames="load">
<CSSTransition key={logger.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<BorderDiv>
<Span style={{paddingBottom: "15px"}}>
<label style={{marginRight: "7px"}}> Name: </label>
Expand Down
9 changes: 6 additions & 3 deletions controller/components/YamlProviders/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { Div, InputsDiv} from "../YamlStyles";
import { ProviderType, ProviderTypes } from "./ProviderTypes";
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import { PewPewProvider } from "../../types/yamlwriter";
import QuestionBubble from "../YamlQuestionBubble";
import styled from "styled-components";
Expand Down Expand Up @@ -112,6 +112,9 @@ export function Providers ({ providers, ...props }: ProviderMainProps) {
// setState((prevState) => ({...prevState, providers }));
// };

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => addProviderDropDown()}>
Expand Down Expand Up @@ -141,9 +144,9 @@ export function Providers ({ providers, ...props }: ProviderMainProps) {
</ProviderInputsDiv>
}
</Div>
<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(providersMap.values()).map((provider: PewPewProvider) => (
<CSSTransition key={provider.id} timeout={300} classNames="load">
<CSSTransition key={provider.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<ProviderTypes
deleteProvider={props.deleteProvider}
changeProvider={props.changeProvider}
Expand Down
9 changes: 6 additions & 3 deletions controller/components/YamlVars/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SESSION_ID_DEFAULT
} from "../../types/yamlwriter";
import { LogLevel, log } from "../../pages/api/util/log";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import QuestionBubble from "../YamlQuestionBubble";
import VarsDropDown from "./DropDown";
import { uniqueId } from "../../pages/api/util/clientutil";
Expand Down Expand Up @@ -180,6 +180,9 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
}
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => props.addVar(emptyVar())}>
Expand Down Expand Up @@ -225,9 +228,9 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
<VarsDropDown display={state.devKey} onChange={changeEnvironment} />
</div>
</Div>
<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(varsMap.values()).map((pewpewVar: PewPewVars) => (
<CSSTransition key={pewpewVar.id} timeout={300} classNames="load">
<CSSTransition key={pewpewVar.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<Div>
<Span>
<Label> Name: </Label>
Expand Down
17 changes: 11 additions & 6 deletions controller/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Compilation, Compiler, Configuration } from "webpack";
import { access, symlink } from "fs/promises";
import CopyPlugin from "copy-webpack-plugin";
import type { NextConfig } from "next";
Expand Down Expand Up @@ -36,12 +37,15 @@ const nextConfig: NextConfig = {
typedRoutes: true
// instrumentationHook: true,
},
webpack: (config, { isServer, dir: optionsDir }) => {
// Defaults to any but is actually type { import('webpack').Configuration }
webpack: (config: Configuration, { isServer, dir: optionsDir }) => {
const wasmExtensionRegExp = /\.wasm$/;

if (!config.resolve) { config.resolve = {}; }
if (!config.resolve.extensions) { config.resolve.extensions = []; }
config.resolve.extensions.push(".wasm");

config.module.rules.forEach((rule: any) => {
config.module?.rules?.forEach((rule: any) => {
(rule.oneOf || []).forEach((oneOf: any) => {
if (oneOf.loader && oneOf.loader.indexOf("file-loader") >= 0) {
// Make file-loader ignore WASM files
Expand All @@ -50,6 +54,7 @@ const nextConfig: NextConfig = {
});
});

if (!config.output) { config.output = {}; }
config.output.webassemblyModuleFilename = "static/wasm/[modulehash].wasm";
if (!config.experiments) { config.experiments = {}; }
config.experiments.asyncWebAssembly = true;
Expand All @@ -58,6 +63,7 @@ const nextConfig: NextConfig = {
// Compiling we run into an issue where it can't find the config wasm.
// On Linux the workaround is to create a symlink to the correct location
// On Windows, the symlinks fail so we must copy the file
if (!config.plugins) { config.plugins = []; }
config.plugins.push(
platform() === "win32"
// https://github.com/vercel/next.js/issues/25852#issuecomment-1727385542
Expand All @@ -68,13 +74,12 @@ const nextConfig: NextConfig = {
})
// https://github.com/vercel/next.js/issues/25852#issuecomment-1057059000
: new (class {
apply (compiler: any) {
apply (compiler: Compiler) {
compiler.hooks.afterEmit.tapPromise(
"SymlinkWebpackPlugin",
// eslint-disable-next-line @typescript-eslint/no-shadow
async (compiler: any) => {
async (compilation: Compilation) => {
if (isServer) {
const from = join(compiler.options.output.path, "config_wasm_bg.wasm");
const from = join(compilation.options.output.path!, "config_wasm_bg.wasm");
const to = join(optionsDir, "../lib/config-wasm/pkg/config_wasm_bg.wasm");
// options.dir /.../pewpew/controller
// console.log(`from/to: ${from} -> ${to}`);
Expand Down
5 changes: 3 additions & 2 deletions controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fs/ppaas-controller",
"version": "3.3.3",
"version": "3.3.4",
"description": "Controller Service for running pewpew tests",
"private": true,
"scripts": {
Expand Down Expand Up @@ -127,6 +127,7 @@
"set-value": "^4.1.0",
"storybook": "~8.4.0",
"trim": "^1.0.1",
"typescript": "^5.3.0"
"typescript": "^5.3.0",
"webpack": "^5.0.0"
}
}
3 changes: 2 additions & 1 deletion guide/results-viewer-react/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Configuration } from "webpack";
import type { StorybookConfig } from "@storybook/nextjs";

const config: StorybookConfig = {
Expand All @@ -16,7 +17,7 @@ const config: StorybookConfig = {
propFilter: prop => prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
}
},
webpackFinal: async config => {
webpackFinal: async (config: Configuration) => {
if (!config.experiments) {
config.experiments = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
PewPewHeader
} from "../../util/yamlwriter";
import { LogLevel, log } from "../../util/log";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { QuestionBubble } from "../YamlQuestionBubble";
import styled from "styled-components";
import { uniqueId } from "../../util/clientutil";
Expand Down Expand Up @@ -142,6 +142,9 @@ export const Endpoints = ({ urls, ...props }: EndpointsProps) => {
const invalidHitRate = !HIT_RATE_REGEX.test(state.hitRate);
const hitRateStyle: React.CSSProperties = getHitRateStyle(invalidHitRate);
const hitRateTitle: string | undefined = state.hitRate === "" ? "Please enter a Hit Rate" : (getHitRateTitle(invalidHitRate) || "Update all hit rates");
// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => addUrl()}>
Expand All @@ -167,9 +170,9 @@ export const Endpoints = ({ urls, ...props }: EndpointsProps) => {
</button>
</NonFlexSpan>
</HitratesDiv>
<TransitionGroup className="endpoints-section_list">
<TransitionGroup className="endpoints-section_list" nodeRef={nodeRef}>
{Array.from(urlsMap.values()).map((url) => (
<CSSTransition key={url.id} timeout={300} classNames="point">
<CSSTransition key={url.id} timeout={300} classNames="point" nodeRef={nodeRef}>
<Urls
deleteUrl={props.deleteUrl}
changeUrl={props.changeUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { Checkbox, Div, InputsDiv, Label, Span} from "../YamlStyles";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { PewPewLoadPattern } from "../../util/yamlwriter";
import QuestionBubble from "../YamlQuestionBubble";
import { uniqueId } from "../../util/clientutil";
Expand Down Expand Up @@ -86,6 +86,9 @@ export function LoadPatterns ({ defaultYaml, patterns, ...props }: LoadPatternPr
props.clearAllPatterns();
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => props.addPattern(newLoadPattern())}>
Expand All @@ -101,13 +104,13 @@ export function LoadPatterns ({ defaultYaml, patterns, ...props }: LoadPatternPr
<QuestionBubble text="Set Default load and ramp time patterns"></QuestionBubble>
<Checkbox type="checkbox" id="defaultPatterns" name="defaultPatterns" onChange={handleClickDefault} checked={state.defaultPatterns} />

<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(loadPatternsMap.values()).map((pewpewPattern: PewPewLoadPattern) => {
// TODO: Do we want to check if they're greater than 0?
const validFrom: boolean = !pewpewPattern.from || NUMBER_REGEX.test(pewpewPattern.from);
const validTo: boolean = NUMBER_REGEX.test(pewpewPattern.to);
const validOver: boolean = OVER_REGEX.test(pewpewPattern.over);
return <CSSTransition key={pewpewPattern.id} timeout={300} classNames="load">
return <CSSTransition key={pewpewPattern.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<Div>
<Span>
<Label> From: </Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export function Loggers ({ defaultYaml, ...props }: LoggerProps) {
modalRef.current?.openModal();
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => props.addLogger(newLogger())}>
Expand All @@ -246,9 +249,9 @@ export function Loggers ({ defaultYaml, ...props }: LoggerProps) {
<QuestionBubble text="test_end logs status errors 500 and above and kills test with too many errors"></QuestionBubble>
<Checkbox type="checkbox" id={KILL_LOGGER} onChange={handleClickDefault} checked={state.killLogger} />
</Div>
<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(loggerMap.values()).map((logger: PewPewLogger) => (
<CSSTransition key={logger.id} timeout={300} classNames="load">
<CSSTransition key={logger.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<BorderDiv>
<Span style={{paddingBottom: "15px"}}>
<label style={{marginRight: "7px"}}> Name: </label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { Div, InputsDiv} from "../YamlStyles";
import { ProviderType, ProviderTypes } from "./ProviderTypes";
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import { PewPewProvider } from "../../util/yamlwriter";
import QuestionBubble from "../YamlQuestionBubble";
import styled from "styled-components";
Expand Down Expand Up @@ -112,6 +112,9 @@ export function Providers ({ providers, ...props }: ProviderMainProps) {
// setState((prevState) => ({...prevState, providers }));
// };

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
return (
<InputsDiv>
<button onClick={() => addProviderDropDown()}>
Expand Down Expand Up @@ -141,9 +144,9 @@ export function Providers ({ providers, ...props }: ProviderMainProps) {
</ProviderInputsDiv>
}
</Div>
<TransitionGroup className="loadPatter-section_list">
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(providersMap.values()).map((provider: PewPewProvider) => (
<CSSTransition key={provider.id} timeout={300} classNames="load">
<CSSTransition key={provider.id} timeout={300} classNames="load" nodeRef={nodeRef}>
<ProviderTypes
deleteProvider={props.deleteProvider}
changeProvider={props.changeProvider}
Expand Down
Loading

0 comments on commit 44596cc

Please sign in to comment.