The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Polyfill Node.contains, compareDocumentPosition and getRootNode in the front component worker (#26518)
Raphaël Bosi19da4c7c3867
diff --git a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdxindex c1775280723..74c02bd7b6a 100644--- a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx+++ b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx@@ -930,7 +930,7 @@ A `ref` gives you a sandbox element, not an `HTMLElement`.| What you write | What happens | Use instead ||----------------|--------------|-------------|| `ref.current.focus()`, `.click()`, `.select()`, `.setSelectionRange()`, `.scrollIntoView()`, `video.play()` | Throws | Controlled components; read values from `event.target` |-| `document.createTreeWalker()` | Throws | `querySelector()` / `querySelectorAll()`, `matches()`, `closest()` (including pseudo-classes such as `:not()`) and `getElementById()` work; `getElementsByClassName()` works too, but returns a static collection, not a live `HTMLCollection` |+| `document.createTreeWalker()` | Throws | `querySelector()` / `querySelectorAll()`, `matches()`, `closest()` (including pseudo-classes such as `:not()`), `getElementById()`, `contains()` and `compareDocumentPosition()` work; `getElementsByClassName()` works too, but returns a static collection, not a live `HTMLCollection` || `document.activeElement` | Always `undefined` | Track focus with `onFocus` / `onBlur` || `canvas` | Renders nothing, no error | SVG, or draw offscreen and show the result in an `img` element || `createPortal(node, document.body)` | Renders nothing, while `isConnected` reports success | Overlays inline with `position: absolute`, or pass the library your own container element |diff --git a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsxindex 223637bfa4f..d10d6db0dfa 100644--- a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx+++ b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx@@ -1,6 +1,5 @@import { themeTokenTest } from '@/__stories__/twenty-ui-gallery/utils/themeTokenTest';-import { inputPreactTest } from '@/__stories__/twenty-ui-gallery/utils/inputPreactTest';-import { inputReactTest } from '@/__stories__/twenty-ui-gallery/utils/inputReactTest';+import { inputTest } from '@/__stories__/twenty-ui-gallery/utils/inputTest';import { settingsRowTest } from '@/__stories__/twenty-ui-gallery/utils/settingsRowTest';import { resizeHandleTest } from '@/__stories__/twenty-ui-gallery/utils/resizeHandleTest';import { createListItemSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createListItemSandboxFailureTest';@@ -17,13 +16,6 @@ import {resetFrontComponentStoryMocks,} from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';import { type TwentyUiGalleryStory as Story } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryStory';-import {- checkboxTest,- createFieldControlsTest,- createRadioGroupPreactTest,- sliderTest,- toastTest,-} from '@/__stories__/twenty-ui-gallery/utils/componentInteractionTests';import {statusControlsTest,tagControlsTest,@@ -41,18 +33,23 @@ import {alertDialogTest,menuTest,popoverTest,- radioGroupReactTest,selectTest,- sliderRangeTest,switchTest,- tabsPreactTest,- tabsReactTest,+ tabsTest,} from '@/__stories__/twenty-ui-gallery/utils/sandboxFailureTests';import { FrontComponentRenderer } from '@/host/components/FrontComponentRenderer';import {tooltipEscapeDismissalTest,tooltipEscapeIgnoredTest,} from '@/__stories__/twenty-ui-gallery/utils/tooltipTests';+import { cardPickerDroppedClickTest } from '@/__stories__/twenty-ui-gallery/utils/cardPickerDroppedClickTest';+import { cardPickerTest } from '@/__stories__/twenty-ui-gallery/utils/cardPickerTest';+import { checkboxTest } from '@/__stories__/twenty-ui-gallery/utils/checkboxTest';+import { createFieldControlsTest } from '@/__stories__/twenty-ui-gallery/utils/createFieldControlsTest';+import { radioGroupTest } from '@/__stories__/twenty-ui-gallery/utils/radioGroupTest';+import { sliderRangeTest } from '@/__stories__/twenty-ui-gallery/utils/sliderRangeTest';+import { sliderTest } from '@/__stories__/twenty-ui-gallery/utils/sliderTest';+import { toastTest } from '@/__stories__/twenty-ui-gallery/utils/toastTest';const meta: Meta<typeof FrontComponentRenderer> = {title: 'FrontComponent/Twenty UI Gallery',@@ -102,12 +99,12 @@ export const IconPreact: Story = createGalleryStory({export const InputReact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-input-gallery',runtime: 'react',- play: inputReactTest,+ play: inputTest,});export const InputPreact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-input-gallery',runtime: 'preact',- play: inputPreactTest,+ play: inputTest,});export const JsonVisualizerReact: Story = createGalleryStory({@@ -262,12 +259,12 @@ export const SettingsRowPreact: Story = createGalleryStory({export const TabsReact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-tabs',runtime: 'react',- play: tabsReactTest,+ play: tabsTest,});export const TabsPreact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-tabs',runtime: 'preact',- play: tabsPreactTest,+ play: tabsTest,});export const PopoverReact: Story = createGalleryStory({@@ -396,23 +393,23 @@ export const SliderRangePreact: Story = createGalleryStory({export const RadioGroupReact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-radio-group',runtime: 'react',- play: radioGroupReactTest,+ play: radioGroupTest,});export const RadioGroupPreact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-radio-group',runtime: 'preact',- play: createRadioGroupPreactTest({ optionName: 'Daily' }),+ play: radioGroupTest,});export const CardPickerReact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-radio-group',runtime: 'react',- play: radioGroupReactTest,+ play: cardPickerDroppedClickTest,});export const CardPickerPreact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-radio-group',runtime: 'preact',- play: createRadioGroupPreactTest({ optionName: 'Pro plan' }),+ play: cardPickerTest,});export const StatusControlsReact: Story = createGalleryStory({diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.mdindex 3ff373007b5..b7585abf176 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md@@ -8,9 +8,10 @@ file contains the metadata and named entries; `utils/` holds the story factory,shared assertions, render checks, interaction checks, and known-failure scenarios.Shared types and error patterns live in `types/` and `constants/`.`createGalleryRenderTest` checks the-exact set of expected failed components. `createSandboxFailureTest` distinguishes-mount failures from click failures; its error expectation requires at least one-error and can allow additional known errors without requiring them to occur.+exact set of expected failed components. `createSandboxFailureTest` mounts the+fixture, clicks a trigger and asserts the sandbox errors; its error expectation+requires at least one error and can allow additional known errors without+requiring them to occur.| Fixture | Components || --- | --- |@@ -50,24 +51,24 @@ No stories are skipped or marked as expected-to-fail by the runner.| Component | Current limitation || --- | --- || Field controls | Forwarded events lack the `nativeEvent` Base UI reads for `composedPath`. Textarea's cloned render element loses its change handler in React. The value report checks the state received by the component after typing. |-| Tabs | React cannot mount without `compareDocumentPosition`; Preact activation fails on the missing native event for `composedPath`. |-| RadioGroup | Ordering its radios needs `compareDocumentPosition`, which the sandbox DOM does not implement. |-| SegmentedControl | Ordering its radios needs `compareDocumentPosition`, so React cannot mount it. In the Preact input gallery it mounts and fails on first focus instead. Selecting would also need `PointerEvent` and native radio activation. |-| Popover, AlertDialog | Opening fails while reading unavailable viewport width data. |-| Menu, Select | Opening fails on viewport data and/or missing `nativeEvent.pointerType`. |-| Switch | Activation attempts to construct an unavailable `PointerEvent`. |+| Tabs | Activation fails on the missing `nativeEvent` for `composedPath` in both runtimes. |+| Popover, Dialog, AlertDialog | Opening fails while reading pointer contact data from the missing `nativeEvent`. |+| Menu, Select | Opening fails on the missing `nativeEvent.pointerType` and pointer contact data. |+| Switch, Checkbox, Radio, CardPicker, SegmentedControl | Activation attempts to construct an unavailable `PointerEvent`. `CardPickerReact` never gets that far: React drops the click handler Base UI adds through `React.cloneElement`, so only the group's focus handling fails on the missing `nativeEvent` for `composedPath`. |+| Slider | Thumbs stay hidden because the sandbox has no `ResizeObserver` to re-measure after the first geometry batch. || Tooltip | `TooltipReact` opens on hover but remains open after Escape because React drops the handlers Base UI adds through `React.cloneElement`. || Responsive hooks | The sandbox has no `window.matchMedia`, so `useIsMobile` and `useIsTouchDevice` return `false` whatever the host viewport or input. The fixture asserts that fallback and must assert host-derived values once a media-query bridge lands. |-The worker DOM now provides `Element.matches`, `closest`, `querySelector` backed-by `css-select`, and property accessors for boolean ARIA attributes so React and+The worker DOM now provides `Node.contains`, `compareDocumentPosition`,+`getRootNode`, `Element.matches`, `closest`, `querySelector` backed by+`css-select`, and property accessors for boolean ARIA attributes so React andPreact forward `true`/`false` instead of empty strings and remove the attributewhen the prop is cleared. `getAttribute` and the selector engine read the remoteproperties React and Preact set, and the selector engine matches the sandbox'scustom element tags by their HTML tag names. `TooltipPreact` therefore covers-hover opening and Escape dismissal. Pointer leave still needs the `Node.contains`-fix and document-level `mousemove` delivery for the safe polygon, and the-compound tooltip's title and description are not covered yet.+hover opening and Escape dismissal. Pointer leave still needs document-level+`mousemove` delivery for the safe polygon, and the compound tooltip's title and+description are not covered yet.Once the remaining gaps are fixed, extend the stories to verify selection,disabled items, keyboard navigation, and overlay content, dismissal, and focusdiff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/RadioActivationErrors.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/RadioActivationErrors.tsnew file mode 100644index 00000000000..d40ac7c1454--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/RadioActivationErrors.ts@@ -0,0 +1,7 @@+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { type SandboxErrorExpectation } from '@/__stories__/twenty-ui-gallery/types/SandboxErrorExpectation';++export const RADIO_ACTIVATION_ERRORS: SandboxErrorExpectation = {+ requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],+ allowedAdditionalErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],+};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.tsindex f7124eac03d..4365b8056d8 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS.ts@@ -1,6 +1,4 @@export const SANDBOX_ERROR_PATTERNS = {- DOCUMENT_POSITION:- /^(?:Uncaught TypeError: )?\w+\.compareDocumentPosition is not a function$/,COMPOSED_PATH:"Uncaught TypeError: Cannot use 'in' operator to search for 'composedPath' in undefined",VIEWPORT_WIDTH:@@ -14,6 +12,7 @@ export const SANDBOX_ERROR_PATTERNS = {HOST_EVENT_LISTENER: 'Uncaught TypeError: listener is not a function',ELEMENT_REF_FOCUS:/^(?:Uncaught TypeError: )?\w+\.current\?\.focus is not a function$/,+ ELEMENT_FOCUS: /^(?:Uncaught TypeError: )?\w+\?\.focus is not a function$/,POINTER_EVENT_CONSTRUCTOR:/^Uncaught TypeError: .+\.PointerEvent is not a constructor$/,};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SEGMENTED_CONTROL_ORDERING_ERROR.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SEGMENTED_CONTROL_ORDERING_ERROR.tsdeleted file mode 100644index ee394ad9508..00000000000--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/constants/SEGMENTED_CONTROL_ORDERING_ERROR.ts+++ /dev/null@@ -1,2 +0,0 @@-export const SEGMENTED_CONTROL_ORDERING_ERROR =- /SegmentedControl: \w+\.compareDocumentPosition is not a function(?: \| |$)/;diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerDroppedClickTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerDroppedClickTest.tsnew file mode 100644index 00000000000..eeadfa4a77f--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerDroppedClickTest.ts@@ -0,0 +1,9 @@+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { createRadioGroupTest } from '@/__stories__/twenty-ui-gallery/utils/createRadioGroupTest';++export const cardPickerDroppedClickTest = createRadioGroupTest({+ optionName: 'Pro plan',+ activationErrors: {+ requiredErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],+ },+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerTest.tsnew file mode 100644index 00000000000..70745bc4dd0--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardPickerTest.ts@@ -0,0 +1,7 @@+import { RADIO_ACTIVATION_ERRORS } from '@/__stories__/twenty-ui-gallery/constants/RadioActivationErrors';+import { createRadioGroupTest } from '@/__stories__/twenty-ui-gallery/utils/createRadioGroupTest';++export const cardPickerTest = createRadioGroupTest({+ optionName: 'Pro plan',+ activationErrors: RADIO_ACTIVATION_ERRORS,+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/checkboxTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/checkboxTest.tsnew file mode 100644index 00000000000..91825d3f50a--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/checkboxTest.ts@@ -0,0 +1,44 @@+import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';+import { expect, userEvent, within } from 'storybook/test';++export const checkboxTest: TwentyUiGalleryPlayFunction = async ({+ canvasElement,+}) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);++ const checkbox = canvas.getByRole('checkbox', { name: 'Select account' });+ const uncontrolled = canvas.getByRole('checkbox', {+ name: 'Uncontrolled selection',+ });+ expect(checkbox).not.toBeChecked();+ expect(uncontrolled).toBeChecked();+ expect(+ canvas.getByRole('checkbox', { name: 'Partial selection' }),+ ).toBePartiallyChecked();+ const disabled = canvas.getByRole('checkbox', {+ name: 'Disabled selection',+ });+ expect(disabled).toHaveAttribute('aria-disabled', 'true');+ await userEvent.click(disabled);+ expect(disabled).not.toBeChecked();++ const readOnly = canvas.getByRole('checkbox', {+ name: 'Read-only selection',+ });+ await userEvent.click(readOnly);+ expect(readOnly).toBeChecked();+ expect(errorHandler).not.toHaveBeenCalled();++ await userEvent.click(checkbox);+ await expectSandboxErrors({+ requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],+ });+ expect(canvas.getByRole('status')).toHaveTextContent(+ 'Selection: unselected; Changes: 0',+ );+};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/componentInteractionTests.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/componentInteractionTests.tsdeleted file mode 100644index b6f1195f0b3..00000000000--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/componentInteractionTests.ts+++ /dev/null@@ -1,181 +0,0 @@-import { expect, userEvent, waitFor, within } from 'storybook/test';--import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';-import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';-import {- INTERACTION_TIMEOUT,- TYPING_DELAY,-} from '@/__stories__/shared/test-utils/timeouts';-import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';-import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';-import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';--type CreateFieldControlsTestOptions = {- expectedReportedValues: string | RegExp;-};--export const checkboxTest: TwentyUiGalleryPlayFunction = async ({- canvasElement,-}) => {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);-- const checkbox = canvas.getByRole('checkbox', { name: 'Select account' });- const uncontrolled = canvas.getByRole('checkbox', {- name: 'Uncontrolled selection',- });- expect(checkbox).not.toBeChecked();- expect(uncontrolled).toBeChecked();- expect(- canvas.getByRole('checkbox', { name: 'Partial selection' }),- ).toBePartiallyChecked();- const disabled = canvas.getByRole('checkbox', {- name: 'Disabled selection',- });- expect(disabled).toHaveAttribute('aria-disabled', 'true');- await userEvent.click(disabled);- expect(disabled).not.toBeChecked();-- const readOnly = canvas.getByRole('checkbox', {- name: 'Read-only selection',- });- await userEvent.click(readOnly);- expect(readOnly).toBeChecked();- expect(errorHandler).not.toHaveBeenCalled();-- await userEvent.click(checkbox);- await expectSandboxErrors({- requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],- });- expect(canvas.getByRole('status')).toHaveTextContent(- 'Selection: unselected; Changes: 0',- );-};--export const createFieldControlsTest =- ({- expectedReportedValues,- }: CreateFieldControlsTestOptions): TwentyUiGalleryPlayFunction =>- async ({ canvasElement }) => {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);-- const email = canvas.getByRole('textbox', { name: 'Email' });- const notes = canvas.getByRole('textbox', { name: 'Notes' });-- expect(email).toHaveAccessibleDescription('Use your work email');- expect(- canvas.getByRole('textbox', { name: 'Required name' }),- ).toHaveAttribute('aria-invalid', 'true');- expect(canvas.getByText('Name is required')).toBeVisible();- expect(canvas.getByRole('textbox', { name: 'Reference' })).toHaveValue(- 'REF-42',- );- expect(canvas.getByText('Keep this reference')).toBeVisible();- expect(canvas.getByText('Reference cannot be changed')).toBeVisible();- expect(- canvas.getByRole('textbox', { name: 'Disabled input' }),- ).toBeDisabled();-- await userEvent.click(canvas.getByText('Email', { exact: true }));- await waitFor(() => expect(email).toHaveFocus());- await userEvent.type(email, 'alice', { delay: TYPING_DELAY });- await userEvent.type(notes, 'Follow up', { delay: TYPING_DELAY });- await userEvent.click(canvas.getByRole('button', { name: 'Read values' }));- await waitFor(() =>- expect(canvas.getByTestId('reported-values')).toHaveTextContent(- expectedReportedValues,- ),- );- await expectSandboxErrors({- requiredErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],- });- };--export const toastTest: TwentyUiGalleryPlayFunction = async ({- canvasElement,-}) => {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);-- expect(canvas.getByRole('status')).toHaveTextContent('Account saved');- expect(- canvas.getByText('Your changes are available to the team'),- ).toBeVisible();- await userEvent.click(canvas.getByRole('button', { name: 'Undo' }));- await waitFor(() =>- expect(- canvas.getByText('Notification: visible; Action: undone'),- ).toBeVisible(),- );- await userEvent.click(canvas.getByRole('button', { name: 'Cancel' }));- await waitFor(() =>- expect(- canvas.getByText('Notification: visible; Action: cancelled'),- ).toBeVisible(),- );- await userEvent.click(- canvas.getByRole('button', { name: 'Dismiss notification' }),- );- await waitFor(() =>- expect(canvas.queryByRole('status')).not.toBeInTheDocument(),- );- expect(- canvas.getByText('Notification: closed; Action: cancelled'),- ).toBeVisible();- expect(errorHandler).not.toHaveBeenCalled();-};--// Slider's synchronous layout measurements leave its thumbs hidden in the sandbox.-export const sliderTest: TwentyUiGalleryPlayFunction = async ({- canvasElement,-}) => {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);- const volume = within(canvas.getByRole('group', { name: 'Volume' }));- const slider = volume.getByRole('slider', { hidden: true });- expect(volume.getByRole('status')).toHaveTextContent('40');- expect(slider).toHaveValue('40');- const disabledVolume = within(- canvas.getByRole('group', { name: 'Disabled volume' }),- );- expect(disabledVolume.getByRole('slider', { hidden: true })).toBeDisabled();- await expect(- waitFor(() => expect(slider).toBeVisible(), {- timeout: INTERACTION_TIMEOUT,- }),- ).rejects.toThrow();- expect(canvas.getByText('Volume: 40; Committed: 40')).toBeVisible();- expect(errorHandler).not.toHaveBeenCalled();-};--type CreateRadioGroupPreactTestOptions = {- optionName: 'Daily' | 'Pro plan';-};--export const createRadioGroupPreactTest =- ({- optionName,- }: CreateRadioGroupPreactTestOptions): TwentyUiGalleryPlayFunction =>- async ({ canvasElement }) => {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);- expect(canvas.getByRole('radio', { name: 'Weekly' })).toBeChecked();- const disabled = canvas.getByRole('radio', { name: 'Monthly' });- expect(disabled).toHaveAttribute('aria-disabled', 'true');- await userEvent.click(disabled);- expect(disabled).not.toBeChecked();- expect(canvas.getByRole('radio', { name: 'Basic plan' })).toBeChecked();-- // Preact can report ordering and forwarded-event errors before PointerEvent fails.- await userEvent.click(canvas.getByRole('radio', { name: optionName }));- await expectSandboxErrors({- requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],- allowedAdditionalErrors: [- SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION,- SANDBOX_ERROR_PATTERNS.COMPOSED_PATH,- ],- });- expect(canvas.getByText('Frequency: weekly')).toBeVisible();- expect(canvas.getByText('Plan: basic')).toBeVisible();- };diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createFieldControlsTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createFieldControlsTest.tsnew file mode 100644index 00000000000..2ef009ee81f--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createFieldControlsTest.ts@@ -0,0 +1,50 @@+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { TYPING_DELAY } from '@/__stories__/shared/test-utils/timeouts';+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';+import { expect, userEvent, waitFor, within } from 'storybook/test';++type CreateFieldControlsTestOptions = {+ expectedReportedValues: string | RegExp;+};++export const createFieldControlsTest =+ ({+ expectedReportedValues,+ }: CreateFieldControlsTestOptions): TwentyUiGalleryPlayFunction =>+ async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);++ const email = canvas.getByRole('textbox', { name: 'Email' });+ const notes = canvas.getByRole('textbox', { name: 'Notes' });++ expect(email).toHaveAccessibleDescription('Use your work email');+ expect(+ canvas.getByRole('textbox', { name: 'Required name' }),+ ).toHaveAttribute('aria-invalid', 'true');+ expect(canvas.getByText('Name is required')).toBeVisible();+ expect(canvas.getByRole('textbox', { name: 'Reference' })).toHaveValue(+ 'REF-42',+ );+ expect(canvas.getByText('Keep this reference')).toBeVisible();+ expect(canvas.getByText('Reference cannot be changed')).toBeVisible();+ expect(+ canvas.getByRole('textbox', { name: 'Disabled input' }),+ ).toBeDisabled();++ await userEvent.click(canvas.getByText('Email', { exact: true }));+ await waitFor(() => expect(email).toHaveFocus());+ await userEvent.type(email, 'alice', { delay: TYPING_DELAY });+ await userEvent.type(notes, 'Follow up', { delay: TYPING_DELAY });+ await userEvent.click(canvas.getByRole('button', { name: 'Read values' }));+ await waitFor(() =>+ expect(canvas.getByTestId('reported-values')).toHaveTextContent(+ expectedReportedValues,+ ),+ );+ await expectSandboxErrors({+ requiredErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],+ });+ };diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createRadioGroupTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createRadioGroupTest.tsnew file mode 100644index 00000000000..4a794678e78--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createRadioGroupTest.ts@@ -0,0 +1,32 @@+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { type SandboxErrorExpectation } from '@/__stories__/twenty-ui-gallery/types/SandboxErrorExpectation';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';+import { expect, userEvent, within } from 'storybook/test';++type CreateRadioGroupTestOptions = {+ optionName: 'Daily' | 'Pro plan';+ activationErrors: SandboxErrorExpectation;+};++export const createRadioGroupTest =+ ({+ optionName,+ activationErrors,+ }: CreateRadioGroupTestOptions): TwentyUiGalleryPlayFunction =>+ async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);+ expect(canvas.getByRole('radio', { name: 'Weekly' })).toBeChecked();+ const disabled = canvas.getByRole('radio', { name: 'Monthly' });+ expect(disabled).toHaveAttribute('aria-disabled', 'true');+ await userEvent.click(disabled);+ expect(disabled).not.toBeChecked();+ expect(canvas.getByRole('radio', { name: 'Basic plan' })).toBeChecked();++ await userEvent.click(canvas.getByRole('radio', { name: optionName }));+ await expectSandboxErrors(activationErrors);++ expect(canvas.getByText('Frequency: weekly')).toBeVisible();+ expect(canvas.getByText('Plan: basic')).toBeVisible();+ };diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest.tsindex 4994770e39e..626ba21d3fc 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest.ts@@ -6,13 +6,10 @@ import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallerimport { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';type CreateSandboxFailureTestOptions = SandboxErrorExpectation & {- trigger:- | { type: 'mount' }- | {- type: 'click';- role: 'button' | 'combobox' | 'switch' | 'tab';- name: string;- };+ trigger: {+ role: 'button' | 'combobox' | 'switch' | 'tab';+ name: string;+ };};export const createSandboxFailureTest =@@ -22,13 +19,10 @@ export const createSandboxFailureTest =allowedAdditionalErrors,}: CreateSandboxFailureTestOptions): TwentyUiGalleryPlayFunction =>async ({ canvasElement }) => {- // Some failures prevent mounting; only interaction tests can await the card.- if (trigger.type === 'click') {- const canvas = within(canvasElement);- await expectFrontComponentMounted(canvas);- await userEvent.click(- canvas.getByRole(trigger.role, { name: trigger.name }),- );- }+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);+ await userEvent.click(+ canvas.getByRole(trigger.role, { name: trigger.name }),+ );await expectSandboxErrors({ requiredErrors, allowedAdditionalErrors });};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dialogTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dialogTest.tsindex 415e449f007..5ab56653dab 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dialogTest.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dialogTest.ts@@ -2,6 +2,6 @@ import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constantimport { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';export const dialogTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'button', name: 'Edit account' },+ trigger: { role: 'button', name: 'Edit account' },requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.tsindex 2955029e105..8d02748aa74 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/dropdownSandboxFailureTest.ts@@ -2,6 +2,6 @@ import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constantimport { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';export const dropdownSandboxFailureTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'button', name: 'Choose assignee' },+ trigger: { role: 'button', name: 'Choose assignee' },requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputPreactTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputPreactTest.tsdeleted file mode 100644index 220e84af83a..00000000000--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputPreactTest.ts+++ /dev/null@@ -1,40 +0,0 @@-import { expect, userEvent, waitFor, within } from 'storybook/test';--import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';-import { SEGMENTED_CONTROL_ORDERING_ERROR } from '@/__stories__/twenty-ui-gallery/constants/SEGMENTED_CONTROL_ORDERING_ERROR';-import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';-import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';-import { createGalleryRenderTest } from '@/__stories__/twenty-ui-gallery/utils/createGalleryRenderTest';--export const inputPreactTest: TwentyUiGalleryPlayFunction = async (context) => {- await createGalleryRenderTest({ expectedFailedComponents: ['RadioGroup'] })(- context,- );-- const canvas = within(context.canvasElement);-- await userEvent.click(- within(canvas.getByRole('radiogroup', { name: 'Choose' })).getByRole(- 'radio',- { name: 'Right' },- ),- );- await expectSandboxErrors({- requiredErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],- });- await waitFor(() => {- const status = canvas.getByTestId('gallery-status');-- expect(status).toHaveAttribute(- 'data-failed-names',- 'RadioGroup, SegmentedControl',- );- expect(status).toHaveAttribute(- 'data-failed-messages',- expect.stringMatching(SEGMENTED_CONTROL_ORDERING_ERROR),- );- });- await expect(- canvas.queryByRole('radiogroup', { name: 'Choose' }),- ).not.toBeInTheDocument();-};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputReactTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputReactTest.tsdeleted file mode 100644index 56e7f895dff..00000000000--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputReactTest.ts+++ /dev/null@@ -1,18 +0,0 @@-import { expect, within } from 'storybook/test';--import { SEGMENTED_CONTROL_ORDERING_ERROR } from '@/__stories__/twenty-ui-gallery/constants/SEGMENTED_CONTROL_ORDERING_ERROR';-import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';-import { createGalleryRenderTest } from '@/__stories__/twenty-ui-gallery/utils/createGalleryRenderTest';--export const inputReactTest: TwentyUiGalleryPlayFunction = async (context) => {- await createGalleryRenderTest({- expectedFailedComponents: ['RadioGroup', 'SegmentedControl'],- })(context);-- expect(- within(context.canvasElement).getByTestId('gallery-status'),- ).toHaveAttribute(- 'data-failed-messages',- expect.stringMatching(SEGMENTED_CONTROL_ORDERING_ERROR),- );-};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputTest.tsnew file mode 100644index 00000000000..65bf09f2a57--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/inputTest.ts@@ -0,0 +1,24 @@+import { expect, userEvent, within } from 'storybook/test';++import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expectSandboxErrors } from '@/__stories__/twenty-ui-gallery/utils/expectSandboxErrors';+import { galleryRenderTest } from '@/__stories__/twenty-ui-gallery/utils/galleryRenderTests';++export const inputTest: TwentyUiGalleryPlayFunction = async (context) => {+ await galleryRenderTest(context);++ const canvas = within(context.canvasElement);++ await userEvent.click(+ within(canvas.getByRole('radiogroup', { name: 'Choose' })).getByRole(+ 'radio',+ { name: 'Right' },+ ),+ );+ await expectSandboxErrors({+ requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],+ allowedAdditionalErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],+ });+ expect(canvas.getByRole('radiogroup', { name: 'Choose' })).toBeVisible();+};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.tsnew file mode 100644index 00000000000..340d02d45b9--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts@@ -0,0 +1,7 @@+import { RADIO_ACTIVATION_ERRORS } from '@/__stories__/twenty-ui-gallery/constants/RadioActivationErrors';+import { createRadioGroupTest } from '@/__stories__/twenty-ui-gallery/utils/createRadioGroupTest';++export const radioGroupTest = createRadioGroupTest({+ optionName: 'Daily',+ activationErrors: RADIO_ACTIVATION_ERRORS,+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sandboxFailureTests.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sandboxFailureTests.tsindex dbabb252bbf..a90c510a686 100644--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sandboxFailureTests.ts+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sandboxFailureTests.ts@@ -1,62 +1,44 @@import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';import { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';-// React cannot mount Tabs without compareDocumentPosition; Preact activation-// expects nativeEvent.composedPath, which the forwarded event lacks.-export const tabsReactTest = createSandboxFailureTest({- trigger: { type: 'mount' },- requiredErrors: [SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION],-});-export const tabsPreactTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'tab', name: 'Activity' },+// Tab activation expects nativeEvent.composedPath, which the forwarded event lacks.+export const tabsTest = createSandboxFailureTest({+ trigger: { role: 'tab', name: 'Activity' },requiredErrors: [SANDBOX_ERROR_PATTERNS.COMPOSED_PATH],- allowedAdditionalErrors: [SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION],});-// Opening the popover requires viewport data absent from the sandbox.+// Opening the popover reads pointer contact data from the missing nativeEvent.export const popoverTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'button', name: 'Account details' },+ trigger: { role: 'button', name: 'Account details' },requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],});-// Menu opening lacks viewport data and nativeEvent.pointerType.+// Menu opening reads nativeEvent.pointerType and pointer contact data.export const menuTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'button', name: 'Account actions' },+ trigger: { role: 'button', name: 'Account actions' },requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_TYPE],allowedAdditionalErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],});-// Select opening lacks viewport data and nativeEvent.pointerType.+// Select opening reads nativeEvent.pointerType and pointer contact data.export const selectTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'combobox', name: 'Account stage' },+ trigger: { role: 'combobox', name: 'Account stage' },requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_TYPE],allowedAdditionalErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH,SANDBOX_ERROR_PATTERNS.COMPOSED_PATH,- SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION,+ SANDBOX_ERROR_PATTERNS.ELEMENT_FOCUS,],});-// Opening the alert dialog requires viewport data absent from the sandbox.+// Opening the alert dialog reads pointer contact data from the missing nativeEvent.export const alertDialogTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'button', name: 'Delete account' },+ trigger: { role: 'button', name: 'Delete account' },requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],});// Switch activation constructs a PointerEvent, which the sandbox lacks.export const switchTest = createSandboxFailureTest({- trigger: { type: 'click', role: 'switch', name: 'Email notifications' },+ trigger: { role: 'switch', name: 'Email notifications' },requiredErrors: [SANDBOX_ERROR_PATTERNS.POINTER_EVENT_CONSTRUCTOR],});--// Ordering range slider thumbs requires compareDocumentPosition in both runtimes.-export const sliderRangeTest = createSandboxFailureTest({- trigger: { type: 'mount' },- requiredErrors: [SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION],-});--// React orders radio group descendants with compareDocumentPosition.-export const radioGroupReactTest = createSandboxFailureTest({- trigger: { type: 'mount' },- requiredErrors: [SANDBOX_ERROR_PATTERNS.DOCUMENT_POSITION],-});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderRangeTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderRangeTest.tsnew file mode 100644index 00000000000..8db5c6e0145--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderRangeTest.ts@@ -0,0 +1,22 @@+import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expect, within } from 'storybook/test';++export const sliderRangeTest: TwentyUiGalleryPlayFunction = async ({+ canvasElement,+}) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);+ const priceRange = within(canvas.getByRole('group', { name: 'Price range' }));+ const [minimumThumb, maximumThumb] = priceRange.getAllByRole('slider', {+ hidden: true,+ });++ expect(minimumThumb).toHaveAttribute('aria-label', 'Minimum price');+ expect(minimumThumb).toHaveValue('20');+ expect(maximumThumb).toHaveAttribute('aria-label', 'Maximum price');+ expect(maximumThumb).toHaveValue('80');+ expect(priceRange.getByRole('status')).toHaveTextContent('20 – 80');+ expect(errorHandler).not.toHaveBeenCalled();+};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderTest.tsnew file mode 100644index 00000000000..6a2775da679--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/sliderTest.ts@@ -0,0 +1,27 @@+import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { INTERACTION_TIMEOUT } from '@/__stories__/shared/test-utils/timeouts';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expect, waitFor, within } from 'storybook/test';++export const sliderTest: TwentyUiGalleryPlayFunction = async ({+ canvasElement,+}) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);+ const volume = within(canvas.getByRole('group', { name: 'Volume' }));+ const slider = volume.getByRole('slider', { hidden: true });+ expect(volume.getByRole('status')).toHaveTextContent('40');+ expect(slider).toHaveValue('40');+ const disabledVolume = within(+ canvas.getByRole('group', { name: 'Disabled volume' }),+ );+ expect(disabledVolume.getByRole('slider', { hidden: true })).toBeDisabled();+ await expect(+ waitFor(() => expect(slider).toBeVisible(), {+ timeout: INTERACTION_TIMEOUT,+ }),+ ).rejects.toThrow();+ expect(canvas.getByText('Volume: 40; Committed: 40')).toBeVisible();+ expect(errorHandler).not.toHaveBeenCalled();+};diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/toastTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/toastTest.tsnew file mode 100644index 00000000000..7b39dfa749f--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/toastTest.ts@@ -0,0 +1,38 @@+import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { expect, userEvent, waitFor, within } from 'storybook/test';++export const toastTest: TwentyUiGalleryPlayFunction = async ({+ canvasElement,+}) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);++ expect(canvas.getByRole('status')).toHaveTextContent('Account saved');+ expect(+ canvas.getByText('Your changes are available to the team'),+ ).toBeVisible();+ await userEvent.click(canvas.getByRole('button', { name: 'Undo' }));+ await waitFor(() =>+ expect(+ canvas.getByText('Notification: visible; Action: undone'),+ ).toBeVisible(),+ );+ await userEvent.click(canvas.getByRole('button', { name: 'Cancel' }));+ await waitFor(() =>+ expect(+ canvas.getByText('Notification: visible; Action: cancelled'),+ ).toBeVisible(),+ );+ await userEvent.click(+ canvas.getByRole('button', { name: 'Dismiss notification' }),+ );+ await waitFor(() =>+ expect(canvas.queryByRole('status')).not.toBeInTheDocument(),+ );+ expect(+ canvas.getByText('Notification: closed; Action: cancelled'),+ ).toBeVisible();+ expect(errorHandler).not.toHaveBeenCalled();+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/constants/DocumentPositionFlagByName.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/constants/DocumentPositionFlagByName.tsnew file mode 100644index 00000000000..7c7d7863eb9--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/constants/DocumentPositionFlagByName.ts@@ -0,0 +1,8 @@+export const DOCUMENT_POSITION_FLAG_BY_NAME = {+ DISCONNECTED: 1,+ PRECEDING: 2,+ FOLLOWING: 4,+ CONTAINS: 8,+ CONTAINED_BY: 16,+ IMPLEMENTATION_SPECIFIC: 32,+} as const;diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installCompareDocumentPositionPolyfill.test.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installCompareDocumentPositionPolyfill.test.tsnew file mode 100644index 00000000000..6bba53e6db2--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installCompareDocumentPositionPolyfill.test.ts@@ -0,0 +1,188 @@+import { Window } from '@remote-dom/polyfill';++import { installCompareDocumentPositionPolyfill } from '../installCompareDocumentPositionPolyfill';++type PolyfillNodeConstructor = typeof Node;++const createPolyfillDocument = (): {+ document: Document;+ nodeConstructor: PolyfillNodeConstructor;+} => {+ const polyfillWindow = new Window();+ const nodeConstructor =+ polyfillWindow.Node as unknown as PolyfillNodeConstructor;++ installCompareDocumentPositionPolyfill({+ nodeConstructor,+ nodePrototype: nodeConstructor.prototype,+ });++ return {+ document: polyfillWindow.document as unknown as Document,+ nodeConstructor,+ };+};++describe('installCompareDocumentPositionPolyfill', () => {+ it('should expose the DOCUMENT_POSITION constants on the constructor and on nodes', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const element = document.createElement('div');++ expect(nodeConstructor.DOCUMENT_POSITION_DISCONNECTED).toBe(1);+ expect(nodeConstructor.DOCUMENT_POSITION_PRECEDING).toBe(2);+ expect(nodeConstructor.DOCUMENT_POSITION_FOLLOWING).toBe(4);+ expect(nodeConstructor.DOCUMENT_POSITION_CONTAINS).toBe(8);+ expect(nodeConstructor.DOCUMENT_POSITION_CONTAINED_BY).toBe(16);+ expect(nodeConstructor.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC).toBe(32);+ expect(element.DOCUMENT_POSITION_FOLLOWING).toBe(4);+ });++ it('should return 0 for the same node', () => {+ const { document } = createPolyfillDocument();+ const element = document.createElement('div');++ expect(element.compareDocumentPosition(element)).toBe(0);+ });++ it('should throw a TypeError when the argument is not a node', () => {+ const { document } = createPolyfillDocument();+ const element = document.createElement('div');++ expect(() =>+ element.compareDocumentPosition(null as unknown as Node),+ ).toThrow(TypeError);+ expect(() => element.compareDocumentPosition({} as Node)).toThrow(+ TypeError,+ );+ expect(() =>+ element.compareDocumentPosition({ parentNode: null } as unknown as Node),+ ).toThrow(TypeError);+ });++ it('should keep disconnected ordering stable and reverse it when arguments reverse', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const first = document.createElement('div');+ const second = document.createElement('div');++ const firstComparison = first.compareDocumentPosition(second);+ const reverseComparison = second.compareDocumentPosition(first);+ const disconnectedFlags =+ nodeConstructor.DOCUMENT_POSITION_DISCONNECTED |+ nodeConstructor.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;++ expect(firstComparison & disconnectedFlags).toBe(disconnectedFlags);+ expect(reverseComparison & disconnectedFlags).toBe(disconnectedFlags);+ expect(+ Boolean(firstComparison & nodeConstructor.DOCUMENT_POSITION_PRECEDING),+ ).toBe(+ Boolean(reverseComparison & nodeConstructor.DOCUMENT_POSITION_FOLLOWING),+ );+ expect(first.compareDocumentPosition(second)).toBe(firstComparison);+ });++ it('should order disconnected trees consistently regardless of which descendants are compared', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const roots = ['div', 'section', 'p'].map((tag) =>+ document.createElement(tag),+ );+ const children = roots.map((root) => {+ const child = document.createElement('span');+ root.append(child);+ return child;+ });+ const [first, second, third] = roots;+ const direction = first.compareDocumentPosition(second);++ expect(children[0].compareDocumentPosition(children[1])).toBe(direction);+ expect(children[1].compareDocumentPosition(third)).toBe(+ nodeConstructor.DOCUMENT_POSITION_DISCONNECTED |+ nodeConstructor.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |+ nodeConstructor.DOCUMENT_POSITION_FOLLOWING,+ );+ expect(first.compareDocumentPosition(third)).toBe(+ second.compareDocumentPosition(third),+ );+ });++ it('should report an ancestor as containing and preceding', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const ancestor = document.createElement('div');+ const intermediate = document.createElement('section');+ const descendant = document.createElement('span');++ ancestor.append(intermediate);+ intermediate.append(descendant);++ expect(descendant.compareDocumentPosition(ancestor)).toBe(+ nodeConstructor.DOCUMENT_POSITION_CONTAINS |+ nodeConstructor.DOCUMENT_POSITION_PRECEDING,+ );+ });++ it('should report a descendant as contained by and following', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const ancestor = document.createElement('div');+ const intermediate = document.createElement('section');+ const descendant = document.createElement('span');++ ancestor.append(intermediate);+ intermediate.append(descendant);++ expect(ancestor.compareDocumentPosition(descendant)).toBe(+ nodeConstructor.DOCUMENT_POSITION_CONTAINED_BY |+ nodeConstructor.DOCUMENT_POSITION_FOLLOWING,+ );+ });++ it('should order siblings and cousins by document order', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const root = document.createElement('div');+ const firstBranch = document.createElement('section');+ const secondBranch = document.createElement('section');+ const firstLeaf = document.createElement('span');+ const secondLeaf = document.createElement('span');++ root.append(firstBranch, secondBranch);+ firstBranch.append(firstLeaf);+ secondBranch.append(secondLeaf);++ expect(firstBranch.compareDocumentPosition(secondBranch)).toBe(+ nodeConstructor.DOCUMENT_POSITION_FOLLOWING,+ );+ expect(secondBranch.compareDocumentPosition(firstBranch)).toBe(+ nodeConstructor.DOCUMENT_POSITION_PRECEDING,+ );+ expect(firstLeaf.compareDocumentPosition(secondLeaf)).toBe(+ nodeConstructor.DOCUMENT_POSITION_FOLLOWING,+ );+ expect(secondLeaf.compareDocumentPosition(firstBranch)).toBe(+ nodeConstructor.DOCUMENT_POSITION_PRECEDING,+ );+ });++ it('should sort elements into document order with the Base UI comparator', () => {+ const { document, nodeConstructor } = createPolyfillDocument();+ const list = document.createElement('div');+ const tabs = ['first', 'second', 'third'].map((label) => {+ const tab = document.createElement('button');+ tab.setAttribute('data-label', label);+ list.append(tab);++ return tab;+ });+ document.body.append(list);++ const sorted = [tabs[2], tabs[0], tabs[1]].sort((first, second) =>+ first.compareDocumentPosition(second) &+ nodeConstructor.DOCUMENT_POSITION_FOLLOWING+ ? -1+ : 1,+ );++ expect(sorted.map((tab) => tab.getAttribute('data-label'))).toEqual([+ 'first',+ 'second',+ 'third',+ ]);+ });+});diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installGetRootNodePolyfill.test.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installGetRootNodePolyfill.test.tsnew file mode 100644index 00000000000..43b4d4ddf76--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installGetRootNodePolyfill.test.ts@@ -0,0 +1,41 @@+import { Window } from '@remote-dom/polyfill';++import { installGetRootNodePolyfill } from '../installGetRootNodePolyfill';++const createPolyfillDocument = (): Document => {+ const polyfillWindow = new Window();++ installGetRootNodePolyfill(polyfillWindow.Node.prototype);++ return polyfillWindow.document as unknown as Document;+};++describe('installGetRootNodePolyfill', () => {+ it('should return the document for a connected node', () => {+ const document = createPolyfillDocument();+ const element = document.createElement('div');+ const nested = document.createElement('span');++ element.append(nested);+ document.body.append(element);++ expect(nested.getRootNode()).toBe(document);+ });++ it('should return the topmost detached ancestor for a detached subtree', () => {+ const document = createPolyfillDocument();+ const root = document.createElement('div');+ const nested = document.createElement('span');++ root.append(nested);++ expect(nested.getRootNode()).toBe(root);+ });++ it('should return the node itself when it has no parent', () => {+ const document = createPolyfillDocument();+ const element = document.createElement('div');++ expect(element.getRootNode()).toBe(element);+ });+});diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installNodeContainsPolyfill.test.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installNodeContainsPolyfill.test.tsnew file mode 100644index 00000000000..61b1f5fdfca--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/installNodeContainsPolyfill.test.ts@@ -0,0 +1,94 @@+import { Window } from '@remote-dom/polyfill';++import { installNodeContainsPolyfill } from '../installNodeContainsPolyfill';++const createPolyfillDocument = (): Document => {+ const polyfillWindow = new Window();++ installNodeContainsPolyfill(polyfillWindow.Node.prototype);++ return polyfillWindow.document as unknown as Document;+};++describe('installNodeContainsPolyfill', () => {+ it('should return true for the node itself', () => {+ const document = createPolyfillDocument();+ const element = document.createElement('div');++ expect(element.contains(element)).toBe(true);+ });++ it('should return true for a direct child', () => {+ const document = createPolyfillDocument();+ const parent = document.createElement('div');+ const child = document.createElement('span');++ parent.append(child);++ expect(parent.contains(child)).toBe(true);+ });++ it('should return true for an indirect descendant', () => {+ const document = createPolyfillDocument();+ const ancestor = document.createElement('div');+ const intermediate = document.createElement('section');+ const descendant = document.createElement('span');++ ancestor.append(intermediate);+ intermediate.append(descendant);++ expect(ancestor.contains(descendant)).toBe(true);+ });++ it('should return true for a text node nested in the subtree', () => {+ const document = createPolyfillDocument();+ const ancestor = document.createElement('div');+ const paragraph = document.createElement('p');+ const text = document.createTextNode('hello');++ ancestor.append(paragraph);+ paragraph.append(text);++ expect(ancestor.contains(text)).toBe(true);+ });++ it('should return false for an ancestor', () => {+ const document = createPolyfillDocument();+ const parent = document.createElement('div');+ const child = document.createElement('span');++ parent.append(child);++ expect(child.contains(parent)).toBe(false);+ });++ it('should return false for a sibling subtree', () => {+ const document = createPolyfillDocument();+ const root = document.createElement('div');+ const left = document.createElement('div');+ const right = document.createElement('div');+ const rightChild = document.createElement('span');++ root.append(left, right);+ right.append(rightChild);++ expect(left.contains(rightChild)).toBe(false);+ });++ it('should return false for a detached node', () => {+ const document = createPolyfillDocument();++ expect(+ document.createElement('div').contains(document.createElement('span')),+ ).toBe(false);+ });++ it('should return false for nullish and non-node arguments', () => {+ const document = createPolyfillDocument();+ const element = document.createElement('div');++ expect(element.contains(null)).toBe(false);+ expect(element.contains(undefined as unknown as Node)).toBe(false);+ expect(element.contains({} as Node)).toBe(false);+ });+});diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/remoteDomPolyfillHooksContract.test.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/remoteDomPolyfillHooksContract.test.tsindex 4aa65aca30b..1ae6ec076c3 100644--- a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/remoteDomPolyfillHooksContract.test.ts+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/__tests__/remoteDomPolyfillHooksContract.test.ts@@ -133,6 +133,8 @@ describe('@remote-dom/polyfill mutation hooks contract the worker MutationObserv});it.each([+ ['Node', 'compareDocumentPosition'],+ ['Node', 'getRootNode'],['Element', 'closest'],['Element', 'matches'],])(@@ -149,6 +151,14 @@ describe('@remote-dom/polyfill mutation hooks contract the worker MutationObserv},);+ it('still ships the Node.contains walk that re-reads the argument parent, which the worker replaces', () => {+ const polyfillWindow = new Window();++ expect(String(polyfillWindow.Node.prototype.contains)).toContain(+ 'node.parentNode',+ );+ });+it('still throws on pseudo-class selectors, which the worker selector engine replaces', () => {const polyfillWindow = new Window();const { document } = polyfillWindow;diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/collectAncestorChainFromRootToNode.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/collectAncestorChainFromRootToNode.tsnew file mode 100644index 00000000000..5ec6e8654c0--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/collectAncestorChainFromRootToNode.ts@@ -0,0 +1,15 @@+import { isObject } from '@sniptt/guards';++import { type NodeLike } from '@/polyfills/dom/types/NodeLike';++export const collectAncestorChainFromRootToNode = (node: unknown): object[] => {+ const ancestorChain: object[] = [];+ let currentNode: unknown = node;++ while (isObject(currentNode)) {+ ancestorChain.push(currentNode);+ currentNode = (currentNode as NodeLike).parentNode;+ }++ return ancestorChain.reverse();+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/compareDocumentPosition.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/compareDocumentPosition.tsnew file mode 100644index 00000000000..c225d6afd9c--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/compareDocumentPosition.ts@@ -0,0 +1,79 @@+import { isObject } from '@sniptt/guards';++import { DOCUMENT_POSITION_FLAG_BY_NAME } from '@/polyfills/dom/constants/DocumentPositionFlagByName';+import { collectAncestorChainFromRootToNode } from '@/polyfills/dom/utils/collectAncestorChainFromRootToNode';+import { findFirstDivergingAncestorIndex } from '@/polyfills/dom/utils/findFirstDivergingAncestorIndex';+import { resolveChildNodeIndexInParent } from '@/polyfills/dom/utils/resolveChildNodeIndexInParent';++const NON_NODE_ARGUMENT_ERROR_MESSAGE =+ "Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.";++export const compareDocumentPosition = ({+ node,+ otherNode,+ nodePrototype,+ resolveDisconnectedRootOrder,+}: {+ node: object;+ otherNode: unknown;+ nodePrototype: object;+ resolveDisconnectedRootOrder: (root: object) => number;+}): number => {+ if (!isObject(otherNode) || !nodePrototype.isPrototypeOf(otherNode)) {+ throw new TypeError(NON_NODE_ARGUMENT_ERROR_MESSAGE);+ }++ if (otherNode === node) {+ return 0;+ }++ const thisChain = collectAncestorChainFromRootToNode(node);+ const otherChain = collectAncestorChainFromRootToNode(otherNode);++ if (thisChain[0] !== otherChain[0]) {+ const doesOtherRootPrecedeThisRoot =+ resolveDisconnectedRootOrder(otherChain[0]) <+ resolveDisconnectedRootOrder(thisChain[0]);++ return (+ DOCUMENT_POSITION_FLAG_BY_NAME.DISCONNECTED |+ DOCUMENT_POSITION_FLAG_BY_NAME.IMPLEMENTATION_SPECIFIC |+ (doesOtherRootPrecedeThisRoot+ ? DOCUMENT_POSITION_FLAG_BY_NAME.PRECEDING+ : DOCUMENT_POSITION_FLAG_BY_NAME.FOLLOWING)+ );+ }++ const divergenceIndex = findFirstDivergingAncestorIndex({+ firstChain: thisChain,+ secondChain: otherChain,+ });++ if (divergenceIndex === otherChain.length) {+ return (+ DOCUMENT_POSITION_FLAG_BY_NAME.CONTAINS |+ DOCUMENT_POSITION_FLAG_BY_NAME.PRECEDING+ );+ }++ if (divergenceIndex === thisChain.length) {+ return (+ DOCUMENT_POSITION_FLAG_BY_NAME.CONTAINED_BY |+ DOCUMENT_POSITION_FLAG_BY_NAME.FOLLOWING+ );+ }++ const commonParent = thisChain[divergenceIndex - 1];+ const thisBranchIndex = resolveChildNodeIndexInParent({+ parent: commonParent,+ child: thisChain[divergenceIndex],+ });+ const otherBranchIndex = resolveChildNodeIndexInParent({+ parent: commonParent,+ child: otherChain[divergenceIndex],+ });++ return otherBranchIndex < thisBranchIndex+ ? DOCUMENT_POSITION_FLAG_BY_NAME.PRECEDING+ : DOCUMENT_POSITION_FLAG_BY_NAME.FOLLOWING;+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/createDisconnectedRootOrderResolver.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/createDisconnectedRootOrderResolver.tsnew file mode 100644index 00000000000..fca3a080f5c--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/createDisconnectedRootOrderResolver.ts@@ -0,0 +1,25 @@+import { isDefined } from 'twenty-shared/utils';++export const createDisconnectedRootOrderResolver = (): ((+ root: object,+) => number) => {+ const orderByDisconnectedRoot = new WeakMap<object, number>();+ let nextDisconnectedRootOrder = 0;++ const resolveDisconnectedRootOrder = (root: object): number => {+ const existingOrder = orderByDisconnectedRoot.get(root);++ if (isDefined(existingOrder)) {+ return existingOrder;+ }++ const order = nextDisconnectedRootOrder;++ nextDisconnectedRootOrder += 1;+ orderByDisconnectedRoot.set(root, order);++ return order;+ };++ return resolveDisconnectedRootOrder;+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/findFirstDivergingAncestorIndex.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/findFirstDivergingAncestorIndex.tsnew file mode 100644index 00000000000..b32990019d6--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/findFirstDivergingAncestorIndex.ts@@ -0,0 +1,19 @@+export const findFirstDivergingAncestorIndex = ({+ firstChain,+ secondChain,+}: {+ firstChain: object[];+ secondChain: object[];+}): number => {+ let index = 0;++ while (+ index < firstChain.length &&+ index < secondChain.length &&+ firstChain[index] === secondChain[index]+ ) {+ index += 1;+ }++ return index;+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installCompareDocumentPositionPolyfill.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installCompareDocumentPositionPolyfill.tsnew file mode 100644index 00000000000..1219f696653--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installCompareDocumentPositionPolyfill.ts@@ -0,0 +1,39 @@+import { DOCUMENT_POSITION_FLAG_BY_NAME } from '@/polyfills/dom/constants/DocumentPositionFlagByName';+import { compareDocumentPosition } from '@/polyfills/dom/utils/compareDocumentPosition';+import { createDisconnectedRootOrderResolver } from '@/polyfills/dom/utils/createDisconnectedRootOrderResolver';+import { definePolyfillMethod } from '@/polyfills/utils/definePolyfillMethod';++type InstallCompareDocumentPositionPolyfillInput = {+ nodeConstructor: object;+ nodePrototype: object;+};++export const installCompareDocumentPositionPolyfill = ({+ nodeConstructor,+ nodePrototype,+}: InstallCompareDocumentPositionPolyfillInput): void => {+ const resolveDisconnectedRootOrder = createDisconnectedRootOrderResolver();++ for (const [flagName, flagValue] of Object.entries(+ DOCUMENT_POSITION_FLAG_BY_NAME,+ )) {+ for (const target of [nodeConstructor, nodePrototype]) {+ Object.defineProperty(target, `DOCUMENT_POSITION_${flagName}`, {+ value: flagValue,+ configurable: true,+ });+ }+ }++ definePolyfillMethod({+ target: nodePrototype,+ methodName: 'compareDocumentPosition',+ method: (node, otherNode) =>+ compareDocumentPosition({+ node,+ otherNode,+ nodePrototype,+ resolveDisconnectedRootOrder,+ }),+ });+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installGetRootNodePolyfill.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installGetRootNodePolyfill.tsnew file mode 100644index 00000000000..d98ba88abd8--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installGetRootNodePolyfill.ts@@ -0,0 +1,11 @@+import { collectAncestorChainFromRootToNode } from '@/polyfills/dom/utils/collectAncestorChainFromRootToNode';+import { definePolyfillMethod } from '@/polyfills/utils/definePolyfillMethod';++export const installGetRootNodePolyfill = (nodePrototype: object): void => {+ definePolyfillMethod({+ target: nodePrototype,+ methodName: 'getRootNode',+ method: (node: object): object =>+ collectAncestorChainFromRootToNode(node)[0] ?? node,+ });+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installNodeContainsPolyfill.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installNodeContainsPolyfill.tsnew file mode 100644index 00000000000..b8138cac7a3--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/installNodeContainsPolyfill.ts@@ -0,0 +1,11 @@+import { isAncestorOrSelfOfNode } from '@/polyfills/dom/utils/isAncestorOrSelfOfNode';+import { definePolyfillMethod } from '@/polyfills/utils/definePolyfillMethod';++export const installNodeContainsPolyfill = (nodePrototype: object): void => {+ definePolyfillMethod({+ target: nodePrototype,+ methodName: 'contains',+ method: (node: object, otherNode: unknown): boolean =>+ isAncestorOrSelfOfNode(node, otherNode),+ });+};diff --git a/packages/twenty-front-component-renderer/src/polyfills/dom/utils/resolveChildNodeIndexInParent.ts b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/resolveChildNodeIndexInParent.tsnew file mode 100644index 00000000000..fafe3c67a75--- /dev/null+++ b/packages/twenty-front-component-renderer/src/polyfills/dom/utils/resolveChildNodeIndexInParent.ts@@ -0,0 +1,19 @@+import { isDefined } from 'twenty-shared/utils';++type NodeWithChildNodes = {+ childNodes?: ArrayLike<unknown>;+};++export const resolveChildNodeIndexInParent = ({+ parent,+ child,+}: {+ parent: object;+ child: object;+}): number => {+ const childNodes = (parent as NodeWithChildNodes).childNodes;++ return isDefined(childNodes)+ ? Array.prototype.indexOf.call(childNodes, child)+ : -1;+};diff --git a/packages/twenty-front-component-renderer/src/remote/worker/remote-worker.ts b/packages/twenty-front-component-renderer/src/remote/worker/remote-worker.tsindex f18045a2558..d51148553a8 100644--- a/packages/twenty-front-component-renderer/src/remote/worker/remote-worker.ts+++ b/packages/twenty-front-component-renderer/src/remote/worker/remote-worker.ts@@ -11,11 +11,14 @@ import { frontComponentHostCommunicationApi } from '@/remote/worker/thread/stateimport { HTML_TAG_TO_CUSTOM_ELEMENT_TAG } from '@/constants/HtmlTagToCustomElementTag';import { installClipboardPolyfill } from '@/polyfills/clipboard/utils/installClipboardPolyfill';import { installClassAttributeAccessors } from '@/polyfills/dom/utils/installClassAttributeAccessors';+import { installCompareDocumentPositionPolyfill } from '@/polyfills/dom/utils/installCompareDocumentPositionPolyfill';import { installDocumentGetElementById } from '@/polyfills/dom/utils/installDocumentGetElementById';import { installGetComputedStyle } from '@/polyfills/dom/utils/installGetComputedStyle';import { installGetElementsByClassName } from '@/polyfills/dom/utils/installGetElementsByClassName';+import { installGetRootNodePolyfill } from '@/polyfills/dom/utils/installGetRootNodePolyfill';import { installLocalStyleOnBaseElements } from '@/polyfills/dom/utils/installLocalStyleOnBaseElements';import { installMutationObserver } from '@/polyfills/dom/utils/installMutationObserver';+import { installNodeContainsPolyfill } from '@/polyfills/dom/utils/installNodeContainsPolyfill';import { installSelectorMethodsPolyfill } from '@/polyfills/selectors/utils/installSelectorMethodsPolyfill';import { workerGeometryStore } from '@/polyfills/geometry/states/workerGeometryStore';import { installElementGeometryPolyfill } from '@/polyfills/geometry/utils/installElementGeometryPolyfill';@@ -55,6 +58,12 @@ installClassAttributeAccessors({});installLocalStyleOnBaseElements(Element.prototype);+installNodeContainsPolyfill(Node.prototype);+installCompareDocumentPositionPolyfill({+ nodeConstructor: Node,+ nodePrototype: Node.prototype,+});+installGetRootNodePolyfill(Node.prototype);installSelectorMethodsPolyfill({elementPrototype: Element.prototype,querySelectorTargets: [