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

Add IS_BROWSER constant to GenericNode #274

Merged
merged 8 commits into from Nov 6, 2021
Merged

Conversation

lukechu10
Copy link
Collaborator

This fixes the ugly hack of using

if TypeId::of::<G>() == TypeId::of::<DomNode>() { ... }

and replaces it with

if G::IS_BROWSER { ... }

@lukechu10 lukechu10 added A-SSR Area: Server Side Rendering (SSR) and Static Site Generation (SSG) A-ergonomics Area: API ergonomics labels Oct 9, 2021
@lukechu10 lukechu10 added the BREAKING CHANGE Breaking changes introduced in this PR label Oct 9, 2021
@jquesada2016
Copy link
Contributor

@lukechu10 Since you mentioned wanting to support other platforms in the future, wouldn't it be wiser to change the IS_BROWSER constant to something like PLATFORM_NAME or PLATFORM with an enum which can include a variant for custom for user provided renderers? This does solve the ugly hack, but doesn't help when targeting other runtimes, such as NativeScript, React Native, etc.

@lukechu10
Copy link
Collaborator Author

@lukechu10 Since you mentioned wanting to support other platforms in the future, wouldn't it be wiser to change the IS_BROWSER constant to something like PLATFORM_NAME or PLATFORM with an enum which can include a variant for custom for user provided renderers? This does solve the ugly hack, but doesn't help when targeting other runtimes, such as NativeScript, React Native, etc.

Only web apps need to be isomorphic, meaning that they should render with both DomNode and SsrNode. For other platforms, there will only ever be one single backend and so this will not be used. In fact, now that I think about it, maybe the constant should go on the new Html trait (that is only implemented for DomNode and SsrNode) instead of GenericNode.

@lukechu10 lukechu10 mentioned this pull request Oct 26, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2021

Codecov Report

Merging #274 (2f51b18) into master (59765a1) will not change coverage.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #274   +/-   ##
=======================================
  Coverage   74.93%   74.93%           
=======================================
  Files          33       33           
  Lines        4800     4800           
=======================================
  Hits         3597     3597           
  Misses       1203     1203           
Impacted Files Coverage Δ
packages/sycamore-macro/src/template/component.rs 64.00% <ø> (ø)
packages/sycamore/src/generic_node/dom_node.rs 0.00% <ø> (ø)
packages/sycamore/src/generic_node/ssr_node.rs 76.45% <ø> (ø)
packages/sycamore/src/lib.rs 100.00% <ø> (ø)
packages/sycamore/src/portal.rs 0.00% <ø> (ø)
website/src/main.rs 0.98% <0.00%> (ø)
packages/sycamore-macro/src/component/mod.rs 73.86% <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 59765a1...2f51b18. Read the comment docs.

@lukechu10 lukechu10 merged commit 865bea0 into master Nov 6, 2021
@lukechu10 lukechu10 deleted the generic-node-is-browser branch November 6, 2021 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ergonomics Area: API ergonomics A-SSR Area: Server Side Rendering (SSR) and Static Site Generation (SSG) BREAKING CHANGE Breaking changes introduced in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants