From 744b00455deaa246d2cde05aea313f41e4a66a8b Mon Sep 17 00:00:00 2001 From: Enoch Riese Date: Wed, 28 Jun 2023 13:04:45 -0500 Subject: [PATCH] allow designs with no measurements to draft --- sites/shared/components/workbench/new.mjs | 11 ++++++++--- sites/shared/components/workbench/workbench.en.yaml | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sites/shared/components/workbench/new.mjs b/sites/shared/components/workbench/new.mjs index 2e0168b54b7..dc57379dc46 100644 --- a/sites/shared/components/workbench/new.mjs +++ b/sites/shared/components/workbench/new.mjs @@ -80,6 +80,7 @@ export const Workbench = ({ design, Design, DynamicDocs }) => { // protect against loops if (!mounted) return + setMounted(true) const [ok, missing] = hasRequiredMeasurements(Design, settings.measurements) if (ok) setMissingMeasurements(false) // Force the measurements view if we have missing measurements @@ -117,8 +118,11 @@ export const Workbench = ({ design, Design, DynamicDocs }) => { setControl: controlState.update, } - // Don't bother without a Design - if (!Design) return + // wait for mount. this helps prevent hydration issues + if (!mounted) return + + // Warn that the design is somehow missing + if (!Design) return {t('workbench.noDesignFound')} // Short-circuit errors early if (error) @@ -163,7 +167,8 @@ export const Workbench = ({ design, Design, DynamicDocs }) => { const layout = ui.layouts?.[view] || settings.layout || true // Generate the pattern here so we can pass it down to both the view and the options menu const pattern = - settings.measurements !== undefined && new Design({ layout, embed: true, ...settings }) + (Design.patternConfig.measurements.length === 0 || settings.measurements !== undefined) && + new Design({ layout, embed: true, ...settings }) // Return early if the pattern is not initialized yet if (typeof pattern.getConfig !== 'function') return null diff --git a/sites/shared/components/workbench/workbench.en.yaml b/sites/shared/components/workbench/workbench.en.yaml index 9b2500d65c4..c155b6c4e82 100644 --- a/sites/shared/components/workbench/workbench.en.yaml +++ b/sites/shared/components/workbench/workbench.en.yaml @@ -31,3 +31,4 @@ patternInspector: Pattern Inspector docs: Documentation configurePattern: Configure pattern measies: Pattern Measurements +noDesignFound: We could not find this design. This shouldn't happen, so we'd really appreciate you reporting it.