-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to patch (navigate patching the content) to another site (#621)
- Loading branch information
Showing
5 changed files
with
96 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Beacon.Private do | ||
@moduledoc false | ||
|
||
# Concentrate calls to private APIs so it's easier to track breaking changes and document them, | ||
# in case we need to make changes or understand why we had to call such APIs. | ||
|
||
# Should be avoided as much as possible. | ||
|
||
@doc """ | ||
On page navigation, the request might actually hit a different site than the one defined by the current session. | ||
That's the case for a live patch to a full URL, for eg: | ||
User is in https://sitea.com/page1 and clicks on a link to https://siteb.com/page2 through a `<.link patch={...}>` component, | ||
and since LV allows such navigation, we must do it as well but we need fetch the session defined for the requested URL and update the state accordingly, | ||
otherwise the page will either not be found or worse could render the wrong content. | ||
Relative paths are not supported because there's no safe way to know if a `/relative` path belongs to site A or B, that's a LV contraint. | ||
We use the private function `Phoenix.LiveView.Route.live_link_info/3` in order to keep the same behavior as LV. | ||
""" | ||
def site_from_session(endpoint, router, url, view) do | ||
case Phoenix.LiveView.Route.live_link_info(endpoint, router, url) do | ||
{_, | ||
%{ | ||
view: ^view, | ||
live_session: %{ | ||
extra: %{ | ||
session: %{"beacon_site" => site} | ||
} | ||
} | ||
}} -> | ||
site | ||
|
||
_ -> | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters