Comments (9)
@nicolas-brousse I'm going to close this now as I don't think that this is a Lookbook-specific issue. Feel free to reopen with more info if required of course :-)
from lookbook.
@allmarkedup I am also experiencing a can't access property "href", this.location is undefined
error on a clean Rails 7 project with the latest view_component and lookbook gems:
Uncaught TypeError: Cannot read properties of undefined (reading 'href')
at Session.notifyApplicationAfterPageLoad (turbo.es2017-esm.js:2729:70)
at Session.pageBecameInteractive (turbo.es2017-esm.js:2666:14)
at PageObserver.pageIsInteractive (turbo.es2017-esm.js:2197:27)
at PageObserver.pageIsComplete (turbo.es2017-esm.js:2201:14)
at HTMLDocument.PageObserver.interpretReadyState (turbo.es2017-esm.js:2169:22)
It seems like this.location
in this function of hotwire turbo is undefined:
notifyApplicationAfterPageLoad(timing = {}) {
clearBusyState(document.documentElement);
return dispatch("turbo:load", { detail: { url: this.location.href, timing } });
}
I generated a new project and added view_component + lookbook. I generated a new example view component with preview. When I start the server bin/dev
and open the component in lookbook (http://localhost:3000/lookbook/example/test) I get the aforementioned error. However, when I open it in a new window (http://localhost:3000/lookbook/preview/example/test) I do not seem to get the error . Removing import "@hotwired/turbo-rails"
from my app/javascript/application.js
file and/or replacing it by legacy 'turbolinks' seems to prevent the error from occurring.
from lookbook.
Setting config.lookbook.preview_srcdoc = false
in development.rb
seems to prevent this issue from occurring.
from lookbook.
Ok so I've looked into this a bit more. The issue is that when using the iframe with the srcdoc
attribute, within the generated document there are some caveats to do with the fact that it effectively doesn't have a standard 'location' URL associated with it. Turbo seems to not play nicely without a standard location so it's throwing some errors in the component preview.
Lookbook uses the srcdoc
attribute by default because it is a bit quicker than making another request for the iframe document. But as it seems to be causing issues in a few places I think the best thing to do here is to either remove the use of srcdoc
on the preview iframe altogether or to change the default to using a regular iframe src attribute pointing at the preview URL.
I think I'll do the latter for now, so people who are not using Turbo still have the option of improving the page load performance by enabling the srcdoc
option. However I suspect the performance benefits are pretty marginal anyway so I may just remove this in a later version.
Thanks again everyone for your help on this issue - I'll update this thread again when I've released a new version with this change in it.
from lookbook.
@nicolas-brousse It's a little hard to tell what is going on there from those errors - although at first glance it doesn't appear to be to do with Lookbook. notifyApplicationAfterPageLoad
is a turbolinks method, are you using that at all anywhere?
On a different note, I've not seen combustion before but that looks like exactly what I need to improve the testing on Lookbook :-) I've struggled to find a good way to run tests with different application configuration loaded and it seems like combustion will solve that. Hopefully will have some time soon to dig in a bit more!
from lookbook.
I'm experiencing the same issue.
from lookbook.
Thanks all for the reports, reopening this now until I have a chance to look into it further 👍
from lookbook.
I also see the same error, the suggestion @mauricebolhuis shared works here too.
from lookbook.
I've just released v0.6.0 that includes this change in the default value for the srcdoc
config option so I'm going to close this again now.
from lookbook.
Related Issues (20)
- Why does the preview filter ignore the path/folder structure? HOT 4
- Add the ability to hide a nested within a group. HOT 3
- Cannot choose display options in an embedded preview HOT 4
- Support better errors / web console instead of rescuing errors in Lookbook HOT 2
- undefined method `strftime' for nil:NilClass with nil datetime HOT 1
- Hidden scenarios within groups are not accessible via their URL
- Swap the order of Previews and Pages sections HOT 4
- Ability to search within pages section HOT 3
- X-Frame-Options always set to deny HOT 8
- Can't draw templates that require instance variables HOT 5
- Lookbook overrides ViewComponent `show_previews` config depending on load order HOT 3
- ActionView::Template::Error occurs when trying to render a template file with a partial HOT 5
- FEA: Support for Mailer Previews HOT 1
- Support configurable frame ancestors for embeds HOT 2
- Documentation request: mention support for Phlex in the README HOT 5
- Previews not rendering nested components HOT 2
- Better integration with Phlex HOT 1
- Version requirement for listen gem is not specified, and wrong version error is suppressed HOT 1
- Syntax error reporting in Lookbook HOT 2
- Sharing View Component Previews Across Multiple Projects Without Duplicating Files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lookbook.