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

Implement use_location #721

Merged
merged 21 commits into from
Apr 8, 2022
Merged

Implement use_location #721

merged 21 commits into from
Apr 8, 2022

Conversation

rmorshea
Copy link
Collaborator

@rmorshea rmorshea commented Apr 1, 2022

By providing access to a use_location hook, users can implement primitive routing. The catch is that, at present, state will not be persisted as users navigate between routes. Support for that will have to come in a future update.

@rmorshea rmorshea marked this pull request as ready for review April 2, 2022 18:24
@rmorshea rmorshea changed the title Turn IDOM Client into an SPA Enable Basic Routing Apr 4, 2022
@rmorshea rmorshea requested a review from Archmonger April 4, 2022 05:10
@Archmonger
Copy link
Contributor

Archmonger commented Apr 4, 2022

Can you shoot me a sample snippet of the syntax for this so I can test?

@rmorshea
Copy link
Collaborator Author

rmorshea commented Apr 4, 2022

@Archmonger here's a demo of how it should work:

from idom import html, component, run
from idom.server import starlette as server


@component
def ShowLocation():
    loc = server.use_location()
    return html.h1(loc.pathname + loc.search)


run(ShowLocation, implementation=server)

Copy link
Contributor

@Archmonger Archmonger left a comment

Choose a reason for hiding this comment

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

Might want to rename the PR to "use_location hook" since this isn't routing, but rather location propagation.

Routing = integrated support for rendering different components based on regex path

requirements/pkg-deps.txt Show resolved Hide resolved
src/client/package.json Outdated Show resolved Hide resolved
src/client/packages/idom-client-react/src/server.js Outdated Show resolved Hide resolved
src/client/snowpack.config.js Show resolved Hide resolved
src/idom/server/flask.py Show resolved Hide resolved
src/idom/server/flask.py Show resolved Hide resolved
src/idom/server/flask.py Show resolved Hide resolved
src/idom/server/utils.py Outdated Show resolved Hide resolved
@rmorshea rmorshea changed the title Enable Basic Routing Implement use_location Apr 4, 2022
rmorshea added 2 commits April 4, 2022 18:58
if we poll sync then the server might not ever
get a hold of the event loop. this was causing
a problem for the sanic server in a test
@rmorshea
Copy link
Collaborator Author

rmorshea commented Apr 5, 2022

@Archmonger, any idea why this test is failing on Windows?

@Archmonger
Copy link
Contributor

Archmonger commented Apr 5, 2022

The way that test is written, I wouldn't expect it to raise anything on any OS?

From what I can tell,

  1. Create /dir/file.txt
  2. Create /escaped-file.txt via symlink
  3. Check if /dir/file.txt is safe

Why would you expect /dir/file.txt to be unsafe?

@Archmonger
Copy link
Contributor

Archmonger commented Apr 5, 2022

Scratch that, I see you're trying to symlink the empty /dir/file.txt to a /escaped-file.txt.

I don't think this is a valid test case to be honest. If the user intentionally symlinked a file into our dir, we should consider it safe. In general, symlinks/hardlinks should be considered as "real files" within both their given directories.

If you want this to fail for some reason, you'd need to use os.path.realpath() or Path.absolute() to follow the symlink to it's origin.

src/idom/server/utils.py Outdated Show resolved Hide resolved
@rmorshea rmorshea merged commit e43bcc0 into main Apr 8, 2022
@rmorshea rmorshea deleted the spa branch April 8, 2022 02:54
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.

2 participants