Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Fix scroll on edit (#1589)
Ivan Starkov935f4aeb8980
diff --git a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.tsindex 7daa416b08..25f974c1c1 100644--- a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts+++ b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts@@ -11,6 +11,7 @@ import {selectedInstanceIntanceToTagStore,selectedInstanceUnitSizesStore,selectedInstanceIsRenderedStore,+ selectedInstanceSelectorStore,} from "~/shared/nano-states";import htmlTags, { type htmlTags as HtmlTags } from "html-tags";import { getAllElementsBoundingBox } from "~/shared/dom-utils";@@ -18,6 +19,10 @@ import { subscribeScrollState } from "~/canvas/shared/scroll-state";import { selectedInstanceOutlineStore } from "~/shared/nano-states";import type { UnitSizes } from "~/builder/features/style-panel/shared/css-value-input/convert-units";import { setDataCollapsed } from "~/canvas/collapsed";+import {+ areInstanceSelectorsEqual,+ type InstanceSelector,+} from "~/shared/tree-utils";const isHtmlTag = (tag: string): tag is HtmlTags =>htmlTags.includes(tag as HtmlTags);@@ -72,11 +77,13 @@ export const SelectedInstanceConnector = ({instance,instanceStyles,instanceProps,+ instanceSelector,}: {instanceElementRef: { current: undefined | HTMLElement };instance: Instance;instanceStyles: StyleDecl[];instanceProps: undefined | Prop[];+ instanceSelector: InstanceSelector;}) => {const instances = useStore(instancesStore);@@ -185,11 +192,24 @@ export const SelectedInstanceConnector = ({unsubscribeScrollState();unsubscribeWindowResize();unsubscribeIsResizingCanvas();- selectedInstanceIsRenderedStore.set(false);++ // Retain selectedInstanceIsRenderedStore state if instanceSelector stays the same.+ // Occasionally, an immediate call to selectedInstanceIsRenderedStore.set(true) may not update StylePanel state+ // within the same batch as the current effect unsubscribe (e.g., due to delayed postMessage). (and cause to lost scroll position)+ // This rare issue is difficult to reproduce, occurring roughly once every 100 calls.+ if (+ areInstanceSelectorsEqual(+ selectedInstanceSelectorStore.get(),+ instanceSelector+ ) === false+ ) {+ selectedInstanceIsRenderedStore.set(false);+ }};}, [instanceElementRef,instance,+ instanceSelector,instanceStyles,// instance props may change dom elementinstanceProps,diff --git a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsxindex 86d7a122dd..0ad4c9a6c7 100644--- a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx+++ b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx@@ -175,6 +175,7 @@ export const WebstudioComponentDev = ({<SelectedInstanceConnectorinstanceElementRef={instanceElementRef}instance={instance}+ instanceSelector={instanceSelector}instanceStyles={instanceStyles}instanceProps={instanceProps}/>