Skip to content

View to Component #81

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

Merged
merged 118 commits into from
Sep 20, 2022
Merged

Conversation

Archmonger
Copy link
Contributor

@Archmonger Archmonger commented Jun 29, 2022

Changelog

  • view_to_component utility that supports both async and sync views. Views can be function or classes.
    • Can convert view to VDOM or an iframe (for compatibility purposes)
  • Reorganize the docs to have separate src an includes folders
  • Docs for view_to_component
  • Update changelog
  • Miscellaneous cleanup across several files

IMPORTANT NOTE

This PR does not add automatic handling of things such as href click events or form submission. Currently compatibility=True is required to get href and forms to work.

This is a desirable behavior that should be implemented in a future PR as a toggleable option.

In the future view_to_component should be able to automatically perform any URL routing/re-rendering that is needed. The VDOM component should essentially "act as if it's an iframe", despite it being VDOM.

Remaining Todo:

  • Tests (needs merge of Playwright test suite)
  • Docs
  • Type Hints

@Archmonger
Copy link
Contributor Author

Archmonger commented Sep 15, 2022

@rmorshea Just merged with main, so this PR is ready for review. There's some features I'd like to add to this in the future, but I don't believe that should be addressed in this PR.

I will make a new Django-IDOM release as soon as this gets merged in.

@Archmonger
Copy link
Contributor Author

Archmonger commented Sep 19, 2022

@rmorshea I'm realizing a limitation with IDOM Core's view_to_component.

Currently, because event handlers can't be JavaScript strings in IDOM core, inline events cannot be serialized into VDOM.

For example, onclick events like this won't work: <button onclick='example()'></button>

@rmorshea
Copy link
Contributor

rmorshea commented Sep 19, 2022

@Archmonger, that's actually more of an issue with React. If you assign onclick="..." IDOM will pass that on to the client as-is. However React does not interpret strings as event handlers. I think the only way to do this would be to dangerouslySetInnerHtml at which point it doesn't seem like you'd need html_to_vdom at all since you could literally use the raw HTML string.

@Archmonger
Copy link
Contributor Author

Archmonger commented Sep 19, 2022

I would say this is ends up being a pretty big limitation. When working within JavaScript frameworks, this issue doesn't really exist.

I can't think of a safe way of fixing this.

cough Even our existing script tag implementation is potentially unsafe.

Might want to document the limitation in core, probably within the html_to_vdom docstring.

@Archmonger
Copy link
Contributor Author

On a different note, I think the revised tests for script, request, args, and kwargs are solid.

@Archmonger Archmonger merged commit 9069952 into reactive-python:main Sep 20, 2022
@Archmonger Archmonger deleted the view-to-component branch September 20, 2022 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants