Skip to content

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Sep 26, 2025

Dynamically importing the test suites causes fake timers to advance in non-deterministic way. Instead we can just import them statically, setupFakeClock is already being called when its module loads, so no need to wrap an async import with it.

Also noticed this weird component that attempts to set up fake timers in an effect, but would absolutely not work as intended as soon as ready is true. Don't understand what it's for really, but I corrected the implementation at the local level, it's now correctly updating the fake clock whenever shouldAdvanceTime changes.

I'm also including a optimizedeps plugin that fixes the jsx in .js files. True vite dev mode for this app still doesn't work due to CJS/ESM issues with the markdown loader. Still to investigate further, but already including this step.

The screenshot is changing to ...:53, this is the correct value. The one on master is from when timers advanced a bit in unpredictable way.

@Janpot Janpot added type: bug It doesn't behave as expected. test scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). labels Sep 26, 2025
@mui-bot
Copy link

mui-bot commented Sep 26, 2025

Deploy preview: https://deploy-preview-19719--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against b2f6872

@bernardobelchior
Copy link
Member

The flaky visual test seems to return the seconds as 53 and sometimes as 54. Why do you think it's related to toLocaleString()? At first sight, the cause doesn't seem to be a formatting difference.

Could it be some fake timer (or the lack of a fake timer) and a test that runs more slowly in some cases, thus resulting in a different second?

@Janpot
Copy link
Member Author

Janpot commented Sep 29, 2025

The flaky visual test seems to return the seconds as 53 and sometimes as 54. Why do you think it's related to toLocaleString()? At first sight, the cause doesn't seem to be a formatting difference.

The exact timestamp that is being visualized is 1408345913500, which has exactly 500 as its milliseconds part. I read that some older runtimes truncate instead of rounding. But I'm not sure that's what's at play here

@JCQuintas
Copy link
Member

The flaky visual test seems to return the seconds as 53 and sometimes as 54. Why do you think it's related to toLocaleString()? At first sight, the cause doesn't seem to be a formatting difference.

The exact timestamp that is being visualized is 1408345913500, which has exactly 500 as its milliseconds part. I read that some older runtimes truncate instead of rounding. But I'm not sure that's what's at play here

Why not just change the ts?

@bernardobelchior
Copy link
Member

The exact timestamp that is being visualized is 1408345913500, which has exactly 500 as its milliseconds part.

Could we update the timestamp to have 0 milliseconds instead of 500?

@Janpot
Copy link
Member Author

Janpot commented Sep 29, 2025

That's what I did in my last commit. It's a draft PR, I'm still researching this.

I'm still not sure that's what's at play here, it suspect shouldAdvanceTime could be causing this as well.

@Janpot Janpot changed the title [code-infra] Attempt stabilizing .toLocaleString [code-infra] Stabilize fake timers in regression tests Sep 30, 2025
@Janpot Janpot marked this pull request as ready for review September 30, 2025 09:16
setPrevShouldAdvanceTime(props.shouldAdvanceTime);
}

return ready ? props.children : null;
Copy link
Member Author

@Janpot Janpot Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little side-quest in some weird code I ran into. It's problematic when shouldAdvanceTime prop changes while ready is true it would render the children once with the wrong fake clock. We can get rid of the effect and instead set up the clock straight in the render.

import { createBrowserRouter, RouterProvider, Outlet, NavLink, useNavigate } from 'react-router';
import { Globals } from '@react-spring/web';
import { setupFakeClock, restoreFakeClock } from '../utils/setupFakeClock'; // eslint-disable-line
import { restoreFakeClock } from '../utils/setupFakeClock'; // eslint-disable-line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we just need to import the file to set up the fake clock, right?

Suggested change
import { restoreFakeClock } from '../utils/setupFakeClock'; // eslint-disable-line
import '../utils/setupFakeClock'; // eslint-disable-line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint disable rule was hiding this. Updated as well

Comment on lines +78 to +79
const [dispose, setDispose] = React.useState<(() => void) | null>(null);
const [prevShouldAdvanceTime, setPrevShouldAdvanceTime] = React.useState(props.shouldAdvanceTime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need state for these? Wouldn't refs work?

Copy link
Member Author

@Janpot Janpot Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://react.dev/reference/react/useRef#caveats, I don't believe a ref would be safe under concurrent rendering.

Do not write or read ref.current during rendering, except for initialization. This makes your component’s behavior unpredictable.

@Janpot Janpot enabled auto-merge (squash) September 30, 2025 11:30
@Janpot Janpot merged commit cf6e816 into mui:master Sep 30, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). test type: bug It doesn't behave as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants