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

html and client fixes #368

Merged
merged 18 commits into from
Mar 19, 2023
Merged

html and client fixes #368

merged 18 commits into from
Mar 19, 2023

Conversation

fscherf
Copy link
Member

@fscherf fscherf commented Mar 19, 2023

This PR fixes multiple problems the HTML parsing API, the rendering code of the client, relative URL resolving of the client and introduces the new, more JavaScript like, widget API for the client.

@markusgritsch: This PR should fix both of your current issues.

fscherf added 2 commits March 19, 2023 14:43
`NodeList.reset()` gets called with a list of nodes when the `Node.nodes`
property gets set. `NodeList.reset()` then clears its node list and creates
a `lona.protocol.OPERATION.RESET` patch.

Previously, the code falsely create a patch for every new node, that contained
all following nodes. That resulted in a list of patches that would override
each other on the client.

This was no problem in the past, because the client has no checks if a node
was already sent by the server, and because the patches overwrote each other,
the HTML end-result always was correct.

This patch changes the code to create only one reset patch, instead of multiple
ones.

Signed-off-by: Florian Scherf <[email protected]>
This patch changes all tests that use `lona.html.HTML` to use `lona.html.HTML1`
explicitly, to make room for tests for `lona.html.HTML2`.

Signed-off-by: Florian Scherf <[email protected]>
This was linked to issues Mar 19, 2023
@fscherf fscherf requested a review from markusgritsch March 19, 2023 13:48
fscherf added 16 commits March 19, 2023 14:50
Previously, `lona.parsing.HTML2` used `lona.parsing.HTML2` to parse given
HTML-strings. Since `lona.parsing.HTML2` wraps all nodes on the top-level of
the parsing result, `lona.parsing.HTML2` calls, that contained nested
HTML-strings, resulted in node trees with falsely wrapped sub node trees.

This patch updates `lona.parsing.HTML2` to use
`lona.parsing.html_string_to_node_list` for given HTML-strings instead, so the
final wrapping only happens on the top-level, and not down the tree.

Signed-off-by: Florian Scherf <[email protected]>
Since client2 will be the client implementation of Lona 2, and Lona 2 is just
around the corner, all testing and debugging should be done against client2
first.

Signed-off-by: Florian Scherf <[email protected]>
This patch adds support for HTML symbols:

    https://www.w3schools.com/html/html_symbols.asp

Signed-off-by: Florian Scherf <[email protected]>
This patch adds support for HTML symbols:

    https://www.w3schools.com/html/html_symbols.asp

Signed-off-by: Florian Scherf <[email protected]>
This patch adds a test to ensure HTML symbols get rendered correctly on the
client.

    https://www.w3schools.com/html/html_symbols.asp

Signed-off-by: Florian Scherf <[email protected]>
Previously, the rendering engine wrote the node cache directly, to add a newly
rendered node, without checking if a already cached node gets overridden by it.
This is dangerous and covers up potential bugs in the rendering code on the
client and in the patch creation code on the server.

This patch adds `_cache_node()` to the rendering engine, which checks if a
node, with the given node id, is already cached, and throws an exception if so.

Signed-off-by: Florian Scherf <[email protected]>
Previously, the Lona client- and widget-API were very Pythonic, and used only
basic JavaScript class features before. In Lona 2, methods like
`Widget.data_updated` will be renamed to `Widget.onDataUpdated`. To facilitate
the transition, the new names and API will be added to Lona 1 and coexist with
the old API, to ensure compatibility until Lona 2.
This is done by adding a new JavaScript class, that abstracts the new and the
old widget API.

This patch adds `Widget.onDataUpdated` as a replacement for
`Widget.data_updated`, `Widget.destroy` as a replacement for
`Widget.deconstruct`, and adds all arguments of `Widget.setup` to
`Widget.constructor`, to make a separate setup stage, besides the JavaScript
constructor, obsolete in Lona 2.

This patch also adds a wrapper class for widget data, to
make helper methods like `WidgetData.set` and `WidgetData.get` possible in the
future.

Signed-off-by: Florian Scherf <[email protected]>
This patch updates the client to use the widget API implementation of client2,
in order to be compatible with the old and the new widget API, until Lona 2
gets released.

Signed-off-by: Florian Scherf <[email protected]>
This new property is helpful for global window actions, in case the server
server disconnects, and for testing the widget API.

Signed-off-by: Florian Scherf <[email protected]>
The window shim implementation of client2 will be the place for all
abstraction of the old and the new widget API, to facilitate a smooth
transition, from Lona 1 to Lona 2.

This patch updates the client, to use the new implementation, as early as
possible.

Signed-off-by: Florian Scherf <[email protected]>
Previously, `Widget.destroy` only got called when a node got orphaned by a
node clearing operation, and collected by
`LonaRenderingEngine._clean_node_cache`. It did not run, when a single node got
removed from the client.

This patch moves the destroy and clean-up code into a helper method of the
rendering engine, and adds a call to it to the node removal code, so
`Widget.destroy` gets called every time a node gets removed from the client.

Signed-off-by: Florian Scherf <[email protected]>
Previously, `Widget.deconstruct` only got called when a node got orphaned by a
node clearing operation, and collected by `_clean_node_cache`. It did not run,
when a singe node got removed from the client.

This patch moves the deconstruct and clean-up code into a helper method, and
adds a call to it to the node removal code, so `Widget.deconstruct` gets called
every time a node gets removed from the client.

Signed-off-by: Florian Scherf <[email protected]>
Previously, the resolving of relative URLs was a custom implementation and had
multiple weird quirks, and behaved differently than the browsers
implementation. That was confusing, because redirects, issued by Lona,
sometimes resulted in slightly different URLs than their link-counterpart.

This patch updates the client to use the browsers implementation of URL
resolving.

Signed-off-by: Florian Scherf <[email protected]>
Previously, the resolving of relative URLs was a custom implementation and had
multiple weird quirks, and behaved differently than the browsers
implementation. That was confusing, because redirects, issued by Lona,
sometimes resulted in slightly different URLs than their link-counterpart.

This patch updates the client to use the browsers implementation of URL
resolving.

Signed-off-by: Florian Scherf <[email protected]>
This patch updates the redirect test, to ensure relative link targets and
relative redirects behave the same in both client implementations.

Signed-off-by: Florian Scherf <[email protected]>
@fscherf fscherf force-pushed the fscherf/html-and-client-fixes branch from cecb0bc to 1215842 Compare March 19, 2023 13:50
@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.12 🎉

Comparison is base (75b75e7) 68.78% compared to head (1215842) 68.91%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
+ Coverage   68.78%   68.91%   +0.12%     
==========================================
  Files          68       68              
  Lines        5165     5166       +1     
  Branches     1164     1164              
==========================================
+ Hits         3553     3560       +7     
+ Misses       1334     1328       -6     
  Partials      278      278              
Impacted Files Coverage Δ
lona/html/node_list.py 84.87% <100.00%> (ø)
lona/html/parsing.py 85.71% <100.00%> (+1.81%) ⬆️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@markusgritsch markusgritsch left a comment

Choose a reason for hiding this comment

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

I can confirm that both issues are fixed.

@fscherf
Copy link
Member Author

fscherf commented Mar 19, 2023

@markusgritsch: Great! :) thanks for testing and reporting in the first place. I will release 1.12.4 this evening

@fscherf fscherf merged commit be4c722 into master Mar 19, 2023
@fscherf fscherf deleted the fscherf/html-and-client-fixes branch March 19, 2023 15:32
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.

CLIENT_VERSION 2 adds spurious <div> How to add &nbsp;
3 participants