fix(custom-widgets): address v2 merge review (#6446)
This commit is contained in:
1 parent
6aceb2fd1f
commit
df967751f6
123 files changed
+8632
-1477
No files matched your search
@@ -162,19 +162,24 @@ function CustomJsxRendererSession({
|
||||
},
|
||||
[inputTypes],
|
||||
);
|
||||
const bindings = useMemo(
|
||||
() => ({ ...createBindings(data), status, options, inputs }),
|
||||
[createBindings, data, inputs, options, status],
|
||||
);
|
||||
const boundaryKey = useMemo(() => createBoundaryKey(template, bindings), [bindings, template]);
|
||||
const rendered = useMemo(() => {
|
||||
try {
|
||||
return { ...renderSafeJsx({ template, components, bindings }), error: null };
|
||||
const bindings = { ...createBindings(data), status, options, inputs };
|
||||
return {
|
||||
...renderSafeJsx({ template, components, bindings }),
|
||||
boundaryKey: createBoundaryKey(template, bindings),
|
||||
error: null,
|
||||
};
|
||||
} catch (error) {
|
||||
return { node: null, warnings: [], error: error instanceof Error ? error : new Error(String(error)) };
|
||||
return {
|
||||
node: null,
|
||||
warnings: [],
|
||||
boundaryKey: `${template.length}:error`,
|
||||
error: error instanceof Error ? error : new Error(String(error)),
|
||||
};
|
||||
}
|
||||
}, [bindings, components, template]);
|
||||
useEffect(() => setParseErrors([]), [bindings, template]);
|
||||
}, [components, createBindings, data, inputs, options, status, template]);
|
||||
useEffect(() => setParseErrors([]), [rendered.boundaryKey, template]);
|
||||
const handleError = useCallback(
|
||||
(error: Error) =>
|
||||
setParseErrors((current) => {
|
||||
@@ -201,7 +206,7 @@ function CustomJsxRendererSession({
|
||||
registerInput={registerInput}
|
||||
setInputValue={setInputValue}
|
||||
>
|
||||
<RendererErrorBoundary resetKey={boundaryKey} onError={handleError}>
|
||||
<RendererErrorBoundary resetKey={rendered.boundaryKey} onError={handleError}>
|
||||
{rendered.node}
|
||||
</RendererErrorBoundary>
|
||||
</CustomJsxInputsProvider>
|
||||
|
||||
@@ -34,6 +34,11 @@ export interface SubFetchProps {
|
||||
trigger?: "auto" | "manual";
|
||||
}
|
||||
|
||||
// Browser timers use signed 32-bit millisecond delays. Whole-second refresh
|
||||
// intervals are capped at the largest value that remains below that boundary.
|
||||
export const MAX_REFRESH_INTERVAL_SECONDS = 2_147_483;
|
||||
export const MAX_REFRESH_INTERVAL_MS = MAX_REFRESH_INTERVAL_SECONDS * 1_000;
|
||||
|
||||
export function SubFetch(props: SubFetchProps) {
|
||||
const { itemId, previewSessionId, queriesDisabled, port, messages, setQueryState } = useCustomWidgetRuntime();
|
||||
const [manualRun, setManualRun] = useState(false);
|
||||
@@ -155,8 +160,9 @@ export function SubFetch(props: SubFetchProps) {
|
||||
return <SubFetchDataContext.Provider value={result?.data}>{content}</SubFetchDataContext.Provider>;
|
||||
}
|
||||
|
||||
function normalizeRefreshInterval(value: number | undefined): number | false {
|
||||
return value && Number.isFinite(value) && value > 0 ? Math.max(1_000, value * 1_000) : false;
|
||||
export function normalizeRefreshInterval(value: number | undefined): number | false {
|
||||
if (!value || !Number.isFinite(value) || value <= 0) return false;
|
||||
return Math.max(1_000, Math.min(value, MAX_REFRESH_INTERVAL_SECONDS) * 1_000);
|
||||
}
|
||||
|
||||
function renderContent(props: SubFetchProps, data: unknown, metadata: SubFetchMetadata) {
|
||||
|
||||
Reference in new issue
Block a user