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

Feature: disable links until JS properly loaded #352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benoawfu
Copy link

@benoawfu benoawfu commented Sep 9, 2021

This PR disables all links with a method other than :get until PhoenixHTML is loaded (= the expected behaviour is ready), to avoid issueing a wrong GET call if somehow phoenixJS is not yet loaded (latency, JS/bundling error, anything that could prevent phoenix_html.js to load).

This way we ensure nobody can hit the wrong GET route when we intended to use only the POST/PUT/DELETE one. For instance a POST might redirect to the matching GET route, in that case you might never know that your POST didn't go through and you just clicked on a link to fetch only the GET route.

I've handled the case where you wanted to create a link disabled, to ensure we don't enable it automatically in JS.

Updated documentation, unit tests and JS part tested in real life.

@Gazler
Copy link
Member

Gazler commented Sep 9, 2021

Hi, thanks for the PR. Functionally, I think this could work in a specific application (running the JS you included in app.js), however I have concerns merging this as it could cause an issue with LiveView. For example:

If you have Routes.link(to: some_route(socket, @dynamic_id), method: :post) in your live_view, then if @dynamic_id changes, the link would be permanently disabled, as the re-rendered HTML would clobber the removal of the disabled attribute triggered from the element being replaced on LiveView. If we were to merge this, we'd have to consider this in LiveView too.

@benoawfu
Copy link
Author

benoawfu commented Sep 9, 2021

I see, yes I didn't consider LiveView using it, so it would need some rework there for sure.

If anyone sees some value in this feature -as I do-, I'll be more than happy if anyone is willing to help to get there!

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.

None yet

2 participants