Merge pull request #4261 from xyflow/react/styles-loaded-warning
React/styles loaded warning
This commit is contained in:
@@ -12,7 +12,6 @@ import {
|
|||||||
Node,
|
Node,
|
||||||
Edge,
|
Edge,
|
||||||
} from '@xyflow/react';
|
} from '@xyflow/react';
|
||||||
import '@xyflow/react/dist/style.css';
|
|
||||||
|
|
||||||
const initialNodes: Node[] = [
|
const initialNodes: Node[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { ReactFlow } from '@xyflow/react';
|
import { ReactFlow } from '@xyflow/react';
|
||||||
import '@xyflow/react/dist/style.css';
|
|
||||||
|
|
||||||
import { useDispatch, useSelector, Provider } from 'react-redux';
|
import { useDispatch, useSelector, Provider } from 'react-redux';
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { useViewportSync } from '../../hooks/useViewportSync';
|
|||||||
import { ConnectionLineWrapper } from '../../components/ConnectionLine';
|
import { ConnectionLineWrapper } from '../../components/ConnectionLine';
|
||||||
import { useNodeOrEdgeTypesWarning } from './useNodeOrEdgeTypesWarning';
|
import { useNodeOrEdgeTypesWarning } from './useNodeOrEdgeTypesWarning';
|
||||||
import type { Edge, Node, ReactFlowProps } from '../../types';
|
import type { Edge, Node, ReactFlowProps } from '../../types';
|
||||||
|
import { useStylesLoadedWarning } from './useStylesLoadedWarning';
|
||||||
|
|
||||||
export type GraphViewProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = Omit<
|
export type GraphViewProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = Omit<
|
||||||
ReactFlowProps<NodeType, EdgeType>,
|
ReactFlowProps<NodeType, EdgeType>,
|
||||||
@@ -104,6 +105,7 @@ function GraphViewComponent<NodeType extends Node = Node, EdgeType extends Edge
|
|||||||
}: GraphViewProps<NodeType, EdgeType>) {
|
}: GraphViewProps<NodeType, EdgeType>) {
|
||||||
useNodeOrEdgeTypesWarning(nodeTypes);
|
useNodeOrEdgeTypesWarning(nodeTypes);
|
||||||
useNodeOrEdgeTypesWarning(edgeTypes);
|
useNodeOrEdgeTypesWarning(edgeTypes);
|
||||||
|
useStylesLoadedWarning();
|
||||||
|
|
||||||
useOnInitHandler(onInit);
|
useOnInitHandler(onInit);
|
||||||
useViewportSync(viewport);
|
useViewportSync(viewport);
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { errorMessages } from '@xyflow/system';
|
||||||
|
|
||||||
|
import { useStoreApi } from '../../hooks/useStore';
|
||||||
|
|
||||||
|
export function useStylesLoadedWarning() {
|
||||||
|
const store = useStoreApi();
|
||||||
|
const checked = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
if (!checked.current) {
|
||||||
|
const pane = document.querySelector('.react-flow__pane');
|
||||||
|
|
||||||
|
if (pane && !(window.getComputedStyle(pane).zIndex === '1')) {
|
||||||
|
store.getState().onError?.('013', errorMessages['error013']('react'));
|
||||||
|
}
|
||||||
|
|
||||||
|
checked.current = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { CoordinateExtent, HandleType } from './types';
|
import { CoordinateExtent, HandleType } from './types';
|
||||||
|
|
||||||
// @todo: update URLs to xyflow
|
|
||||||
export const errorMessages = {
|
export const errorMessages = {
|
||||||
error001: () =>
|
error001: () =>
|
||||||
'[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001',
|
'[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001',
|
||||||
@@ -23,6 +22,8 @@ export const errorMessages = {
|
|||||||
error011: (edgeType: string) => `Edge type "${edgeType}" not found. Using fallback type "default".`,
|
error011: (edgeType: string) => `Edge type "${edgeType}" not found. Using fallback type "default".`,
|
||||||
error012: (id: string) =>
|
error012: (id: string) =>
|
||||||
`Node with id "${id}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,
|
`Node with id "${id}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,
|
||||||
|
error013: (lib: string = 'react') =>
|
||||||
|
`It seems that you haven't loaded the styles. Please import '@xyflow/${lib}/dist/style.css' or base.css to make sure everything is working properly.`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const infiniteExtent: CoordinateExtent = [
|
export const infiniteExtent: CoordinateExtent = [
|
||||||
|
|||||||
Reference in New Issue
Block a user