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

Adoption of PortProvider and PortFinder #3903

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

esanzgar
Copy link
Contributor

@esanzgar esanzgar commented Nov 3, 2021

This adoption simplifies the discovery of frames.

I did a little bit of clean-up in the tests: rearranged a few variables
alphabetically, and delete unneeded lines and variables.

Closes #3533

@esanzgar esanzgar changed the base branch from master to port-finder-and-port-provider November 3, 2021 18:07
@esanzgar esanzgar force-pushed the port-finder-and-port-provider branch 3 times, most recently from cffd395 to c6e48bf Compare November 11, 2021 12:52
Base automatically changed from port-finder-and-port-provider to master November 15, 2021 14:57
@esanzgar esanzgar force-pushed the port-finder-and-port-provider-adoption branch from f0d7c4d to cacceeb Compare November 16, 2021 11:07
@codecov
Copy link

codecov bot commented Nov 16, 2021

Codecov Report

Merging #3903 (75d7e43) into master (922d6ef) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3903      +/-   ##
==========================================
- Coverage   99.00%   99.00%   -0.01%     
==========================================
  Files         214      214              
  Lines        8015     8011       -4     
  Branches     1896     1894       -2     
==========================================
- Hits         7935     7931       -4     
  Misses         80       80              
Impacted Files Coverage Δ
src/annotator/annotation-sync.js 100.00% <100.00%> (ø)
src/annotator/guest.js 99.14% <100.00%> (ø)
src/annotator/sidebar.js 98.18% <100.00%> (-0.04%) ⬇️
src/shared/port-finder.js 100.00% <100.00%> (ø)
src/shared/port-provider.js 100.00% <100.00%> (ø)
src/sidebar/services/frame-sync.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 922d6ef...75d7e43. Read the comment docs.

@esanzgar esanzgar force-pushed the port-finder-and-port-provider-adoption branch from cacceeb to 92b6ca3 Compare November 16, 2021 11:30
@esanzgar esanzgar changed the base branch from master to simplify-nomenclature November 16, 2021 11:31
@esanzgar esanzgar marked this pull request as ready for review November 16, 2021 11:32
@esanzgar esanzgar changed the title POC: Port finder and port provider adoption Adoption of PortProvider and PortFinder Nov 16, 2021
Base automatically changed from simplify-nomenclature to master November 17, 2021 10:21
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I have had an initial look over this. Functionally everything seems to work as desired. Aside from the minor comments, a few high level issues I raised:

  1. Where we put the logic that determines where the host frame is, in relation to the current frame. Related to this, the behavior of the Guest constructor changes significantly depending on the config.subFrameIdentifier property, but that's not captured at all in docs or argument types.
  2. Where the PortProvider is constructed. This currently happens in the Sidebar class, but perhaps it should live at a higher level (ie. the entry point) since it is so central to how the application works and should be easy to find.
  3. I raised a hazard regarding stubbing of window.parent.postMessage in guests. That doesn't break anything in the test runner that I can see at present, but I can see a risk of that happening in future.

src/annotator/guest.js Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/sidebar.js Outdated Show resolved Hide resolved
src/annotator/sidebar.js Show resolved Hide resolved
src/annotator/sidebar.js Outdated Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/index.js Outdated Show resolved Hide resolved
src/annotator/index.js Outdated Show resolved Hide resolved
src/annotator/test/integration/anchoring-test.js Outdated Show resolved Hide resolved
@esanzgar esanzgar force-pushed the port-finder-and-port-provider-adoption branch 4 times, most recently from 8ce62d7 to 2a730d1 Compare November 18, 2021 09:02
Copy link
Contributor Author

@esanzgar esanzgar left a comment

Choose a reason for hiding this comment

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

@robertknight, I have added all your suggestions on a second commit.

src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/guest.js Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/guest.js Outdated Show resolved Hide resolved
src/annotator/test/integration/anchoring-test.js Outdated Show resolved Hide resolved
src/annotator/test/sidebar-test.js Outdated Show resolved Hide resolved
src/annotator/test/sidebar-test.js Outdated Show resolved Hide resolved
@@ -178,7 +178,7 @@ export class PortProvider {
/**
* Returns the `host` port from the `sidebar-host` channel.
*/
get sidebarPort() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realised it had the wrong port name.

Copy link
Member

Choose a reason for hiding this comment

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

You'll need to change this if other other host-side ports can be retrieved in future, such as a host <-> notebook port. I think something like hostPortFor('sidebar') might be a good API even if the 'sidebar' argument is currently redundant, as it makes it clearer to a reader what is at the other end of the port.

}
}

/**
* @param {'hostPortRequest'} eventName
* @param {'hostFrameRequest'} eventName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this name matches the PortFinder#discover, which tries to discover a frame. The name of the port is not as relevant as that the host frame has been discovered.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I had some suggestions regarding PortProvider APIs and a few JSDoc comments. Otherwise the changes look good to me.

src/annotator/index.js Show resolved Hide resolved
src/annotator/sidebar.js Outdated Show resolved Hide resolved
@@ -178,7 +178,7 @@ export class PortProvider {
/**
* Returns the `host` port from the `sidebar-host` channel.
*/
get sidebarPort() {
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to change this if other other host-side ports can be retrieved in future, such as a host <-> notebook port. I think something like hostPortFor('sidebar') might be a good API even if the 'sidebar' argument is currently redundant, as it makes it clearer to a reader what is at the other end of the port.

src/shared/port-provider.js Outdated Show resolved Hide resolved
@@ -226,7 +234,7 @@ export class FrameSyncService {
/**
* Connect to the host frame and guest frame(s) in the current browser tab.
*/
connect() {
async connect() {
Copy link
Member

Choose a reason for hiding this comment

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

Because connect is now async, any failures will no longer trigger the catch block at the bottom of src/sidebar/index.js and thus the exception won't be reported via reportLaunchError. I think fixing that would be too big of a change for this PR, but we should address it in future.

This adoption simplifies the discovery of frames.

I did a little bit of clean-up in the tests: rearranged a few variables
alphabetically, and delete unneeded lines and variables.
@esanzgar esanzgar force-pushed the port-finder-and-port-provider-adoption branch 2 times, most recently from 7e200c7 to a461010 Compare November 22, 2021 11:17
In future PR, `Guest` will contain two bridges (like `FrameSync`).
Naming them by the destination frame will help identify the purpose of
it.

It seems that the convention for this `Bridge`s is to contain the word
`RPC` to indicate that it is a remote (inter-frame) procedure.
@esanzgar esanzgar force-pushed the port-finder-and-port-provider-adoption branch from a461010 to 75d7e43 Compare November 22, 2021 11:22
@esanzgar esanzgar merged commit 520b5c5 into master Nov 22, 2021
@esanzgar esanzgar deleted the port-finder-and-port-provider-adoption branch November 22, 2021 11:27
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.

Epic: overhaul the inter-frame communication system
2 participants