Repository navigation
Fix/theme mermaid d3 transition #13051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
96bd4bf
3d115d4
0c4f8dd
89f689e
6e4a6e3
8cc4668
d75d301
582388a
0c4ecf7
e26b598
e2f176a
8c5b2f7
a4b0a6a
e21ef05
2823f0d
4958218
2df4875
434cfef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import {select} from 'd3-selection'; | ||
| import {describe, expect, it, vi} from 'vitest'; | ||
| import {loadMermaid} from '../loadMermaid'; | ||
|
|
||
| const mermaidImport = vi.hoisted(() => ({ | ||
| onLoad: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('mermaid', () => { | ||
| mermaidImport.onLoad(); | ||
| return {default: {}}; | ||
| }); | ||
|
|
||
| describe('loadMermaid', () => { | ||
| it('registers D3 transitions before importing Mermaid', async () => { | ||
| const selection = select(null); | ||
| const getTransition = () => | ||
| (selection as unknown as {transition?: unknown}).transition; | ||
|
|
||
| expect(getTransition()).toBeUndefined(); | ||
|
|
||
| mermaidImport.onLoad.mockImplementation(() => { | ||
| expect(getTransition()).toBeTypeOf('function'); | ||
| }); | ||
|
|
||
| await expect(loadMermaid()).resolves.toEqual({}); | ||
| expect(mermaidImport.onLoad).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare module 'd3-transition'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,5 +10,10 @@ import type {Mermaid} from 'mermaid'; | |
| // We load Mermaid with a dynamic import to code split / lazy load the library | ||
| // It is only called inside a useEffect, so loading can be deferred | ||
| export async function loadMermaid(): Promise<Mermaid> { | ||
| // Mermaid's flowchart tooltips call selection.transition(). This method is | ||
| // added by d3-transition, but can be tree-shaken when Mermaid imports only | ||
| // selected exports from the side-effect-free d3 entry point. Load the | ||
| // extension explicitly before Mermaid so it patches the same D3 selection. | ||
| await import('d3-transition'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a type declaration for
Add a shorthand module declaration under Suggested fix
|
||
| return (await import('mermaid')).default; | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.