Skip to content

don't dispatch an input event on the initial render - #2488

Open
Umer-Butt07 wants to merge 2 commits into
observablehq:mainfrom
Umer-Butt07:fix-2160-pointer-initial-dispatch
Open

Umer-Butt07 wants to merge 2 commits into
observablehq:mainfrom
Umer-Butt07:fix-2160-pointer-initial-dispatch

Conversation

@Umer-Butt07

Copy link
Copy Markdown

The pointer transform renders with a null value during Plot.plot, which called context.dispatchValue and dispatched an input event on the plot before it was returned, when there can't be any listeners yet. This also needed document.defaultView.Event during server-side rendering.

dispatchValue now still sets the initial value (null) but only dispatches the input event after the plot has been rendered; pointing afterwards dispatches as before.

Closes #2160

Tests

  • pnpm vitest run test/pointer-test.js test/document-test.js — passed. New pointer-test cases check that the initial render dispatches no input event (value is null, for both svg and figure) and that pointing dispatches one. The existing document-test case asserted the initial dispatch; it now checks the document's Event is used when pointing.
  • pnpm run lint and pnpm run tsc — passed.
  • Full pnpm run test on Windows: the only failures were timeouts that passed on rerun and two tests that fail the same way on main (docs-test, timeAxisLocal snapshot).

Comment thread src/plot.js Outdated
Comment on lines 185 to 186
if (!rendered) return;
figure.dispatchEvent(new context.document.defaultView.Event("input", {bubbles: true}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!rendered) return;
figure.dispatchEvent(new context.document.defaultView.Event("input", {bubbles: true}));
if (rendered) figure.dispatchEvent(new context.document.defaultView.Event("input", {bubbles: true}));

@Umer-Butt07

Copy link
Copy Markdown
Author

thanks, applied the inline conditional. the pointer/document tests, lint and type checks pass. the full suite has one projection snapshot mismatch that also reproduces on the unchanged base.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The pointer interaction shouldn’t synchronously dispatch an event on initial render

2 participants