Skip to content
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

feat:allow explicitly reveiving certain dom events for inert elements #19121

Merged
merged 14 commits into from
Apr 10, 2024

Conversation

mstahv
Copy link
Member

@mstahv mstahv commented Apr 5, 2024

Added API to allow bypassing inert check for DOM events.

Fixes #19116

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@mstahv
Copy link
Member Author

mstahv commented Apr 5, 2024

There is bit ugly API changes, but luckily only for internal classes (marked properly with documentation). Some code smell, but don't have good ideas how to refactor as I don't understand all the details related to the implementation.

@mcollovati
Copy link
Collaborator

A comment after a quick and not in-depth look: do we really need to change handleNode() and fireEvent() to add the inert flag?
I mean, the flag seems to be used only by ElementListenerMap.fireEvent() and I wonder if we could get the same information from the event as we do for isEnabled (e.g. event.getSource().getNode().isInert()).
This way, we may probably be able to also remove the hard-coded instanceof EventRpcHandler in AbstractRpcInvocationHandler; then EventRpcHandler should override allowInert(...) to return true (similar to PublishedServerEventHandlerRpcHandler) since the check will be performed later in fireEvent.

I apologize in advance if the above statements are incorrect 😁

@mcollovati mcollovati added the Contribution PRs coming from the community or external to the team label Apr 5, 2024
@knoobie
Copy link
Contributor

knoobie commented Apr 5, 2024

I would follow Marco's suggestion if it works to reduce the possibility of any breaking change 😅

@mstahv
Copy link
Member Author

mstahv commented Apr 7, 2024

The "breaking changes" are only in classes marked with "For internal use only. May be renamed or removed in a future release.", so I think those ought to be rather safe.

I spent quite a while looking into a way to get the right details, but I sure might have missed some opportunity due to the complexity of the code. I have an hour or two in car so I can give it an another look now, but my my true wish is that somebody who actaully understands this code would step in :-)

@mcollovati is there any kind of "developer docs" for this internals? Like some kind of brief overview or description of what these classes do or even just some class/sequence diagrams? Currently it is very hard to understand how the thing are supposed to work and why it is build in this way...

@mstahv
Copy link
Member Author

mstahv commented Apr 7, 2024

Oh yes, the allowInter is an instance method, overriding that might help 👍

@mstahv
Copy link
Member Author

mstahv commented Apr 7, 2024

If we can assume that this piece in AbstractRpcInvocationHandler:

StateNode node = ui.getInternals().getStateTree()
                .getNodeById(getNodeId(invocationJson));

... returns the same instance as event.getSource().getNode() in ElementListenerMap, then passing around the inert flag could be omitted as well. I have no idea, don't really even understand the purpose of StateNode 😬

@mstahv
Copy link
Member Author

mstahv commented Apr 7, 2024

Refactored, the current state isn't tested in any ways though now...

@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Apr 7, 2024
Copy link

github-actions bot commented Apr 7, 2024

Test Results

1 099 files  ± 0  1 099 suites  ±0   1h 28m 37s ⏱️ + 3m 57s
6 947 tests + 1  6 898 ✅ + 1  49 💤 ±0  0 ❌ ±0 
7 304 runs  +23  7 243 ✅ +23  61 💤 ±0  0 ❌ ±0 

Results for commit 35b7a78. ± Comparison against base commit a07e2ad.

♻️ This comment has been updated with latest results.

@mstahv
Copy link
Member Author

mstahv commented Apr 7, 2024

There is now a unit test IT will be there throught the resize event improvement. I think this is ready. Annotation support could be added later if needed, I don't need it.

@mstahv mstahv marked this pull request as ready for review April 7, 2024 11:43
@mcollovati
Copy link
Collaborator

If we can assume that this piece in AbstractRpcInvocationHandler: ...

The node get from UI in AbstractRpcInvocationHandler is the same used to create theElement object for the DomEvent, so event.getSource().getNode() returns the exactly same instance.

@mcollovati
Copy link
Collaborator

It looks like this change is breaking navigation on modal components (InertComponentIT.modalComponentAdded_routerLinkClicked_navigation).
Probably ElementListenerMap.fireEvent() should allow navigation events (BrowserNavigateEvent.EVENT_NAME and BrowserLeaveNavigationEvent.EVENT_NAME) regardless of the inert node flag, as AbstractRpcInvocationHandler.isNavigationInvocation() does.

@mcollovati
Copy link
Collaborator

@mstahv if you are busy, I can apply the changes and then continue the discussion

@mshabarov mshabarov requested a review from tepi April 8, 2024 11:36
@mstahv
Copy link
Member Author

mstahv commented Apr 8, 2024

@mcollovati Go ahead if you have these in IDE already! Otherwise I can open this again at some point when I can't get text out of my brain 😁

@mstahv
Copy link
Member Author

mstahv commented Apr 8, 2024

Probably the whole isNavigationInvocation logic should be in that event specific implementation 🤔

@mstahv
Copy link
Member Author

mstahv commented Apr 8, 2024

I'll spend a minute on this...

@mstahv
Copy link
Member Author

mstahv commented Apr 8, 2024

Nah, if you have good ideas @mcollovati, go for it. My idea was to use the new API for those navigation events, but they are some "special cases" and it started to look complicated...

@tepi tepi mentioned this pull request Apr 9, 2024
9 tasks
@vaadin-bot vaadin-bot added +1.0.0 and removed +0.1.0 labels Apr 9, 2024
@mstahv mstahv changed the title Feature/allow intert for dom events Feature/allow explicitly reveiving certain dom events for inert elements Apr 9, 2024
@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Apr 10, 2024
@mstahv mstahv changed the title Feature/allow explicitly reveiving certain dom events for inert elements feat:allow explicitly reveiving certain dom events for inert elements Apr 10, 2024
@tepi
Copy link
Contributor

tepi commented Apr 10, 2024

Looks good to me! @mcollovati did you have any remaining comments about this one?

Copy link

sonarcloud bot commented Apr 10, 2024

Quality Gate Passed Quality Gate passed

Issues
6 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@mcollovati
Copy link
Collaborator

Looks good to me too. There's still a pending discussion about the message log level, but if we want to differentiate between dev and prod, we can do it in another PR

@tepi tepi enabled auto-merge (squash) April 10, 2024 11:25
@tepi tepi merged commit 63f64cc into main Apr 10, 2024
27 of 42 checks passed
@tepi tepi deleted the feature/allow-intert-for-dom-events branch April 10, 2024 11:25
@mstahv
Copy link
Member Author

mstahv commented Apr 10, 2024

Excellent! I migth even be so bold that I would throw illegal state exception, at least in dev mode.

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution PRs coming from the community or external to the team Released with Vaadin 24.4.0 +0.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

event listeners need to support bypassing modality checks
5 participants